统计建模与R软件第四章习题…
来源:互联网 发布:mac 上不了网 编辑:程序博客网 时间:2024/06/05 12:56
原文地址:统计建模与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.05
Ex4.3
Poisson分布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] 16
Ex4.5
>x<-c(54,67,68,78,70,66,67,70,65,69)
>t.test(x) #t.test()做单样本正态分布区间估计
One Sample t-test
data:x
t = 35.947, df = 9, p-value =4.938e-11
alternative hypothesis: truemean is not equal to 0
95 percent confidenceinterval:
63.158571.6415
sampleestimates:
mean of x
67.4
平均脉搏点估计为 67.4 ,95%区间估计为 63.158571.6415 。
>t.test(x,alternative="less",mu=72)#t.test()做单样本正态分布单侧区间估计
One Sample t-test
data:x
t = -2.4534, df = 9, p-value =0.01828
alternative hypothesis: truemean is less than 72
95 percent confidenceinterval:
-Inf 70.83705
sampleestimates:
mean of x
67.4
p值小于0.05,拒绝原假设,平均脉搏低于常人。
要点:t.test()函数的用法。本例为单样本;可做双边和单侧检验。
Ex4.6
>x<-c(140,137,136,140,145,148,140,135,144,141);x
[1] 140 137136 140 145 148 140 135 144 141
>y<-c(135,118,115,140,128,131,130,115,131,125);y
[1] 135 118115 140 128 131 130 115 131 125
>t.test(x,y,var.equal=TRUE)
Two Sample t-test
data: x andy
t = 4.6287, df = 18, p-value =0.0002087
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
7.5362620.06374
sampleestimates:
mean of x mean ofy
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-test
data: x andy
t = 1.198, df = 7, p-value =0.2699
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
-0.001996351 0.006096351
sampleestimates:
mean of x mean ofy
0.14125 0.13920
期望差的95%的区间估计为-0.001996351 0.006096351
Ex4.8
接Ex4.6
>var.test(x,y)
F test to compare two variances
data: x andy
F = 0.2353, num df = 9, denomdf = 9, p-value = 0.04229
alternative hypothesis: trueratio of variances is not equal to 1
95 percent confidenceinterval:
0.058452760.94743902
sampleestimates:
ratio ofvariances
0.2353305
要点:var.test可做两样本方差比的估计。基于此结果可认为方差不等。
因此,在Ex4.6中,计算期望差时应该采取方差不等的参数。
>t.test(x,y)
Welch Two Sample t-test
data: x andy
t = 4.6287, df = 13.014,p-value = 0.0004712
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
7.35971320.240287
sampleestimates:
mean of x mean ofy
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.9
0.95的置信区间为1.49,2,32
Ex4.10
>x<-c(1067,919,1196,785,1126,936,918,1156,920,948)
>t.test(x,alternative="greater")
One Sample t-test
data:x
t = 23.9693, df = 9, p-value =9.148e-10
alternative hypothesis: truemean is greater than 0
95 percent confidenceinterval:
920.8443 Inf
sampleestimates:
mean of x
997.1
灯泡平均寿命置信度95%的单侧置信下限为920.8443
要点:t.test()做单侧置信区间估计
只会极大似然法,不会矩法...
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.05
Ex4.3
Poisson分布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]
$code
[1] 1
$iterations
[1] 16
Ex4.5
>x<-c(54,67,68,78,70,66,67,70,65,69)
>t.test(x)
data:
t = 35.947, df = 9, p-value =4.938e-11
alternative hypothesis: truemean is not equal to 0
95 percent confidenceinterval:
sampleestimates:
mean of x
平均脉搏点估计为 67.4 ,95%区间估计为 63.158571.6415 。
>t.test(x,alternative="less",mu=72)
data:
t = -2.4534, df = 9, p-value =0.01828
alternative hypothesis: truemean is less than 72
95 percent confidenceinterval:
sampleestimates:
mean of x
p值小于0.05,拒绝原假设,平均脉搏低于常人。
要点:t.test()函数的用法。本例为单样本;可做双边和单侧检验。
Ex4.6
>x<-c(140,137,136,140,145,148,140,135,144,141);x
>y<-c(135,118,115,140,128,131,130,115,131,125);y
>t.test(x,y,var.equal=TRUE)
data:
t = 4.6287, df = 18, p-value =0.0002087
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
sampleestimates:
mean of x mean ofy
期望差的95%置信区间为
要点: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)
data:
t = 1.198, df = 7, p-value =0.2699
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
sampleestimates:
mean of x mean ofy
Ex4.8
接Ex4.6
>var.test(x,y)
data:
F = 0.2353, num df = 9, denomdf = 9, p-value = 0.04229
alternative hypothesis: trueratio of variances is not equal to 1
95 percent confidenceinterval:
sampleestimates:
ratio ofvariances
要点:var.test可做两样本方差比的估计。基于此结果可认为方差不等。
因此,在Ex4.6中,计算期望差时应该采取方差不等的参数。
>t.test(x,y)
data:
t = 4.6287, df = 13.014,p-value = 0.0004712
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
sampleestimates:
mean of x mean ofy
期望差的95%置信区间为 7.359713 20.240287。
要点:t.test(x,y,var.equal=TRUE)做方差相等的两正态样本的均值差估计
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.9
0.95的置信区间为1.49,2,32
Ex4.10
>x<-c(1067,919,1196,785,1126,936,918,1156,920,948)
>t.test(x,alternative="greater")
data:
t = 23.9693, df = 9, p-value =9.148e-10
alternative hypothesis: truemean is greater than 0
95 percent confidenceinterval:
sampleestimates:
mean of x
灯泡平均寿命置信度95%的单侧置信下限为920.8443
要点:t.test()做单侧置信区间估计
0 0
- 统计建模与R软件第四章习题…
- 统计建模与R软件第三章习题…
- 统计建模与R软件第二章习题…
- 统计建模与R软件第五章习题…
- 统计建模与R软件第六章习题…
- 统计建模与R软件第七章习题…
- 统计建模与R软件-第三章习题答案
- 『原创』统计建模与R软件-第四章 参数估计
- 《统计建模与R软件》练习答案-第2章
- 统计建模与R软件第二章作业
- 统计建模与R软件(绪论)
- 统计软件R
- R统计软件资源
- R软件的使用-习题
- UML与软件建模
- Ubuntu8安装统计软件R
- 第四章 习题4.9
- 第四章习题
- [zz]ggplot2绘图入门系列之…
- 阻止冒泡和浏览器默认行为
- 统计建模与R软件第三章习题…
- C语言const:禁止修改变量的值
- 统计建模与R软件第二章习题…
- 统计建模与R软件第四章习题…
- 隐马尔科夫模型
- 统计建模与R软件第五章习题…
- 统计建模与R软件第六章习题…
- ROS:两个节点同时具有发布和订阅图像信息的功能
- 统计建模与R软件第七章习题…
- 上海市劳动和社会保障局关于建立人…
- 微信小程序-第一章-简述
- ftl实现文档WORD导出