Search code examples
rregressiontidyverselinear-regressionnon-linear-regression

How to find the best regression model fit for your plot


let's say I wish to fit a regression model to disp ~ drat from the mtcars dataset. Is there a package I can use that can tell me what type of regression I should use e.g. linear, polynomial, bayesian etc.?

ggplot(mtcars, aes(disp, drat)) +
  geom_point() +
  facet_wrap(~cyl)  

Solution

  • Pointing out the suggestion from @Roland you should do some exploratory and visual analysis to understand your data first. You can try with stat_smooth() and then decide what kind of model you want to fit:

    library(ggplot2)
    #Code
    ggplot(mtcars, aes(disp, drat)) +
      geom_point() +
      facet_wrap(~cyl)+
      stat_smooth(se=F)+
      stat_smooth(color='magenta',method = 'lm',se=F)
    

    Output:

    enter image description here