Skip to content

Instantly share code, notes, and snippets.

@mick001
Created August 28, 2015 00:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mick001/82e8ef620b48d5ef37fc to your computer and use it in GitHub Desktop.
Save mick001/82e8ef620b48d5ef37fc to your computer and use it in GitHub Desktop.
Example of a quadratic model fit in R
#-------------------------------------------------------------------------------
# Parabola y = a + bx + cx^2
#-------------------------------------------------------------------------------
model2 <- lm(wt ~ disp+I(disp^2))
summary(model2)
coef(model2)
# Predicted vs original
predicted <- fitted(model2)
original <- wt
# Plot model2
curve(predict(model2,data.frame(disp=x)),col='green',lwd=2,add=TRUE)
#-------------------------------------------------------------------------------
# Polynomial n=3 y = a +bx + cx^2 + dx^3
#-------------------------------------------------------------------------------
model3 <- lm(wt ~ disp+ I(disp^2) + I(disp^3))
summary(model3)
coef(model3)
# Predicted vs original
predicted <- fitted(model3)
original <- wt
# Plot model3
curve(predict(model3,data.frame(disp=x)),col='blue',lwd=2,add=TRUE)
@macele
Copy link

macele commented Jul 7, 2018

from the above example how to perform a lack of fit test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment