Skip to content

Instantly share code, notes, and snippets.

@mick001
Created Aug 28, 2015
Embed
What would you like to do?
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