Databases Reference
In-Depth Information
Here the little “hat” symbol on top of the β is there to indicate that it's
the estimator for β . You don't know the true value of β ; all you have is
the observed data, which you plug into the estimator to get an estimate.
To actually fit this, to get the β s, all you need is one line of R code where
you've got a column of y's and a (single) column of x's:
model <- lm(y ~ x)
So for the example where the first few rows of the data were:
x
y
7
276
3
43
4
82
6
136
10
417
9
269
The R code for this would be:
> model <- lm ( y ~ x )
> model
Call :
lm ( formula = y ~ x )
Coefficients :
( Intercept ) x
-32.08 45.92
> coefs <- coef ( model )
> plot ( x , y , pch = 20 , col = "red" , xlab = "Number new friends" ,
ylab = "Time spent (seconds)" )
> abline ( coefs [ 1 ], coefs [ 2 ])
And the estimated line is y =−32 . 08 + 45 . 92 x , which you're welcome
to round to y =−32 + 46 x , and the corresponding plot looks like the
lefthand side of Figure 3-5 .
Search WWH ::




Custom Search