n <- 100
x <- seq(0,1,length=n)
y <- vector(length=100)
e <- rnorm(100)
y= 1+ 2*x +e
model=lm(y~x)
summary(model)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.10132 -0.60480 0.05776 0.58731 2.48614
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.9905 0.1854 5.342 5.97e-07 ***
## x 2.2220 0.3203 6.937 4.34e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.934 on 98 degrees of freedom
## Multiple R-squared: 0.3293, Adjusted R-squared: 0.3225
## F-statistic: 48.12 on 1 and 98 DF, p-value: 4.341e-10
z=cbind(rep(1,100),x)
b <- solve(t(z)%*%z)%*%t(z)%*%y
b
## [,1]
## 0.9904802
## x 2.2219540