Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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