



모집단 상태에 대한 추측
두가지 가설 중 하나를 선택하는 검정에서 발생할 수 있는 오류

제1종 오류 : 실제모수는 귀무가설이 참이지만, 대립가설을 채택하는 오류 . 알파로 표기
제2종 오류 : 실제모수는 대립가설이 참이지만, 귀무가설을 채택하는 오류 . 베타로 표기

검정력 : 1-베타
제1종 오류를 유의수준으로 사용
유의수준은 실험에서 설정함







스포츠 이온음료의 용량이 제품에 표시된 3001교보다 모자라는 것 같아서 직접 조시를 해보고자 한다. 표본 300개를 대상으로 용량을 측정한 결과, 평균이 244.65로 확인되있다. 표준편차가 20일 때, 가설을 수립하고 유의수준 0.05에서의 좌측검정을 실시하라
귀무가설: 모평균이 특정 값과 동일

대립가설: (1) 양측검정의 경우, 모평균이 특정 값과 동일하지 않다
(2) 단측검정의 경우

t.test 이용
# MASS package에 포함되어 있는 cats data(Sex(성별), Bwt(몸무게), Hwt(심장무게)) 이용
library(MASS)
# H1: 몸무게의 평균이 2.6이 아니다.
t.test(cats$Bwt, mu=2.6)
One Sample t-test
data: cats$Bwt
t = 3.0565, df = 143, p-value = 0.002673
alternative hypothesis: true mean is not equal to 2.6
95 percent confidence interval:
2.643669 2.803553
sample estimates:
mean of x
2.723611
# H1: 몸무게의 평균이 2.7이 아니다.
t.test(cats$Bwt, mu=2.7)
One Sample t-test
data: cats$Bwt
t = 0.58382, df = 143, p-value = 0.5603
alternative hypothesis: true mean is not equal to 2.7
95 percent confidence interval:
2.643669 2.803553
sample estimates:
mean of x
2.723611
# H1: 몸무게의 평균이 2.6보다 크다.
t.test(cats$Bwt, mu=2.6, alternative="greater")
One Sample t-test
data: cats$Bwt
t = 3.0565, df = 143, p-value = 0.001337
alternative hypothesis: true mean is greater than 2.6
95 percent confidence interval:
2.656656 Inf
sample estimates:
mean of x
2.723611
# H1: 몸무게의 평균이 2.6보다 작다.
t.test(cats$Bwt, mu=2.6, alternative="less")
One Sample t-test
data: cats$Bwt
t = 3.0565, df = 143, p-value = 0.001337
alternative hypothesis: true mean is greater than 2.6
95 percent confidence interval:
2.656656 Inf
sample estimates:
mean of x
2.723611
# H0: 몸무게의 평균은 2.6이다.
# 99% 신뢰구간
t.test(cats$Bwt, mu=2.6, conf.level=0.99)
One Sample t-test
data: cats$Bwt
t = 3.0565, df = 143, p-value = 0.002673
alternative hypothesis: true mean is not equal to 2.6
99 percent confidence interval:
2.618031 2.829191
sample estimates:
mean of x
2.723611
# 성별에 따라 몸무게에 차이가 있는지 검정
# H0: 남녀간 평균 몸무게는 같다.
t.test(Bwt~Sex, data=cats)
Welch Two Sample t-test
data: Bwt by Sex
t = -8.7095, df = 136.84, p-value = 8.831e-15
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.6631268 -0.4177242
sample estimates:
mean in group F mean in group M
2.359574 2.900000
# 성별에 따라 몸무게에 차이가 있는지 검정
# H0: 남녀간 평균 몸무게는 같다.
Bwt.f=cats$Bwt[cats$Sex=="F"]
Bwt.m=cats$Bwt[cats$Sex=="M"]
t.test(Bwt.f,Bwt.m)
Welch Two Sample t-test
data: Bwt by Sex
t = -8.7095, df = 136.84, p-value = 8.831e-15
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.6631268 -0.4177242
sample estimates:
mean in group F mean in group M
2.359574 2.900000
▪ dataset: { 55,50,45,48,47,54,51,55,49,51}
▪ 귀무가설: 평균은 50이다.
▪ 대립가설: 평균은 50보다 크다
# default: 양쪽검정
x <- c(55,50,45,48,47,54,51,55,49,51)
dx<- x-50
t.test(dx)
One Sample t-test
data: dx
t = 0.464, df = 9, p-value = 0.6537
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-1.937584 2.937584
sample estimates:
mean of x
0.5
# default: 양쪽검정
t.test(dx)
One Sample t-test
data: dx
t = 0.464, df = 9, p-value = 0.6537
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-1.937584 2.937584
sample estimates:
mean of x
0.5
# 한쪽 검정
x <- c(55,50,45,48,47,54,51,55,49,51)
dx<- x-50
t.test(dx,alternative = 'greater’ )
One Sample t-test
data: dx
t = 0.464, df = 9, p-value = 0.3268
alternative hypothesis: true mean is greater than 0
95 percent confidence interval:
-1.475268 Inf
sample estimates:
mean of x
0.5
s전자에서 AS 센터 서비스에 대한 불만이 민원으로 접수되이, 센터를 방문한 고객을대상으로 서비스 만족도를 조사하고자 한다. 방문한 고객의 80% 이상이 서비스에 만족한다면 서비스에 관한 재교육을 실시하지 않고, 그렇지 않다면 재교육을 실시할 예정이다.
무작위로 선택된 100명의 고객을 대상으로 만족도를 조사한 결과, 일명의 고객이 서비스에 만족한다고 했다. 이에 대해 유의수준 0.05에서 검정하라.


# 표본크기 n=30, 앞면의 개수 x=18
# H1: 앞면이 나올 확률이 0.5가 아니다.
prop.test(x=18, n=30, p=0.5, alternative="greater")
1-sample proportions test with continuity correction
data: 18 out of 30, null probability 0.5
X-squared = 0.83333, df = 1, p-value = 0.1807
alternative hypothesis: true p is greater than 0.5
95 percent confidence interval:
0.4344744 1.0000000
sample estimates:
p
0.6
# H0: 4개 병원의 폐관련 질환 환자 수 대비 흡연자의 비율은 동일하다.
pa=c(86,93,136,82) # 4개 병원의 폐 관련 환자 수.
sm=c(83,90,129,70) # 폐 관련 환자 중 흡연자 수.
# H0: 4개 병원의 폐관련 질환 환자 수 대비 흡연자의 비율은 동일하다.
pa=c(86,93,136,82) # 4개 병원의 폐 관련 환자 수.
sm=c(83,90,129,70) # 폐 관련 환자 중 흡연자 수.
prop.test(x=sm, n=pa)
4-sample test for equality of proportions without continuity correction
data: sm out of pa
X-squared = 12.6, df = 3, p-value = 0.005585
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3 prop 4
0.9651163 0.9677419 0.9485294 0.8536585
# 4개 병원의 폐 관련 환자 수 대비 흡연자의 비율이 동일하다는 귀무
가설 기각
500 명의 소비자를 대상으로 신규 출시하는 제품에 대한 선호도를 조사하였더니
이 중 86 명이 선호하는 것으로 나타났다. 이를 기초로 신규 출시하는 제품에 대한
선호율이 20%인지 유의수준 5%로 검정하라.
# 표본크기 n=500, x=86
# H0: 선호율은 20%이다.
prop.test(x=86, n=500, p=0.2, alternative="greater")
1-sample proportions test with continuity correction
data: 86 out of 500, null probability 0.2
X-squared = 2.2781, df = 1, p-value = 0.9344
alternative hypothesis: true p is greater than 0.2
95 percent confidence interval:
0.1450926 1.0000000
sample estimates:
p
0.172
# 표본 4개
S1=c(89,90,92,66,44)
S2=c(56,66,77,90,44)
S3=c(67,80,91,99,34)
S4=c(45,34,56,82,34)
scores=data.frame(S1,S2,S3,S4)
scores
S1 S2 S3 S4
1 89 56 67 45
2 90 66 80 34
3 92 77 91 56
4 66 90 99 82
5 44 44 34 34
# 표본
4
개 summary
lapply
(scores,length
)
$S1
[1] 5
$S2
[1] 5
$S3
[1] 5
$S4
[1] 5
sapply
(scores,length
)
S1 S2 S3 S4
5 5 5 5
tests=lapply(scores,t.test)
tests
$S1
One Sample t-test
data: X[[i]]
t = 8.1583, df = 4, p-value = 0.001229
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
50.26735 102.13265
sample estimates:
mean of x
76.2
$S4
One Sample t-test
data: X[[i]]
t = 5.6182, df = 4, p-value = 0.004934
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
25.39157 75.00843
sample estimates:
mean of x
50.2
sapply(tests, function(t) t$conf.int) # tests=lapply(scores, t.test)
S1 S2 S3 S4
[1,] 50.26735 44.39538 42.55096 25.39157
[2,] 102.13265 88.80462 105.84904 75.00843