[R] Two sample t.test, order of comparions
Helmut Schütz
helmut.schuetz at bebac.at
Wed Apr 18 16:17:40 CEST 2007
Dear Charilaos!
Charilaos Skiadas wrote:
>>
>> Do you know a more elegant way than the clumsy one I have tried?
>>
>>> as.numeric(exp(result$estimate[2]-result$estimate[1]))
>>> as.numeric(exp(-result$conf.int[2]))
>>> as.numeric(exp(-result$conf.int[1]))
>
> First off, those three could probably be simplified slightly as:
> as.numeric(exp(-diff(result$estimate)))
> as.numeric(exp(-result$conf.int))
>
> The simplest solution I think is to specify that resp$treatment should
> have the levels ordered in the way you like them using this first:
>
> resp$treatment <- ordered(resp$treatment,
> levels=rev(levels(resp$treatment)))
>
> Then the t.test will show things in the order you want them.
I applied relevel() as suggested by Douglas and Dimitri:
> relevel(resp$treatment, ref = "Reference")
> result <- t.test(logAUC ~ treatment, data = resp, subset = (period ==
1), var.equal = FALSE, conf.level = 0.90)
> result
yielding
Welch Two Sample t-test
data: logAUC by treatment
t = 1.1123, df = 21.431, p-value = 0.2783
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
-0.0973465 0.4542311
sample estimates:
mean in group Reference mean in group Test
3.562273 3.383831
So right now the confidence interval in the log-domain is of the correct
order.
Your first suggestion is working (sign changed due to reversed level)
> as.numeric(exp(diff(result$estimate)))
> [1] 0.8365723
But still I have to apply
> as.numeric(exp(-result$conf.int[2]))
[1] 0.634936
> as.numeric(exp(-result$conf.int[1]))
[1] 1.102242
because
> as.numeric(exp(-result$conf.int))
[1] 1.102242 0.634936
in order to get the correct CI in the untransformed domain I had to sort
the list:
> sort(as.numeric(exp(-result$conf.int)))
[1] 0.634936 1.102242
Best regards,
Helmut
--
Ing. Helmut Schütz
BEBAC - Consultancy Services for
Bioequivalence and Bioavailability Studies
Neubaugasse 36/11
1070 Vienna, Austria
tel/fax +43 1 2311746
e-mail helmut.schuetz at bebac.at
web http://bebac.at
forum http://forum.bebac.at
More information about the R-help
mailing list