Skip to content

Compare one level of a factor with *all* other non-missing levels

4 messages · Peter Ehlers, deriK2000

#
Dear list,

I try to compare the mean of a variable given a value of a factor with the
mean of the same variable for all K-1 other non-missing values of this
factor. This procedure I want to repeat for each level of the factor.

Having read the recommendations of this list I want to avoid creating K-1
dummy variables and searched for options of the pairwise.t.test. But
couldn't find a solution. Anyone with a suggestion how to do the
comparisions?

Cheers,

Derik
#
On 2010-12-10 03:24, deriK2000 wrote:
Sounds like you want the Dunnett test procedure which seems
to be implemented in a number of packages: multcomp, asd, MCPAN
and others.

It would probably be a good idea to install package 'sos' and
learn how to search with it.

Peter Ehlers
#
Peter Ehlers wrote:
Thanks for the hints! 

Unfortunately, Dunnett compares the mean(x) for a factor level with the
means(x) of all single K-1 other levels resulting in K-1 comparisions for
each level (printed in a lower triangular matrix for the results). Instead,
I just want to compare this one mean(x) with one other mean(x) of all the
K-1 other levels (printed in a vector of length K for the results). 

Concerning  sos: sounds like a good idea!

Cheers, 

Derik
#
On 2010-12-10 05:58, deriK2000 wrote:
Okay, I misunderstood; should have read more carefully.
I would just use a loop (I'm not as loop-averse as
some R users).

  x <- rnorm(20)
  f <- gl(4, 5, lab = letters[1:4])
  lev <- levels(f)
  len <- length(lev)
  pv <- numeric(len)
  for(i in 1:len){
    pv[i] <- t.test(x[f == lev[i]], x[f != lev[i]])$p.value
  }
  pv

For pvalue adjustment (if you think that's needed),
see ?p.adjust.
Yes, it's an excellent tool.

Peter Ehlers