R语言与统计分析第六章课后习题(汤银才)

题-1

有一批枪弹, 出厂时, 其初速r语言keep r语言课后答案汤银才_r语言keep(单位:r语言keep r语言课后答案汤银才_ide_02). 经过较长时间储存, 取9发进行测试, 得样本值(单位:r语言keep r语言课后答案汤银才_ide_02)如下:r语言keep r语言课后答案汤银才_r语言_04

据经验, 枪弹储存后其初速仍服从正态分布, 且标准差不变, 问是否可认为这批枪弹的初速有显著降低?r语言keep r语言课后答案汤银才_ide_05

speed<-c(914, 920, 910, 934, 953, 940, 912, 924, 930)
t.test(speed, mu=950, conf.level = 0.99)

# p值=0.001<0.01, 不接收原假设
# 初速度有明显变化,且又有926.3 <950
# 可以认为弹药初速度有显著降低
One Sample t-test
 .
 data: speed
 t = -5, df = 8, p-value = 0.001
 alternative hypothesis: true mean is not equal to 950
 99 percent confidence interval:
 910.3 942.3
 sample estimates:
 mean of x
 926.3
题-2

已知维尼纶纤度在正常条件下服从正态分布, 且标准差为0.048. 从某天 生产的产品中抽取5根纤维, 测得其纤度为: r语言keep r语言课后答案汤银才_r语言keep_06, 问这天抽取的维尼纶纤度的总体标准差是否正常?r语言keep r语言课后答案汤银才_r语言keep_07

fiber<-c(1.32,1.55,1.36,1.40,1.1)

# 课本提供的chisq.var.test()函数:
chisq.var.test<-function (x,var,alpha,alternative="two.sided"){
  options(digits=4)
  result<-list( )
  n<-length(x)
  v<-var(x)
  result$var<-v
  chi2<-(n-1)*v/var
  result$chi2<-chi2
  p<-pchisq(chi2,n-1)
  if(alternative == "less"|alternative=="greater"){
    result$p.value<-p
  }else if (alternative=="two.sided") {
    if(p>.5)
    p<-1-p
    p<-2*p
    result$p.value<-p
  }else return("your input is wrong")
    result$conf.int<-c(
    (n-1)*v/qchisq(alpha/2, df=n-1, lower.tail=FALSE),
    (n-1)*v/qchisq(alpha/2, df=n-1, lower.tail=TRUE))
    result
}

chisq.var.test(fiber, 0.048^2, 0.05, alternative="two.sided")
# p值=4.992e-09<0.05, 不接收原假设, 总体标准差不正常

# library(TeachingDemos)
# sigma.test(x,sigmasq=0.048^2,conf.level=0.95,alternative="two.sided")
# 也可以使用TeachingDemos库所带sigma.test函数,计算值为5e-09<0.05
$var
 [1] 0.02648
 .
 $chi2
 [1] 45.97
 .
 $p.value
 [1] 4.992e-09
 .
 $conf.int
 [1] 0.009505 0.218654
题-3

下面给出两种型号的计算器充电以后所能使用的时间(单位:小时)的观测值:

型号A

5.5

5.6

6.3

4.6

5.3

5.0

6.2

5.8

5.1

5.2

5.9

型号B

3.8

4.3

4.2

4.9

4.5

5.2

4.8

4.5

3.9

3.7

3.6

2.9

设两样本独立且数据所属的两个总体的密度函数至多差一个平移量. 试问能否认为型号A的计算器平均使用时间比型号B来得长?r语言keep r语言课后答案汤银才_ide_05

# 两个总体的密度函数至多差一个平移量说明方差相同,但未知,使用t检验:
A<-c(5.5,5.6,6.3,4.6,5.3,5.0,6.2,5.8,5.1,5.2,5.9)
B<-c(3.8,4.3,4.2,4.9,4.5,5.2,4.8,4.5,3.9,3.7,3.6,2.9)

t.test(A,B,var.equal = TRUE)
# p值=3e-05<0.05, 故拒绝接收AB时长相等原假设,A所用时间显著比B长
Two Sample t-test
 .
 data: A and B
 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 me

an of y
5.500 4.192

题-4

测得两批电子器件的样本的电阻r语言keep r语言课后答案汤银才_概率论_09为:

A批(x)

0.140

0.138

0.143

0.142

0.144

0.137

B批(y)

0.135

0.140

0.142

0.136

0.138

0.130

设这两批器材的电阻值分别服从正态分布r语言keep r语言课后答案汤银才_r语言_10r语言keep r语言课后答案汤银才_r语言_11, 且两样本独立,

(1)试检验两个总体的方差是否相等?r语言keep r语言课后答案汤银才_ide_05

(2)试检验两个总体的均值是否相等?r语言keep r语言课后答案汤银才_r语言keep_07

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)

var.test(x, y, conf.level = 0.99)
# p值=0.4>0.01,接收H0,认为两个总体的方差相等

# 由于上一问认为方差相同,则这一问设置var.equal = TRUE
t.test(x,y,var.equal = TRUE)
# p值=0.09>0.05,接收H0,认为两个总体的均值相等

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
 99 percent confidence interval:
 0.02964 6.61491
 sample estimates:
 ratio of variances
 0.4428
 .
 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
题-5

有人称某地成年人中大学毕业生比例不低于30%, 为检验之, 随机调查该地15名成年人, 发现有3名大学毕业生, 取r语言keep r语言课后答案汤银才_r语言keep_14, 问该人的看法是否成立?

binom.test(c(3,12),p=0.3,alternative = "less",conf.level = 0.95)
# p-value=0.3>0.05不拒绝原假设
Exact binomial test
 .
 data: c(3, 12)
 number of successes = 3, number of trials = 15, p-value = 0.3
 alternative hypothesis: true probability of success is less than 0.3
 95 percent confidence interval:
 0.0000 0.4398
 sample estimates:
 probability of success
 0.2