2013년 8월 20일 화요일

T-test (two samples)-No25

Today I am going to introduce t-test for two samples.

t-test is a statistical hypothesis test to compare two group.
t-test uses a mean and standard deviation of sample data to determine whether the population means of two group have a relation or not.
Actually, there is an another test which is ANOVA (analysis of variance) has a same purpose. Usually t-test is much more simple than ANOVA test.

This test might be applied in many cases. Such as following
case1) Income gab between city and urban.
case2) New medicine test for patient




There is some prerequisite condition in order to get a reliable result.
The variance of two group population should be equal. By this assumption, test method would be different.
R also provide the method to determine whether two group has a same variation or not..
(var.test( x, y) )

As I said, this is a hypothesis test so null hypothesis is that "true difference in means is equal " and alternative hypothesis is "true difference in means is not equal "

This test would be different in accordance with the way of your sample such as independent samples or paired samples.
The case1 above can be a independent test, given that there is no movement during test.
The case2 can be a paired test because tester should be tested twice before taking a medicine and after taking the medicine.


Let's do it right now.

I would like to verify if a brand new high blood pressure pill affects patients.
> before <- c(150,140,130,140,135,150)
> after <- c(130,120,110,120,110,100)

You might judge this easily this pill affects patients.















(1 : before medicine,
 2 : after medicine)



Before conducting t-test I should verify the equality of variances.
Null hypothesis of this test is that ratio of  two variances is equal.

> var.test(before,after)

        F test to compare two variances

data:  before and after
F = 0.5833, num df = 5, denom df = 5, p-value = 0.5686
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.08162639 4.16872273
sample estimates:
ratio of variances
         0.5833333

Considering above result, we can assume that ratio of variances is equal so that we are able to conduct simple t-test instead of "Welch Two Sample t-test.
As I said earlier, this test should be conducted under paired test condition.


> t.test(before,after, paired=T)

        Paired t-test

data:  before and after
t = 5.2702, df = 5, p-value = 0.003271
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 13.23282 38.43385
sample estimates:
mean of the differences
               25.83333


As you can see this test lead us to make a conclusion that there is a difference between two data group. In other words, this brand new pill has an effect of something to patient.






댓글 없음:

댓글 쓰기