Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 통계학
- 신라
- linear regression
- 히스토그램
- post hoc test
- 고구려
- 한서지리지
- repeated measures ANOVA
- 지리지
- 패수
- 독사방여기요
- Histogram
- t test
- 창평
- ANOVA
- 후한서
- 낙랑군
- 우분투
- categorical variable
- 태그를 입력해 주세요.
- 단군
- spss
- 기자조선
- 한서
- 선형회귀분석
- 통계
- 기자
- 유주
- R
- 풍백
Archives
- Today
- Total
獨斷論
Independent samples t test (통계 R 초급 - 2) 본문
서로 다른 두 그룹의 차이를 비교하는 것이 independent samples t test이다.
예를 들어 담배를 피는 사람들과 안피는 사람들 사이의 단기 기억력을 비교한다고 하자. 각각의 그룹에 대해서 단기간 기억력을 조사한 것을 각각의 변수에 저장하면 아래와 같다.
> nonsmokers = c(18,22,21,17,20,17,23,20,22,21)
> smokers = c(16,20,14,21,20,18,13,15,17,21)
대략의 결과를 예측해보려면 두 데이터에 대해서 boxplot을 그려보면 된다.
> boxplot(nonsmokers,smokers,ylab="Scores on Digit Span Task", names=c("nonsmokers","smokers"))
그냥 한눈으로 봐도 두 평균의 차이가 좀 크다.
이걸 t test로 보여보자.
> t.test(nonsmokers,smokers,alternative="two.sided",var.equal=T)
Two Sample t-test
data: nonsmokers and smokers
t = 2.2573, df = 18, p-value = 0.03665
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.1801366 5.0198634
sample estimates:
mean of x mean of y
20.1 17.5
p-value가 0.037이므로 alternative hypothesis를 받아들일수 있다.
하지만 대개 위 그룹의 샘플의 분산이 같다고 가정하기는 어려우므로 아래와 같은 방법을 써야 한다.
> t.test(nonsmokers,smokers,alternative="two.sided",var.equal=F)
Welch Two Sample t-test
data: nonsmokers and smokers
t = 2.2573, df = 16.376, p-value = 0.03798
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.1628205 5.0371795
sample estimates:
mean of x mean of y
20.1 17.5
여기서도 마찬가지로 p-valuerk 0.038이 나왔고 공교롭게도 분산이 같다고 가정한 결과와 같은 결론을 내릴 수 있다.
위와 같이 수행할수도 있지만 regression formula를 이용하여 t.test를 수행하는 방법도 있다. 즉 y변수를 단기간 기억력의 값으로 놓고 x변수를 두 그룹으로 놓아 t.test를 수행하는 방법이다.
> scores = c(nonsmokers, smokers) #단기기억력샘플은 하나의 변수로 저장
> grp = c("nonsmokers", "smokers") #문자변수생성
> groups = rep(grp, c(10,10)) #grp를 각각 10개씩 만든다.
> smoke.data = data.frame(groups, scores) #지금까지 만든 값을 data.frame형식으로 생성
> smoke.data # 아래 결과를 보면 무엇을 하려는 것인지 이해가 될것임...
groups scores
1 nonsmokers 18
2 nonsmokers 22
3 nonsmokers 21
4 nonsmokers 17
5 nonsmokers 20
6 nonsmokers 17
7 nonsmokers 23
8 nonsmokers 20
9 nonsmokers 22
10 nonsmokers 21
11 smokers 16
12 smokers 20
13 smokers 14
14 smokers 21
15 smokers 20
16 smokers 18
17 smokers 13
18 smokers 15
19 smokers 17
20 smokers 21
> t.test(smoke.data$scores ~ smoke.data$groups) # t test수행
Welch Two Sample t-test
data: smoke.data$scores by smoke.data$groups
t = 2.2573, df = 16.376, p-value = 0.03798
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.1628205 5.0371795
sample estimates:
mean in group nonsmokers mean in group smokers
20.1 17.5
좀 지루하게 길지만 linear regression과 ANOVA를 이해하는데 도움이 되니 한번씩 수행해 보는게 좋을 것이다. 결과는 이렇게 하나 저렇게 하나 똑같다.
Comments