t = 5.3, df = 21, p-value = 3e-05
alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.7955 1.8212 sample estimates: mean of x mean of y 5.500 4.192
由结果可知:因为p值显著小于0.01,因此拒绝原假设,即: (4)、
测得俩批电子器件的样本电阻
设这俩批器材的电阻值分别服从正态分布N和M,样本独立。 (1)试样本俩个总体的方差是否相等(0.01)? (2)试样本俩个总体的均值是否相等(0.05)? x<-c(0.140,0.138,0.143,0.142,0.144,0.137) y<-c(0.135,0.140,0.142,0.136,0.138,0.130) t.test(x,y,var.equal=TRUE)
Two Sample t-test
data: x and y
t = 1.9, df = 10, p-value = 0.09
alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.0007721 0.0084388 sample estimates: mean of x mean of y 0.1407 0.1368
由结果可知:p值为0.09,大于显著性水平0.05,说明应该接受原假设,即:均值显著相等 var.test(x,y)
F test to compare two variances
data: x and y
F = 0.44, num df = 5, denom df = 5, p-value = 0.4
alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0.06196 3.16425 sample estimates: ratio of variances 0.4428
由结果可知:p值为0.4,大于显著性水平0.01,说明应该接受原假设,即:方差显著相等
(5)、
有人称某地成年人中大学毕业生比例不低于30%,为检验之,随机调查该地15名成年人,发现有3名大学毕业生,有0.95的置信度,问该人的看法是否成立? binom.test(c(12,3),p=0.3)%单样本比率p的近似检验 Exact binomial test
data: c(12, 3)
number of successes = 12, number of trials = 15, p-value = 9e-05
alternative hypothesis: true probability of success is not equal to 0.3 95 percent confidence interval: 0.5191 0.9567 sample estimates:
probability of success 0.8
由结果可知:p值显著小于显著性水平0.05,所以应该拒绝原假设,即:此人看法不成立
第八章
单因素方差分析: 例题8.1.1
以淀粉为原料生产葡萄糖的过程中,残留许多糖蜜,可作为生产酱色的原料,在生产酱色的过程之前应该尽可能的除去杂质,以保证酱色质量。为此对于除杂方法进行选择,在实验中用五种不同除杂方式,每种作4次试验,数据如下: 代码段:
> X<-c(25.6,22.2,28.0,29.8,24.4,30.0,29.0,27.5,25.0,27.7,23.0,32.2,28.8,28.0,31.5,25.9,20.6,21.2,22.0,21.2)
> A<-factor(rep(1:5,each=4))#定义各因子变量的数据读入分段。
> miscellany<-data.frame(X,A)#将定义完成各因子变量的分段混合后赋给“miscellany”混合变量。
> aov.mis<-aov(X~A,data=miscellany)#进行方差分析。 > summary(aov.mis)#调用summary函数提取分析结果。
以上结果中:Df表示自由度;sum sq表示平方和;mean sq表示均方和;F value表示F检验统计量的值,即为:F比;Pr(>F)表示检验的p值;A就是因素A;Residuals为残差。
可以看出P=0.0162<0.05,说明有理由拒绝原假设,即,有显著性差异。 > plot(miscellany$X~miscellany$A)#绘制以上数据的箱线图。
均值的多重比较: 代码段:
P.adjust.methods#调用处调整p值得方法列表。
Pairwise.t.test(X,A,p.adjust.method=”none”)//应当注意“none”的符号问题。
>pairwise.t.test(X,A,p.adjust.method='none') #得到多重比较p值,“none”指的是不作任何调整,默认值按照holm调整。
Pairwise.t.test(X,A,p.adjust.method=’holm’)//应当注意首字母不能大写 > pairwise.t.test(X,A,p.adjust.method='holm')
#按照缺省的“holm”对p值进行调整。
>pairwise.t.test(X,A,p.adjust.method='bonferroni')#按照缺省的“bonferroni”对p值进行调整。
同时置信区间发:Tukey法
>TukeyHSD(aov(X~A,miscellany))
共有10个两两比较结果,在0.05的显著性水平下A5-A1,A5-A2,A5-A3,A5-A4的差异是显著的。其他结果均不显著。 方差齐性检验: 代码段:
>bartlett.test(X,A,data=miscellany)#方差齐性检验之“bartlett”检验。
由p值0.1309>0.05,故:接受原假设,认为各处理组数据等方差。
无交互作用双因子方差分析: 例题8.2.1
原来检验果汁中铅含量有三种方法,A1,A2,A3,现在研究出另一种检验方法 A4,能否用A4代替前三种方法,要进行实验考察。实验数据如下: 代码段:
>juice<-data.frame(X=c(0.05,0.46,0.12,0.16,0.84,1.30,0.08,0.38,0.4,0.10,0.92,1.57,0.11,0.43,0.05,0.10,0.94,1.10,0.11,0.44,0.08,0.03,0.93,1.15),A=gl(4,6),B=gl(6,1,24))#数据输入与整理。
> juice.aov<-aov(X~A+B,juice)#无交互双因素方差分析。 > summary(juice.aov)#提取结果。
p值说明了因素B对含铅量有显著影响,而因素A对含铅量影响不显著。 > bartlett.test(X~A,data=juice)
由于p=0.9659>0.05,所以接受原假设认为各处理组数据等方差。
> bartlett.test(X~B,data=juice)
由于p=0.003766<0.05所以拒绝原假设,认为各处理组数居方差不等。
有交互作用的方差分析: 代码段:
> rats<-data.frame(Time=c(0.31,0.45,0.46,0.43,0.82,1.10,0.88,0.72,0.43,0.45,0.63,0.76,0.45,0.71,0.66,0.62,0.38,0.29,0.40,0.23,0.92,0.61,0.49,1.24,0.44,0.35,0.31,0.40,0.56,1.02,0.71,0.38,0.22,0.21,0.18,0.23,0.30,0.37,0.38,0.29,0.23,0.25,0.24,0.22,0.30,0.36,0.31,0.33),Toxicant=gl(3,16,48,labels=c(\\定义数据。 > op<-par(mfrow=c(1,2))
> plot(Time~Toxicant+Cure,data=rats) Hit