How Do I Do a Simple Linear Regression in R

Data from:

http://www.statsci.org/data/general/samara.txt

Load Data

setwd('~/Desktop/R/regression/')
samara <- read.table('~/Desktop/R/regression/samara.txt',header=T)

Display Data

head(samara)
##   Tree  Load Velocity
## 1    1 0.239     1.34
## 2    1 0.208     1.06
## 3    1 0.223     1.14
## 4    1 0.224     1.13
## 5    1 0.246     1.35
## 6    1 0.213     1.23
str(samara)
## 'data.frame':    36 obs. of  3 variables:
##  $ Tree    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Load    : num  0.239 0.208 0.223 0.224 0.246 0.213 0.198 0.219 0.241 0.21 ...
##  $ Velocity: num  1.34 1.06 1.14 1.13 1.35 1.23 1.23 1.15 1.25 1.24 ...

Plot Data

plot(Velocity~Load,data=samara)
fit = lm(Velocity~Load,data=samara)
abline(fit)

fit
## 
## Call:
## lm(formula = Velocity ~ Load, data = samara)
## 
## Coefficients:
## (Intercept)         Load  
##    -0.09326      5.82019