#install.packages("ISwR")
library(ISwR)
??vitcap
plot(vital.capacity~age, pch=group, data=vitcap)
attach(vitcap)
var.test(vital.capacity~group)
##
## F test to compare two variances
##
## data: vital.capacity by group
## F = 2.3105, num df = 11, denom df = 11, p-value = 0.1806
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6651437 8.0260128
## sample estimates:
## ratio of variances
## 2.310509
t.test(vital.capacity~group, conf.level = 0.99) # Welch Two Sample t-test at 99% confidence interval. Tow-sided
##
## Welch Two Sample t-test
##
## data: vital.capacity by group
## t = -2.9228, df = 19.019, p-value = 0.008724
## alternative hypothesis: true difference in means is not equal to 0
## 99 percent confidence interval:
## -2.06447665 -0.02219002
## sample estimates:
## mean in group 1 mean in group 3
## 3.949167 4.992500
The result of t-test can be misleading because we don’t know how the subjects were selected. There will be the effect of age, which can be confounding variable between groups and vital.capacity.
If the samples violate one or more of the t-test assumptions, the result of t-test analysis may be incorrect or misleading. If the assumption of independence is violated, the two-sample unpaired t-test is not appropriate; paired t-test is better. But, in this case of vitcap data, the group 1 and group 3 look independent. Another example is when the assumption of normality is violated, or outliers are persent. The sample size very small in the dataset of vitcap, and there seems to be several outliers in the plot. Therefore, the vitcap dataset has high possibility to violate the assumption of normality. Then, the t-test may not be the most powerful test.
plot(vas.active~vas.plac,pch=grp,data=ashina)
abline(0,1)
# The drug effect can be analyzed in a simple way if we compare the intra-individual differences regardless of the patient group
# Null hypothesis: Mean of vas.active is equal to Mean of vas.plac
# Alternative hypothesis: Mean of vas.active is not equal to Mean of vas.plac
attach(ashina)
t.test(vas.active,vas.plac,paired=T) # p-value 0.005644
##
## Paired t-test
##
## data: vas.active and vas.plac
## t = -3.2269, df = 15, p-value = 0.005644
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -71.1946 -14.5554
## sample estimates:
## mean of the differences
## -42.875
# The drug effect can be analyzed in an improved method by taking group into account.
# Null hypothesis: there is no drug effect Mean of vas.active = Mean of vas.plac
# Alternative hypothesis: Mean of vas.active is less than Mean of vas.plac
# use alt="l" option in the t.test
with(ashina,t.test((vas.active-vas.plac)[grp==1],-(vas.active-vas.plac)[grp==2])) # p-value 0.005807
##
## Welch Two Sample t-test
##
## data: (vas.active - vas.plac)[grp == 1] and -(vas.active - vas.plac)[grp == 2]
## t = -3.2517, df = 13.97, p-value = 0.005807
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -130.56481 -26.76853
## sample estimates:
## mean of x mean of y
## -53.50000 25.16667
# Here is another improved method to examine the drug effect in the two groups separately.
# Null hypothesis: there is no drug effect Mean of vas.active = Mean of vas.plac
# Alternative hypothesis: Mean of vas.active is less than Mean of vas.plac
p1 = with(ashina,t.test((vas.active-vas.plac)[grp==1], alt="l"))$p.v # p-value = 0.01024195
p2 = with(ashina, t.test((vas.active-vas.plac)[grp==2], alt="l") )$p.v # p-value = 0.07598672
## Fisher's combined p-value for detecting differences
# Null Hypothesis: the two p-values are the same
# Alternative hypotheis; the two p-values are different.
# df = 2*length(p-values)
1-pchisq(-2*log(p1*p2), df=2*2) # 0.006349341 This is one-sided test
## [1] 0.006349341
# or I can use like this
pchisq(-2*log(p1*p2), df=2*2, lower.tail=FALSE) # 0.006349341
## [1] 0.006349341
The drug effect can be analyzed in a simple way, t.test, if I compare the intra-individual differences regardless of the patient group. (I have to use Paired T-test because vas.active and vas.plac were measured in a patient). Then, I got a significant p-value 0.005644; the significance criteria is 0.05. This means I reject Null Hypothesis, and Alternative Hypothesis is accepted. This implies drug treatment is effective.
But, the drug effect can be analyzed in a better method by taking group data into account. It considers group1 and group2 patients data, and perform Welch two sample T-test. Then, I got p-value 0.005807.
with(ashina,t.test((vas.active-vas.plac)[grp==1],-(vas.active-vas.plac)[grp==2]))
To improve more, I can perform T-test individually in group1 and group2.
p1 = with(ashina,t.test((vas.active-vas.plac)[grp==1], alt="l"))$p.v
p2 = with(ashina, t.test((vas.active-vas.plac)[grp==2], alt="l") )$p.v
As I know “Mean of vas.plac”" is less than “Mean of vas.active”, I used option alt=“l” in each T-test. In group1, I got p-value 0.0102, but in group2, I got p-value 0.075. This means I reject null hypothesis in group1, but I can’t reject null hypothesis in group2. There is drug treatment effect in the group1, but no effect in group2.
Then, I can use “Fisher’s method to combine p-value” to examine the difference between the two p-values in group1 and group2. In the Fisher’s method, I got chi-square statistic p-value 0.0063. This is one-sided test, and the small value of the chi-square statistic indicates that the two p-values from group1 and group2 are different.
Study materials of Fisher’s combined p-value test for detecting differences
http://brainder.org/2012/05/11/the-logic-of-the-fisher-method-to-combine-p-values/ http://stats.stackexchange.com/questions/78596/when-combining-p-values-why-not-just-averaging http://bmcgenomics.biomedcentral.com/articles/10.1186/1471-2164-8-96 http://stats.stackexchange.com/questions/59360/fishers-method-for-combing-p-values-what-about-the-lower-tail