原文地址:统计建模与R软件第四章习题答案(参数估计)
作者:蘓木柒
Ex4.1只会极大似然法,不会矩法... Ex4.2指数分布,λ的极大似然估计是n/sum(Xi)> x<-c(rep(5,365),rep(15,245),rep(25,150),rep(35,100),rep(45,70),rep(55,45),rep(65,25))> lamda<-length(x)/sum(x);lamda[1] 0.05Ex4.3Poisson分布P(x=k)=λ^k/k!*e^(-λ)其均数和方差相等,均为λ,其含义为平均每升水中大肠杆菌个数。取均值即可。> x<-c(rep(0,17),rep(1,20),rep(2,10),rep(3,2),rep(4,1))> mean(x)[1] 1平均为1个。Ex4.4> obj<-function(x){f<-c(-13+x[1]+((5-x[2])*x[2]-2)*x[2],-29+x[1]+((x[2]+1)*x[2]-14)*x[2]) ;sum(f^2)} #其实我也不知道这是在干什么。所谓的无约束优化问题。> x0<-c(0.5,-2)>nlm(obj,x0)$minimum[1] 48.98425$estimate[1] 11.4127791 -0.8968052$gradient[1] 1.411401e-08 -1.493206e-07$code[1] 1$iterations[1] 16Ex4.5> x<-c(54,67,68,78,70,66,67,70,65,69)> t.test(x) #t.test()做单样本正态分布区间估计 One Sample t-testdata: xt = 35.947, df = 9, p-value = 4.938e-11alternative hypothesis: true mean is not equal to 095 percent confidence interval: 63.1585 71.6415sample estimates:mean of x 67.4平均脉搏点估计为 67.4 ,95%区间估计为 63.1585 71.6415 。> t.test(x,alternative="less",mu=72) #t.test()做单样本正态分布单侧区间估计 One Sample t-testdata: xt = -2.4534, df = 9, p-value = 0.01828alternative hypothesis: true mean is less than 7295 percent confidence interval: -Inf 70.83705sample estimates:mean of x 67.4p值小于0.05,拒绝原假设,平均脉搏低于常人。要点:t.test()函数的用法。本例为单样本;可做双边和单侧检验。Ex4.6> x<-c(140,137,136,140,145,148,140,135,144,141);x [1] 140 137 136 140 145 148 140 135 144 141> y<-c(135,118,115,140,128,131,130,115,131,125);y [1] 135 118 115 140 128 131 130 115 131 125> t.test(x,y,var.equal=TRUE) Two Sample t-testdata: x and yt = 4.6287, df = 18, p-value = 0.0002087alternative hypothesis: true difference in means is not equal to 095 percent confidence interval: 7.53626 20.06374sample estimates:mean of x mean of y 140.6 126.8期望差的95%置信区间为 7.53626 20.06374 。要点:t.test()可做两正态样本均值差估计。此例认为两样本方差相等。ps:我怎么觉得这题应该用配对t检验?Ex4.7> x<-c(0.143,0.142,0.143,0.137)> y<-c(0.140,0.142,0.136,0.138,0.140)> t.test(x,y,var.equal=TRUE) Two Sample t-testdata: x and yt = 1.198, df = 7, p-value = 0.2699alternative hypothesis: true difference in means is not equal to 095 percent confidence interval: -0.001996351 0.006096351sample estimates:mean of x mean of y 0.14125 0.13920 期望差的95%的区间估计为-0.001996351 0.006096351Ex4.8接Ex4.6> var.test(x,y) F test to compare two variancesdata: x and yF = 0.2353, num df = 9, denom df = 9, p-value = 0.04229alternative hypothesis: true ratio of variances is not equal to 195 percent confidence interval: 0.05845276 0.94743902sample estimates:ratio of variances 0.2353305要点:var.test可做两样本方差比的估计。基于此结果可认为方差不等。因此,在Ex4.6中,计算期望差时应该采取方差不等的参数。> t.test(x,y) Welch Two Sample t-testdata: x and yt = 4.6287, df = 13.014, p-value = 0.0004712alternative hypothesis: true difference in means is not equal to 095 percent confidence interval: 7.359713 20.240287sample estimates:mean of x mean of y 140.6 126.8期望差的95%置信区间为 7.359713 20.240287 。要点:t.test(x,y,var.equal=TRUE)做方差相等的两正态样本的均值差估计 t.test(x,y)做方差不等的两正态样本的均值差估计Ex4.9> x<-c(rep(0,7),rep(1,10),rep(2,12),rep(3,8),rep(4,3),rep(5,2))> n<-length(x)> tmp<-sd(x)/sqrt(n)*qnorm(1-0.05/2)> mean(x)[1] 1.904762> mean(x)-tmp;mean(x)+tmp[1] 1.494041[1] 2.315483平均呼唤次数为1.90.95的置信区间为1.49,2,32Ex4.10> x<-c(1067,919,1196,785,1126,936,918,1156,920,948)> t.test(x,alternative="greater") One Sample t-testdata: xt = 23.9693, df = 9, p-value = 9.148e-10alternative hypothesis: true mean is greater than 095 percent confidence interval: 920.8443 Infsample estimates:mean of x 997.1灯泡平均寿命置信度95%的单侧置信下限为 920.8443 要点:t.test()做单侧置信区间估计