6. 추 정 (estimation)hosting03.snu.ac.kr/~hokim/int/2017/chap_6.pdf · 2017-04-10 · 6.1...
TRANSCRIPT
6.1 머리말 (Introduction)
• 통계적 추론 (statistical inference)
– 어느 모집단으로부터 구한 표본에서
얻어진 결과를 기초로 그 모집단에 관해추측하는 과정
– To say something about the population based on the information of the sample
1) 추정(estimation)
2) 가설검정(hypothesis testing)
• 추정치(estimate)
1) 점추정(point estimate)
2) 구간추정(interval estimate)
• 추정식(estimator)
• 불편이성(unbiasedness)
3ix
xn
의추정식
2
ˆ( . . based on data) is an unbaised estimator of (parameter)
ˆif ( )
. ( ) , so sample mean is an ue of the population mean
if the samples are randomly selected from ( , )
r v
E
ex E X
N
* 예) sample variance (𝑆2) is an unbiased estimator of 𝜎2
So 𝐸(𝑆2) = 𝜎2
: not an unbiased estimator
• Bias =
• Bias of an unbiased estimator is zero
• Probability sampling and non-probability sampling
• Randomization
• Blinding
2 21( )iE y y
n
ˆ( )E
• 표집모집단과 목표모집단 (sampled population and target population)
• 랜덤표본과 비랜덤표본 (random sample and non-random sample)
– 편의표본 (convenience sample)
6.2 모집단평균의 신뢰구간(Confidence interval of population mean)
• 추정량 ± 신뢰성계수 × 표준오차
estimator ± reliability coefficient × standard error
𝑥 ± 𝑧1−
𝛼
2
𝜎 𝑥 , 𝑃 𝑍 < 𝑧1−
𝛼
2
= 1 −𝛼
2
• If we select samples repeatedly from normal population, 𝑥 ± 𝑧
1−𝛼
2
𝜎 𝑥 will include 𝜇 with the
probability of 100 1 − 𝛼 %
• 1 − 𝛼:confidence level (ex. .95) 신뢰수준
𝛼 :significance level (ex. .05) 유의수준
• 정밀도(precision), 오차범위 (margin of error): reliability coefficient × standard error
<Ex 6.2.1>
연구자가 특정 집단의 효소의 평균을 추정하기위하여 10명의 표본을 뽑아 효소값을 측정했다. 그 결과 표본평균 𝑥 = 22이었다. 효소값은분산이 45인 정규분포를 따른다고 할 때, 𝜇의95% 신뢰구간을 추정하라.
A researcher measures amount of a certain enzyme. n=10, sample mean=22, We can assume normality with pop variance=45. . 95% C.I. of ?
𝑥 ± 1.96𝜎 𝑥 ⇒ 22 ± 1.9645
10
= 22 ± 1.96 2.1213 ⇒ 17.84, 26.16
<Ex 6.2.2>
물리치료사가 한 집단의 개인에 대한 특정 근육의 최대근력의 평균치를 99% 신뢰수준에서 추정하려고 한다. 근력 지수는 분산이 144인 정규분포를 따른다고 한다. 실험에 참가한 15명의 근력 지수 평균은 84.3이다.
Measuring maximum strength of a certain muscle. We want 99% CI of the pop mean. We assume normality with pop variance=144. n=15, sample mean=84.3,
• 신뢰수준 0.99에 대응되는 신뢰성계수는 R 함수 qnorm(0.995)에 의해 2.58
• 표준오차는 𝜎 𝑥 = 12 15 = 3.0984
• 𝜇에 대한 99% 신뢰구간은
• 84.3 ± 2.58 3.0984 = 84.3 ± 8.0 ⟹ (76.3, 92.3)
• 정규모집단이 아닌 경우
• Sample from non-normal popcentral limit theorem
<Ex 6.2.3>
환자 35명의 지각 시간 조사. 평균=17.2분이고, 모표준편차= 8분. 모집단이 정규분포를 따르는지 모른다는 가정하에 지각 시간의 모평균 𝜇에 대한 90% 신뢰구간?.
delay time because of patient’s being late at a clinic, n=35, sample mean=17.2 min, sd from the previous study (assumed to be known)=8 min. Pop is not normally dist’ed.
what is 90% CI of ?
Sol) Sample size is big enough (=35>30) -> apply CLT
• qnorm(0.95)= 1.645이다. 𝜎 𝑥 =8
35= 1.3522
• 17.2 ± 1.645 1.3522 = 17.2 ± 2.2 ⇒ 15.0, 19.4
* <Ex 6.2.4> when pop variance is not known.
birth.csv 자료에서 bweight의 95% 신뢰구간을 구하시오.
(95% confidence interval of the variable bweight in birth.csv data)
Sol) birth <- read.csv(‘C:\\Users\\owner\\Desktop\\보건통계학개론\\birth.csv',header=T)
head(birth) ; x <- birth$bweight
n<- length(x)
mean(x)-qnorm(0.975)*sd(x)/sqrt(length(x))
mean(x)+qnorm(0.975)*sd(x)/sqrt(length(x))
summary(x)
sd(x)
* CI calculation using R
m <- mean(x) ; m
s <- sqrt(var(x)) ; s
n <- length(x) ; n
alpha <- 0.05
error <- qnorm(1-alpha/2)*s/sqrt(n)
left <- m-error
right <- m+error
left; right confint <- function(m,s,n,alpha=0.05){error <- qnorm(1-alpha/2)*s/sqrt(n)left <- m-errorright <- m+errorprint(c(left,right)) }
confint(m,s,n) confint(0.7164,sqrt(0.36),35)
[중위수를 이용한 추정]Estimating population mean using median of the sample.
Robust 한 결과를 준다 -> 오차가 많이 포함된 경우에 선호
[절사평균] 가장 크고 작은 관찰치들을 제거한 후 평균 계산 -> robust 한 결과를 준다. Trimmed mean
> x<-c(1:9,100)> mean(x); ?mean[1] 14.5> mean(1:10, trim=0.1)[1] 5.5> mean(2:9)[1] 5.5> mean(x, trim=0.5);median(x)[1] 5.5[1] 5.5
6.3 t-분포 (t-dist’n)
• 모분산이 알려져 있고 표본수가 충분히 큰 경우에는
𝑍 = 𝑋−𝜇
𝜎/ 𝑛에 표준정규분포를 적용한다.
(Pop variance is known and n is large-> use Z)
• 모분산을 모르지만 표본수가 충분히 큰 경우에는 𝑠 =
𝑥𝑖 − 𝑥 2/(𝑛 − 1)를 𝜎대신에 사용한다. (Pop
variance is not known and n is large : use 𝑠 insteadof 𝜎)
• 표본수가 적은 경우 (n<30) Small sample size :
derived by Gosset “Student’s t-dist’n”
𝑡 = 𝑋−𝜇
𝑆/ 𝑛~𝑡𝑛−1
T-분포의 특성(Some properties of t-dist’n)
1) 평균은 0 (mean= 0)
2) 확률밀도함수가 평균에 대해서 대칭 (Symmetric about the mean)
3)
4), 5) 분산=df/(df-2) for df >2, -> 1 as n -> ∞ Variance=df/(df-2) for df >2, -> 1 as n -> ∞
6) t-분포는 정규분포에 비해 꼬리가 두꺼운 형태.
Tail of t-dist’n is thick than that of normal dist’n.
7) 자유도가 커질수록 정규분포에 근사
T-dist’n approaches to normal dist’n as df increases
t
[신뢰구간] CI :
𝑥 ± 𝑡𝑑𝑓=𝑛−1, 1− 𝛼 2
𝑠
𝑛
Ex 6.3.1
𝑛 = 19인 관측값의 평균은 250.8, 표준편차는 130.9라고한다. 모집단이 정규분포를 따른다고 할 때, 모평균의95% 신뢰구간을 구하라.
n=19, measure physical strength mean=250.8, sd=130.9, pop variance is not known. 95% CI of the pop mean?
𝑥 = 250.8, 𝑠/ 𝑛 = 130.9/ 19 = 30.0305, df = 𝑛 − 1 = 18이다. qt(0.975,df=18), 𝑡df=18,0.975 = 2.1009
250.8 ± 2.1009 30.0305 = 250.8 ± 63.1 ⟹ (187.7, 313.9)
*
x <- seq(-4, 4, length=100)hx <- dnorm(x)
degf <- c(1, 3, 8, 30)colors <- c("red", "blue", "darkgreen", "gold", "black")labels <- c("df=1", "df=3", "df=8", "df=30", "normal")
plot(x, hx, type="l", lty=2, xlab="x value",ylab="Density", main="Comparison of t Distributions")
for (i in 1:4){lines(x, dt(x,degf[i]), lwd=2, col=colors[i])
}
legend("topright", inset=.05, title="Distributions",labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
6.4 두 모집단 평균차이의 신뢰구간(CI of the difference of the two means)
• Samples from normal pop’s
𝑥1 − 𝑥2 ± 𝑧1−
𝛼
2
𝜎12
𝑛1+
𝜎22
𝑛2
<Ex 6.4.1> 어떤 대형병원에서 12명의 다운증후군 환자들로부터 계산한 혈청 요산 수치의 평균값은 𝑥1 =4.5mg/100ml이고, 동일 연령, 동일 성별인 정상인 15명으로부터 구한 혈청 요산 수치의 평균은 𝑥2 =3.4mg/100ml이라고 한다. 만약 두 모집단이 분산이각각 1, 1.5인 정규분포를 따른다고 할 때, 𝜇1 − 𝜇2의95% 신뢰구간을 구하라.
<Ex 6.4.1>
Measure serum uric acid from 12 patients 𝑥1 =4.5mg/100ml, measurements from 15 normal controls 𝑥2 = 3.4mg/100ml, variances are known to be 1 and 1.5 for pt and ct group, 95% CI for 𝜇1 −𝜇2 ?
Sol) 𝜎 𝑥1− 𝑥2=
𝜎12
𝑛1+
𝜎22
𝑛2=
1
12+
1.5
15= 0.4282
1.1 ± 1.96 0.4282 = 1.1 ± .84 ⟹ 0.26, 1.94
CI does not include 0
[모집단이 정규분포를 따르지 않을 때의 신뢰구간]
Sample from non-normal pop ->central limit theorem
<보기 6.4.2>
To compare # cigarettes for pregnant women for two groups
A: 𝑛1 = 328, 𝑥1 = 5.2, 𝑠 = 6.33,
B: 𝑛2 = 64, 𝑥2 = 15, 𝑠 = 7.16,
99% CI of ?
Sample sizes are enough
𝑠 𝑥1− 𝑥2=
6.332
328+
7.162
64= 0.96
−9.8 ± 2.58 0.96 ⇒ (−12.28,−7.32)
• 평균비교시 t-분포를 사용할 때
• (t-dist’n and difference of the means)
1) 모분산이 동일 할 때 (Same variances),
2) 모분산이 동일하지 않을 때 (Different variances)
- 모분산이 동일한 경우: 합동추정량을 사용한다.
(When the variances are the same: we calculate pooled estimate by calculating weighted average of the
variances) 𝑠𝑝2 =
𝑛1−1 𝑠12+ 𝑛2−1 𝑠2
2
𝑛1+𝑛2−2, 𝑠 𝑥1− 𝑥2
=𝑠𝑝2
𝑛1+
𝑠𝑝2
𝑛2
𝜇1 − 𝜇2에 대한 100 1 − 𝛼 % 신뢰구간 𝐶𝐼 :
( 𝑥1 − 𝑥2) ± 𝑡𝑛1+𝑛2−2,(1− 𝛼 2)
𝑠𝑝2
𝑛1+
𝑠𝑝2
𝑛2
-모분산이 동일하지 않은 경우 (When the variances are different)
does not follow t-dist!1 2 1 2
2 21 2
1 2
( ) ( )x x
s s
n n
1 1 2 21 2
1 2
'w t w t
tw w
2 2
1 21 2 (1 2)
1 2
( ) 's s
x x tn n
2 21 1 1 2 2 2
1 1 1 2 2 2 1 2
* , ,
1 , 1
w s n w s n
df n t t df n t t
<Ex 6.4.3>18명의 조현병 환자의 치료 일수의 평균은 4.7일, 표준편차는 9.3이다. 또한 10명의 조울증 환자들의 치료 일수 평균은 8.8일, 표준편차는 11.5이다. 두 표본을 이용하여 두 모평균 차이의 95% 신뢰구간을 구하라
n mean sd n mean sd
Dx A: 18 4.7 9.3 Dx B:10 8.8 11.5
1 295% CI of ?
동일분산의 가정 하에서(if we assume that the variances are the same) 분산의 합동추정치(pooled estimate of the variance)
𝑠𝑝2 =
)18 − 1 9.32 + 10 − 1 (11.52
18 + 10 − 2= 102.33
모평균의 신뢰구간 4.7 − 8.8 ± 2.0555102.33
18+
102.33
10=
− 4.1 ± 8.20 ⟹ −12.3, 4.1
<Ex 6.4.4> 분산이 다르다고 가정한다면 (under the heterogeneous assumption)
t17 t9
t′ = 9.32 18 2.1098 + 11.52 10 2.2622
9.32 18 + 11.52 10= 2.2216
4.7 − 8.8 ± 2.2216 4.246175−13.5, 5.3
4.7 − 8.8 ± 2.22169.32
18+
11.52
10
6.5 모집단 비율의 신뢰구간(CI of proportion)
<Ex 6.5.1> 1,000명의 의약품 사용자, 20%는 정보검색위하여 인터넷 사용. 모비율의 95% 신뢰구간?
n=1,000, 20% internet user
𝑝에 대한 100 1 − 𝛼 % 신뢰구간
𝑝 ± 𝑧1−
𝛼
2
𝑝 1− 𝑝
𝑛
𝑝(1 − 𝑝 ) 𝑛 = 0.20)(0.80 ) 1000 = .013
0.20 ± 1.96 0.013 = 0.20 ± 0.025⇒ 0175, 0.225
6.6 두 모집단 비율의 차이의 신뢰구간CI of difference of two proportions
𝑝1 − 𝑝2의 100 1 − 𝛼 % 신뢰구간 (CI)
𝑝1 − 𝑝2 ± 𝑧1−
𝛼
2
𝑝1 1− 𝑝1
𝑛1+
𝑝2 1− 𝑝2
𝑛2
<Ex 6.6.1>73명의 여자와 315명의 남자로 구성된 388명의 어린이와 청소년의 확률표본에서 21명의 여자와 45명의 남자가자살충동을 느낀 경험이 있다고 한다. 두 모집단에서 자살충동을 느낀 사람의 비율의 차이에 대한 99% 신뢰구간을 구하라.
6.6 두 모집단 비율의 차이의 신뢰구간CI of difference of two proportions
<Ex 6.6.1> Out of 73 female, 315 male, 21, 45 said yes (suicidal thoughts) 99% CI for the difference
𝑝𝐹 = 21 73 = 0.2877, 𝑝𝑀 =45
315= 0.1429
𝑝𝐹 − 𝑝𝑀 = 0.2877 − 0.1429 = 0.1448
𝜎 𝑝𝐹− 𝑝𝑀=
(0.2877)(0.7123)
73+
0.1429 (0.8571)
315= 0.0565
qnorm(0.995)=2.58
0.1448 ± 2.58 0.0565 ⟹ (−0.0010, 0.2906)
6.7 표본 크기의 결정: 모평균sample size calculation: inference of the mean
표본의 크기가 크거나 혹은 복원추출하는 경우
(when sample size is enough or sampling w replacement)
𝑑 = 𝑧1−𝛼/2𝜎
𝑛: 신뢰구간의 한쪽 방향의 길이 (width CI/2)
𝑛 =𝑧1−𝛼/22 𝜎2
𝑑2
표본의 크기가 작고 비복원추출하는 경우
(when sample size is not enough and sampling w/o replacement)
𝑑 = 𝑧𝜎
𝑛
𝑁−𝑛
𝑁−1
𝑛 =𝑁𝑧1−𝛼/2
2 𝜎2
𝑑2 𝑁−1 +𝑧1−𝛼/22 𝜎2
[분산의 추정]Estimation of the variance
1. 모집단으로부터 시험표본(pilot sample)을 뽑고, 시험표본으로부터 표본분산을 이용하여 필요한 표본의 크기를 계산할 수 있다. 시험표본은 나중에 뽑을 표본과함께 분석에 활용할 수 있다. 따라서 필요한 표본의 크기는 (산출된 표본크기) – (시험표본의 크기)이다.
2. 이전 (previous) 혹은 유사(similar)한 연구(studies)에서 𝜎2의 추정값을 이용할 수 있다.
3. 모집단이 정규분포를 따를 때, 범위는 대략적으로 표준편차의 6배(𝜎 ≈ R/6)이다. 따라서 모집단의 최솟값과 최대값을 알면 표준편차의 추정값을 얻을 수 있다.
<Ex 6.7.1> 신뢰구간의 폭은 20, 신뢰수준은 0.95, 그리고모분산은 15라고 할 때, 표본의 크기를 구하는 과정을 설명하라.
Width of CI=20 (+-10). Confidence level= 0.95, pop sd=15, pop is very large; we can ignore finite pop correction factor
𝑧1− 𝛼 2 = 1.96, 𝜎 = 15, 𝑑 = 10
𝑛 =1.96 2 15 2
10 2 = 8.6436 -> 9
무한모집단 (Infinite population) 𝑛 =𝑧1−𝛼/22 𝑝𝑞
𝑑2
유한모집단 (finite population) 𝑛 =𝑁𝑧1−𝛼/2
2 𝑝𝑞
𝑑2 𝑁−1 +𝑧1−𝛼/22 𝑝𝑞
모집단 크기가 충분히 크면 유한모집단 가정 가능
If 𝑛/𝑁 ≤ .05 infinite pop can be assumed.
6.8 표본 크기의 결정: 모비율sample size calculation: inference of the proportion
[모비율의 추정] Estimating the pop. proportion
• 시험표본(pilot study)으로부터 계산한 점추정값을 모비율로 이용할수 있다.
• 이전 연구나 유사한 연구(previous or similar studies) 에서 p의 추정값을 이용할 수 있다.
• p를 제외한 다른 값들이 고정되어 있다고 가정하자. p가 0.5일 때표본의 크기가 최대가 된다. 따라서 p에 대하여 알려진 사실이 전혀없으면 0.5를 이용하여 표본의 크기를 계산할 수 있다. 하지만 이럴경우 필요 이상으로 표본의 크기가 커지므로, 연구에 필요한 비용이증가함을 기억하자. (n is maximized when p=.5. You may assume p=0.5 if you have no idea.)
• 만약 p의 범위를 알고 있다고 하자. 범위에 들어가는 값들 중에서표본의 크기를 최대로 만들어주는 p를 이용하여 표본의 크기를 계산할 수 있다. 표본의 크기를 최대로 만들어주는 p의 값은 식(6.8.1), (6.8.2)의 경우 0.5에 가장 가까운 값이다. 가령 성차별을경험한 여성의 비율에 대하여 추정한다고 가정하자. 이때 성차별을경험한 여성의 비율 p는 0.40보다 클 수 없다는 사실이 알려져 있다면, p의 값으로 0.40를 이용하면 된다. (If you know the range of p, choose p closest to .5)
<Ex 6.8.1> 어떤 도시에서 아파트에 거주하는 사람의 비율을 추정하려고 한다. 아파트에 거주하는 사람의 비율이0.45보다 작다고 알려져 있다. 이때 신뢰구간의 폭이0.1보다 작으며, 95%의 신뢰도를 갖는 신뢰구간을 얻기위하여 필요한 표본의 크기를 구하라.
proportion living in an apartment. We know p<0.45.
We want that width of 95% CI < 0.10, n=?
𝑛 =𝑧1−𝛼/22 𝑝𝑞
𝑑2=
1.96 2 0.45 0.55
0.05 2= 380.3184 → 381
6.9 정규분포 모집단 분산의 신뢰구간CI of the variance from normal dist’n
• Point estimator of variance
각 표본이 정규분포에서 나왔다면 (under the normal assumption)
𝐸( 𝑖=1𝑛 𝑥𝑖 − 𝑥 2) = (𝑛 − 1)𝜎2
𝐸(1
𝑛−1 𝑖=1
𝑛 𝑥𝑖 − 𝑥 2) =𝜎2 → 𝐸(𝑆2)=𝜎2
Good estimator? ‘unbiasedness’
• * 일반적으로 모수 𝜃를 추정하기 위한 방법은 수없이 많으며 그 중에서 bias를 0로 하면서(unbiased estimator) 분산을 최소화시키는 방법이 이상적이라고 할 수 있다 -> 이러한 방법을Uniformly Minimum Variance Unbiased Estimator (UMVUE) 이라고 한다.
• UMVUE (Uniformly Minimum Variance Unbiased Estimator) is a very good estimator satisfying unbiasedness with small variance.
• 표본평균은 정규분포 조건하에서 모평균의 최소분산불편추정치이다. (sample mean is the UMVUE of the pop mean under the normal assumption.)
• 카이제곱 분포 (chi-square distribution)
𝑛−1 𝑆2
𝜎2 =(𝑛−1)
𝜎2
1
𝑛−1 𝑖=1
𝑛 𝑥𝑖 − 𝑥 2 = 𝑖=1𝑛 (𝑥𝑖− 𝑥)2
𝜎2
~𝜒2(df = 𝑛 − 1)
𝜒df,𝛼2
𝛼
카이제곱 분포의 확률밀도함수(Chi-square distribution)
카이제곱 분포의 분위수(Quantiles of Chi-square distribution)
2
2 22 2
/ 2 (1 / 2)2 2
2 22 2
2 2(1 / 2) / 2
100(1 )%
( 1) ( 1) 100(1 )%
( 1) ( 1) 100(1 )%
n s n s
n s n s
CI of ?
CI of
CI of
<Ex 6.9.1>
다음은 10명의 2형 당뇨병 환자의 공복혈을 측정한 결과이다.
150.3, 140.1, 144.3, 155.3, 175.4, 182.9, 140.7, 143.7, 139.0, 142.3
Under the normal assumption, what is 95% CI of the pop variance?
Sol) 𝑠2 = 241.4578이고, qchisq(0.975, df=9), qchisq(0.025, df=9)𝜒0.975
2 = 19.0228, 𝜒0.0252 = 2.7004
9(241.4578)
19.0228< 𝜎2 <
9(241.4578)
2.7004⇔ 114.2365 < 𝜎2 < 804.7401
6.10 두 정규분포 모집단의 분산비의 대한 신뢰구간CI for the ratio of two variances
• F-distribution
1 2
2 21 1
1, 12 22 2
n n
sF
s
•
<Ex 6.10.1> 여성 16명의 체질량 지수의 표준편차는 5.84이고, 4명의 남성 체질량 지수의 표준편차는 6.3이었다고 한다. 남성과 여성의 분산의 비에 대한 95% 신뢰구간을 구하라.
normal adults, n=16 females and 4 males. Sample sd’sare 5.84 and 6.3. 95% C.I. of the ratio of the variances?
21
22
100(1 )%
CI of ?
2 2 2 2 2 2 21 1 1 2 1 1 2
/ 2 (1 / 2)2 2 2(1 / 2) / 22 2 2
,s s s s s
F FF Fs
𝑛1 = 16 𝑛2 = 4 s12 = 5.84 2 = 34.11, 𝑠2
2 = 6.3 2 = 39.69
df1 = 15, df2 = 3 -> F0.025 = 0.24096 F0.975 = 14.25 .34.11/39.69
14.2527<
𝜎12
𝜎22 <
34.11/39.69
0.2408⇒ 0.0603 <
𝜎12
𝜎22 < 3.5690
> qf(0.025,15,3)
[1] 0.2408012
> qf(0.975,15,3)
[1] 14.25271
[𝐅𝐝𝐟𝟏,𝐝𝐟𝟐,𝟏−(𝜶/𝟐)와 𝐅𝐝𝐟𝟏,𝐝𝐟𝟐, 𝜶 𝟐의 관계]
Fdf1,df2,1−α =1
Fdf2,df1,𝛼
> qf(0.975,3,15)
[1] 4.152804
> 1/qf(0.025,15,3)
[1] 4.152804
*[Levene’s test: 등분산성 검정 (Homogeneity test)]
library(car)
male <- c(10.673, 14.103, 25.731, 30.081)
female <- c(26.086, 13.372, 25.195, 15.402, 22.537, 20.860, 22.409, 18.106, 19.779, 17.651, 24.403, 18.474, 15.063, 14.624, 9.136, 40.354)
data <- c(male,female)
leven.test(male,female)
leveneTest(male,female)
?leveneTest
group <-c(rep(1,length(male)),rep(2,length(female)))
leveneTest(data,factor(group))
t.test(male,female)
?t.test
t.test(male,female,var.equal=T)
> t.test(male,female)
Welch Two Sample t-test
data: male and female
t = -0.0139, df = 3.936, p-value = 0.9896
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.90105 13.76368
sample estimates:
mean of x mean of y
20.14700 20.21569
> t.test(male,female,var.equal=T)
Two Sample t-test
data: male and female
t = -0.0164, df = 18, p-value = 0.9871
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-8.883343 8.745968
sample estimates:
mean of x mean of y
20.14700 20.21569
> leveneTest(data,factor(group))Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)group 1 1.1221 0.3035
18 >
* SAS Example: Two Independent Samples
dataset: bullets Bullets Dataset
Obs powder velocity
1 1 27.3
2 1 28.1
3 1 27.4
4 1 27.7
5 1 28.0
6 1 28.1
7 1 27.4
8 1 27.1
9 2 28.3
10 2 27.9
11 2 28.1
12 2 28.3
13 2 27.9
14 2 27.6
15 2 28.5
16 2 27.9
17 2 28.4
18 2 27.7
proc ttest data=bullets;
var velocity;class powder;
run;
The TTEST Procedure
Lower CL Upper CL Lower CL
Variable powder N Mean Mean Mean Std Dev
velocity 1 8 27.309 27.638 27.966 0.2596
velocity 2 10 27.841 28.06 28.279 0.2106
velocity Diff (1-2) -0.771 -0.422 -0.074 0.2582
Upper CL
Variable powder Std Dev Std Dev Std Err Minimum Maximum
velocity 1 0.3926 0.799 0.1388 27.1 28.1
velocity 2 0.3062 0.5591 0.0968 27.6 28.5
velocity Diff (1-2) 0.3467 0.5276 0.1644
Variable Method Variances DF t Value Pr > |t|
velocity Pooled Equal 16 -2.57 0.0206
velocity Satterthwaite Unequal 13.1 -2.50 0.0267
Equality of Variances
Variable Method Num DF Den DF F Value Pr > F
velocity Folded F 7 9 1.64 0.4782
For H0: Variances are equal, F = 1.64 DF = (7,9)
• * Statistical distributions
: sum of n independent normal rv’s
21 2, , , N( , ) nY Y Y random sample from iid
2
,Y Nn
22
212
1
( 1) ni
n
i
Y Yn s
0,1/
YN
n
1
/n
Yt
s n
2n
2
2
1
(0,1)n
i in
i
Y YN
22 2
/ 2, 1 1 / 2, 12
( 1)1n n
n sP