Se tiene un estudio sobre un nuevo suplemento de alimento (X) para tres diferentes
razas de pollos (de seis semanas) para determinar el efecto sobre la dureza (Y) de la
cscara de huevo. Ajuste un modelo de regresin lineal para las tres razas de pollo.
SCT=t(y)%*%y
SCT
[,1]
[1,] 14449.89
b
[,1]
l 5.0225372
x 0.2634373
x1 0.9436435
x2 1.4448054
2.7859925
0.8313879
sig2<-(SCT-SCRComp)/(29-6)
sig2
[,1]
[1,] 1.482512
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.02254 0.87188 5.761 7.22e-06 ***
x 0.26344 0.06876 3.831 0.000855 ***
x1 0.94364 1.21798 0.775 0.446374
x2 1.44481 1.32492 1.090 0.286794
x:x1 2.78599 0.11957 23.299 < 2e-16 ***
x:x2 0.83139 0.15957 5.210 2.77e-05 ***
---
Residual standard error: 1.218 on 23 degrees of freedom
Multiple R-squared: 0.9923, Adjusted R-squared: 0.9906
F-statistic: 590.4 on 5 and 23 DF, p-value: < 2.2e-16
anova(modelcompleto)
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
x 1 230.86 230.86 155.721 1.008e-11 ***
x1 1 2898.07 2898.07 1954.836 < 2.2e-16 ***
x2 1 442.02 442.02 298.157 1.158e-14 ***
x:x1 1 765.06 765.06 516.055 < 2.2e-16 ***
x:x2 1 40.24 40.24 27.146 2.774e-05 ***
Residuals 23 34.10 1.48
Xp<-X[,c(1,2,3,4)]
b<-(solve(t(Xp)%*%Xp))%*%(t(Xp)%*%y)
SCRp<-t(b)%*%(t(Xp)%*%y)
b
[,1]
l -5.182747
x 1.172819
x1 26.005430
x2 11.162628
sig2p<-(SCT-SCRp)/(29-4)
sig2p
[,1]
[1,] 33.57602
##Estimando el modelo con pendiente comn, pero diferentes
interceptos utilizando lm:
model<-lm(y~x+x1+x2)
summary(model)
Call:
lm(formula = y ~ x + x1 + x2)
Residuals:
Min 1Q Median 3Q Max
-13.5755 -2.4096 0.3248 3.1319 10.5279
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.1827 3.4002 -1.524 0.14000
x 1.1728 0.2494 4.703 8.04e-05 ***
x1 26.0054 2.6848 9.686 6.08e-10 ***
x2 11.1626 3.0765 3.628 0.00128 **
---
Residual standard error: 5.794 on 25 degrees of freedom
Multiple R-squared: 0.8097, Adjusted R-squared: 0.7868
F-statistic: 35.45 on 3 and 25 DF, p-value: 3.674e-09
anova(model)
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
x 1 230.86 230.86 6.8757 0.014664 *
x1 1 2898.07 2898.07 86.3137 1.386e-09 ***
x2 1 442.02 442.02 13.1648 0.001278 **
Residuals 25 839.40 33.58
modelunarecta<-lm(y~x)
summary(modelunarecta)
Residuals:
Min 1Q Median 3Q Max
-16.052 -9.973 -3.977 9.417 25.879
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 13.5557 4.7373 2.862 0.00805 **
x 0.5954 0.4875 1.221 0.23256
---
Residual standard error: 12.44 on 27 degrees of freedom
Multiple R-squared: 0.05234, Adjusted R-squared: 0.01725
F-statistic: 1.491 on 1 and 27 DF, p-value: 0.2326