统计建模与R软件第四章习题…
发布日期:2021-10-16 07:12:20
浏览次数:37
分类:技术文章
本文共 3522 字,大约阅读时间需要 11 分钟。
原文地址: 作者:
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: true mean is not equal to 0
95 percent confidence interval:
63.1585 71.6415
sample 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-test
data: x
t = -2.4534, df = 9, p-value = 0.01828
alternative hypothesis: true mean is less than 72
95 percent confidence interval:
-Inf 70.83705
sample estimates:
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 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-test
data: x and y
t = 4.6287, df = 18, p-value = 0.0002087
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
7.53626 20.06374
sample 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-test
data: x and y
t = 1.198, df = 7, p-value = 0.2699
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.001996351 0.006096351
sample estimates:
mean of x mean of y
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 and y
F = 0.2353, num df = 9, denom df = 9, p-value = 0.04229
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.05845276 0.94743902
sample estimates:
ratio of variances
0.2353305
要点:var.test可做两样本方差比的估计。基于此结果可认为方差不等。
因此,在Ex4.6中,计算期望差时应该采取方差不等的参数。
> t.test(x,y)
Welch Two Sample t-test
data: x and y
t = 4.6287, df = 13.014, p-value = 0.0004712
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
7.359713 20.240287
sample 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.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: true mean is greater than 0
95 percent confidence interval:
920.8443 Inf
sample estimates:
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: true mean is not equal to 0
95 percent confidence interval:
sample estimates:
mean of x
平均脉搏点估计为 67.4 ,95%区间估计为 63.1585 71.6415 。
> t.test(x,alternative="less",mu=72)
data:
t = -2.4534, df = 9, p-value = 0.01828
alternative hypothesis: true mean is less than 72
95 percent confidence interval:
sample estimates:
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: true difference in means is not equal to 0
95 percent confidence interval:
sample estimates:
mean of x mean of y
期望差的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: true difference in means is not equal to 0
95 percent confidence interval:
sample estimates:
mean of x mean of y
Ex4.8
接Ex4.6
> var.test(x,y)
data:
F = 0.2353, num df = 9, denom df = 9, p-value = 0.04229
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
sample estimates:
ratio of variances
要点:var.test可做两样本方差比的估计。基于此结果可认为方差不等。
因此,在Ex4.6中,计算期望差时应该采取方差不等的参数。
> t.test(x,y)
data:
t = 4.6287, df = 13.014, p-value = 0.0004712
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
sample estimates:
mean of x mean of y
期望差的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: true mean is greater than 0
95 percent confidence interval:
sample estimates:
mean of x
灯泡平均寿命置信度95%的单侧置信下限为 920.8443
要点:t.test()做单侧置信区间估计
转载地址:https://blog.csdn.net/sjpljr/article/details/70168872 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年03月29日 18时02分34秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Android】 Intent应用详解
2019-04-26
【Android】 Intent详解
2019-04-26
【Android】 常用的Intent
2019-04-26
Android中AsyncTask的简单用法
2019-04-26
【Android】 Android中Log调试详解
2019-04-26
【Android】Android中WIFI开发总结(二)
2019-04-26
【Android】Android之WiFi开发应用示例
2019-04-26
【Android】 Android adb常见问题整理
2019-04-26
【Android】 Android体系结构图
2019-04-26
【Android】 Android中spinner下拉列表的使用
2019-04-26
说说在 python 中,如何删除左右两边不需要的字符
2019-04-26
说说如何管理 Spring Boot 中的起步依赖
2019-04-26
说说如何在 Linux 中,新建账号
2019-04-26
说说如何在 linux 中搭建 FTP 服务
2019-04-26
说说如何在 Python 的正则表达式中使用分组
2019-04-26
说说 Python 正则表达式的匹配类型
2019-04-26
说说 Python 的贪心和非贪心匹配策略
2019-04-26
说说在 Python 中,如何找出所有字符串匹配
2021-06-29
说说 Python 正则表达式中的那些字符类别码
2021-06-29
说说 Spring Boot 的条件化注解
2021-06-29