实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.4 R语言解题

发布于:2025-05-30 ⋅ 阅读:(13) ⋅ 点赞:(0)

本文是实验设计与分析(第6版,Montgomery著,傅珏生译) 第5章析因设计引导5.7节思考题5.4 R语言解题。主要涉及方差分析,正态假设检验,残差分析,交互作用图。

dataframe<-data.frame(

Light=c(280,290,285,230,235,240,300,310,295,260,240,235,290,285,290,220,225,230),

phospor=gl(3, 6,18),

glass=gl(2, 3, 18))

summary (battery)

battery.aov2 <- aov(Light ~ phospor * glass,data= dataframe)

summary (battery.aov2)

> summary (battery.aov2)

              Df Sum Sq Mean Sq F value   Pr(>F)   

phospor        2    933     467   8.842  0.00436 **

glass          1  14450   14450 273.789 1.26e-09 ***

phospor:glass  2    133      67   1.263  0.31780   

Residuals     12    633      53                    

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

with(dataframe,interaction.plot(phospor,glass,Light,type="b",pch=19,fixed=T,xlab="phosphor",ylab="Light"))

plot.design(Light~glass*phospor,data=dataframe)

fit <-lm(Light~glass*phospor,data=dataframe)

anova(fit)

> anova(fit)

Analysis of Variance Table

Response: Light

              Df  Sum Sq Mean Sq  F value    Pr(>F)   

glass          1 14450.0 14450.0 273.7895 1.259e-09 ***

phospor        2   933.3   466.7   8.8421  0.004364 **

glass:phospor  2   133.3    66.7   1.2632  0.317801   

Residuals     12   633.3    52.8                      

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

summary(fit)

> summary(fit)

Call:

lm(formula = Light ~ glass * phospor, data = dataframe)

Residuals:

    Min      1Q  Median      3Q     Max

-10.000  -5.000   0.000   4.167  15.000

Coefficients:

                Estimate Std. Error t value Pr(>|t|)   

(Intercept)      285.000      4.194  67.949  < 2e-16 ***

glass2           -50.000      5.932  -8.429 2.19e-06 ***

phospor2          16.667      5.932   2.810   0.0158 * 

phospor3           3.333      5.932   0.562   0.5845   

glass2:phospor2   -6.667      8.389  -0.795   0.4422   

glass2:phospor3  -13.333      8.389  -1.589   0.1379   

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 7.265 on 12 degrees of freedom

Multiple R-squared:  0.9608,    Adjusted R-squared:  0.9444

F-statistic:  58.8 on 5 and 12 DF,  p-value: 5.067e-08

par(mfrow=c(2,2))

plot(fit)

par(mfrow=c(2,2))

plot(as.numeric(dataframe$glass), fit$residuals, xlab="glass", ylab="Residuals", type="p", pch=16)

plot(as.numeric(dataframe$phospor), fit$residuals, xlab="phospor", ylab="Residuals", pch=16)


 


网站公告

今日签到

点亮在社区的每一天
去签到