Skip to content

Instantly share code, notes, and snippets.

@mick001
Created August 28, 2015 00:55
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/4af1369a200af5790236 to your computer and use it in GitHub Desktop.
Save mick001/4af1369a200af5790236 to your computer and use it in GitHub Desktop.
Linear regression in R
#-------------------------------------------------------------------------------
# Linear regression y = a + bx
#-------------------------------------------------------------------------------
# Fit the model
model1 <- lm(wt ~ disp)
# Parameters and information about the model
model1
coef(model1)
summary(model1)
# Plot the model
abline(model1,col='red',lwd=2)
##################################################################################
# OUTPUT
##################################################################################
# > summary(model1)
#
# Call:
# lm(formula = wt ~ disp)
#
# Residuals:
# Min 1Q Median 3Q Max
# -0.89044 -0.29775 -0.00684 0.33428 0.66525
#
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 1.5998146 0.1729964 9.248 2.74e-10 ***
# disp 0.0070103 0.0006629 10.576 1.22e-11 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Residual standard error: 0.4574 on 30 degrees of freedom
# Multiple R-squared: 0.7885, Adjusted R-squared: 0.7815
# F-statistic: 111.8 on 1 and 30 DF, p-value: 1.222e-11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment