You are on page 1of 3

> Strength =

c(66.30,64.84,64.36,69.70,66.26,72.06,73.23,71.40,68.85,75.78,72.57,76.64,78.87,7
7.37,75.94,78.82,77.13,77.09)
> length(Strength)
[1] 18
> Temp = c(40,40,40,45,45,45,50,50,50,55,55,55,60,60,60,65,65,65)
> length(Temp)
[1] 18
> fit1 = lm(Strength~Temp)
> summary(fit1)

Call:
lm(formula = Strength ~ Temp)

Residuals:
Min 1Q Median 3Q Max
-2.4815 -1.6821 -0.1003 1.6372 3.3185

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 45.4538 2.8459 15.972 2.97e-11 ***
Temp 0.5175 0.0535 9.672 4.36e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.938 on 16 degrees of freedom


Multiple R-squared: 0.854, Adjusted R-squared: 0.8448
F-statistic: 93.55 on 1 and 16 DF, p-value: 4.358e-08

> anova(fit1)
Analysis of Variance Table

Response: Strength
Df Sum Sq Mean Sq F value Pr(>F)
Temp 1 351.50 351.50 93.553 4.358e-08 ***
Residuals 16 60.12 3.76
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> model.matrix(fit1)
(Intercept) Temp
1 1 40
2 1 40
3 1 40
4 1 45
5 1 45
6 1 45
7 1 50
8 1 50
9 1 50
10 1 55
11 1 55
12 1 55
13 1 60
14 1 60
15 1 60
16 1 65
17 1 65
18 1 65
attr(,"assign")
[1] 0 1
> names(fit1)
[1] "coefficients" "residuals" "effects" "rank"
"fitted.values" "assign" "qr" "df.residual" "xlevels"
[10] "call" "terms" "model"
> plot(Strength~Temp)
> abline(fit1)
75
Strength

70
65

40 45 50 55 60 65

Temp

> X = model.matrix(fit1)
> invXtX = solve(t(X)%*%(X))
> XtY = t(X)%*%Strength
> betahatFB = invXtX%*%XtY
> betahatFB
[,1]
(Intercept) 45.4537778
Temp 0.5175048
> deviance(fit1)
[1] 60.11599
>

You might also like