作业一
a1 = c(25.6,22.2,28.0,29.8)
a2 = c(24.4,30.0,29.0,27.5)
a3 = c(25.0,27.7,23.0,32.2)
a4 = c(28.8,28.0,34.5,25.8)
a5 = c(20.6,21.2,22.0,21.2)
fivemethods = data.frame(result=c(a1,a2,a3,a4,a5),method=factor(c(rep("a1",4),rep("a2",4),rep("a3",4),rep("a4",4),rep("a5",4))))
fit <- aov (result~method,data = fivemethods)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## method 4 147.4 36.85 3.946 0.0221 *
## Residuals 15 140.1 9.34
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
说明:上述结果中,method为因子,自由度为4,平方和为147.4,均方和为36.85,F检验统计量的值为3.946,检验的p值为0.0221。因为p = 0.0221 < 0.05,故拒绝𝐻0,认为因子(除杂方法)显著,即五种除杂方法对除杂量有显著差别。
作业二
x = c(20,25,30,35,40,45,50,55,60,65)
y = c(13.2,15.1,16.4,17.1,17.9,18.7,19.6,21.2,22.5,24.3)
summary(lm(y~x))
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.67273 -0.33333 -0.07273 0.34545 0.68182
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.12121 0.47708 19.12 5.8e-08 ***
## x 0.22303 0.01063 20.97 2.8e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.483 on 8 degrees of freedom
## Multiple R-squared: 0.9821, Adjusted R-squared: 0.9799
## F-statistic: 439.8 on 1 and 8 DF, p-value: 2.805e-08
mylm <- summary(lm(y~x))
plot(x,y,xlab = "温度",ylab = "产量",xlim = c(15,70),ylim = c(13,25),abline(lm(y~x)))
#coefficients
text(x=60,y=18,labels=paste("y=",round(mylm$coefficients[1],3),"+",round(mylm$coefficients[2],3),"x",sep=""))
#R-squared
text(x=60,y=16,labels=paste("R2=",round(mylm$r.squared,3),sep = ""))
#p-value
text(x=60,y=14,labels=paste("p=",signif(mylm$coefficients[2,4],3),sep=""))
说明:回归系数的估计与检验:回归系数的估计为α= 9.12121,β=0.22303a。相关分析:相关系数的平方为0.982,表明数据中98.2%可由此回归方程来描述。方程的检验:F分布的p值为2.8e-08,说明方程非常显著。