[R] Help in using multcomp.
Chuck Cleland
ccleland at optonline.net
Sat Feb 10 15:33:54 CET 2007
A Ezhil wrote:
> Hi Chuck,
>
> Thank you very for this help. I am able to store the
> results. Now, I am facing the following problems:
>
> 1. I am trying to extract only the p-values from
>
> dunres <- lapply(amod, function(x){summary(glht(x,
> linfct=mcp(f = contr)))})
>
> but I am stuck. If I use dunres[[1]], it displays the
> results. But I don't know how to extract the p value
> from this.
Ezhil:
str(summary(glht(amod[[1]], linfct=mcp(f = contr)))) suggests a way to
extract just the p values. Try this:
library(multcomp)
dat <- matrix(rnorm(45), nrow=5, ncol=9)
f <- gl(3,3,9, label=c("C", "Tl", "T2"))
aof <- function(x) {
m <- data.frame(f, x);
aov(x ~ f, m)
}
amod <- apply(dat,1,aof)
my.pvals <- sapply(amod, function(x){summary(glht(x, linfct=mcp(f =
contr)))$test$pvalues})
rownames(my.pvals) <- rownames(contr)
colnames(my.pvals) <- paste("amod", 1:5, sep="")
my.pvals
amod1 amod2 amod3 amod4 amod5
C - T1 0.03348242 0.3581771 0.9873633 0.9764219 0.9225445
C - T2 0.67794496 0.7138491 0.2183949 0.9962458 0.8439224
C - All T 0.10621039 0.4344881 0.4913578 0.9970689 0.8519888
> 2. If I want to get raw pvalues instead of adjusted
> ones, what should I do in summary(glht)?
See the test argument of summary.glht(). You could do something like
this:
my.pvals <- sapply(amod, function(x){summary(glht(x, linfct=mcp(f =
contr)), test = adjusted("none"))$test$pvalues})
rownames(my.pvals) <- rownames(contr)
colnames(my.pvals) <- paste("amod", 1:5, sep="")
my.pvals
amod1 amod2 amod3 amod4 amod5
C - T1 0.01770489 0.2197886 0.8985143 0.8611198 0.7466660
C - T2 0.46651736 0.4994115 0.1278132 0.9448342 0.6364631
C - All T 0.05953715 0.2733017 0.3149223 0.9512189 0.6464735
hope this helps,
Chuck Cleland
> Thanks again for your help. I look forward to your
> reply.
>
> Kind regards,
> Ezhil
>
>
> --- Chuck Cleland <ccleland at optonline.net> wrote:
>
>> A Ezhil wrote:
>>> Hi All,
>>>
>>> I am trying use 'multcomp' for multiple
>> comparisons
>>> after my ANOVA analysis. I have used the following
>>> code to do ANOVA:
>>>
>>> dat <- matrix(rnorm(45), nrow=5, ncol=9)
>>> f <- gl(3,3,9, label=c("C", "Tl", "T2"))
>>>
>>> aof <- function(x) {
>>> m <- data.frame(f, x);
>>> aov(x ~ f, m)
>>> }
>>> amod <- apply(dat,1,aof)
>>>
>>> Now, how can I use 'glht' for the above amod. I
>> know
>>> that I cannot use simply
>>>
>>> glht(amod, linfct = mcp(f = "Dunnett")).
>> Since amod is a list of models rather than one
>> model, do you want
>> something like this?
>>
>> lapply(amod, function(x){summary(glht(x, linfct =
>> mcp(f = "Dunnett")))})
>>
>>> Also, if I want to use Dunnett for comparing C vs
>> (T1
>>> and T2), how can I specify this in the glht
>> function.
>>
>> How about doing it with user-defined contrasts?
>>
>> contr <- rbind("C - T1 " = c(-1, 1, 0),
>> "C - T2 " = c(-1, 0, 1),
>> "C - All T" = c(-1,.5,.5))
>>
>> lapply(amod, function(x){summary(glht(x, linfct =
>> mcp(f = contr)))})
>>
>>> Thanks in advance.
>>> Regards,
>>> Ezhil
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained,
>> reproducible code.
>>
>> --
>> Chuck Cleland, Ph.D.
>> NDRI, Inc.
>> 71 West 23rd Street, 8th floor
>> New York, NY 10010
>> tel: (212) 845-4495 (Tu, Th)
>> tel: (732) 512-0171 (M, W, F)
>> fax: (917) 438-0894
>>
>
>
>
>
> ____________________________________________________________________________________
> Need a quick answer? Get one in minutes from people who know.
> Ask your question on www.Answers.yahoo.com
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list