Created
August 28, 2015 00:58
-
-
Save mick001/82e8ef620b48d5ef37fc to your computer and use it in GitHub Desktop.
Example of a quadratic model fit in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from the above example how to perform a lack of fit test?