Created
August 28, 2015 01:00
-
-
Save mick001/578cfa675c44cb237102 to your computer and use it in GitHub Desktop.
Linear model with 4 variables in R
This file contains 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
#------------------------------------------------------------------------------- | |
# Another linear model using more information y = a*x1 + b*x2 + c*x3 + d*x4 | |
#------------------------------------------------------------------------------- | |
# Plot data | |
plot(disp,wt,type='p',xlab='Disp',ylab='Wt',main='Linear regression') | |
# Add a legend | |
legend("topleft",c("Observ.","Predicted"), col=c("black","red"), lwd=3) | |
model4 <- lm(wt ~ disp+mpg+hp+drat) | |
summary(model4) | |
coef(model4) | |
predicted <- fitted(model4) | |
original <- wt | |
mat <- cbind(predicted,original) | |
points(disp,predicted, type="p", col="red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment