Skip to content

Instantly share code, notes, and snippets.

@mick001
Created August 28, 2015 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mick001/578cfa675c44cb237102 to your computer and use it in GitHub Desktop.
Save mick001/578cfa675c44cb237102 to your computer and use it in GitHub Desktop.
Linear model with 4 variables in R
#-------------------------------------------------------------------------------
# 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