Re: [R] Asking, are simple effects different from 0

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Wed, 05 Mar 2008 09:01:36 -0500

On 3/4/2008 2:45 PM, Jarrett Byrnes wrote:
> Hello, R-i-zens. I'm working on an data set with a factorial ANOVA
> that has a significant interaction. I'm interested in seeing whether
> the simple effects are different from 0, and I'm pondering how to do
> this. So, I have
>
> my.anova<-lm(response ~ trtA*trtB)
>
> The output for which gives me a number of coefficients and whether
> they are different from 0. However, I want the simple effects only,
> incorporating their intercepts, with their error estimates. Can I
> somehow manipulate this object to get that? Or, would a good shortcut
> be
>
> my.simple.anova<-lm(response ~ trtA:trtB + 0)
>
> and then use those coefficients and their error estimates?

   One approach would be to use glht() in the multcomp package. You need to work out how to formulate the matrix of coefficients that give the desired contrasts. Here is an example using the warpbreaks data frame:

fm <- lm(breaks ~ tension*wool, data=warpbreaks)

# names(coef(fm))
# (Intercept) tensionM tensionH woolB tensionM:woolB tensionH:woolB

cm <- rbind(

"A vs. B at L" = c(0, 0, 0,-1, 0, 0),
"A vs. B at M" = c(0, 0, 0,-1,-1, 0),
"A vs. B at H" = c(0, 0, 0,-1, 0,-1),
"M vs. L at A" = c(0, 1, 0, 0, 0, 0),
"M vs. H at A" = c(0, 1,-1, 0, 0, 0),
"L vs. H at A" = c(0, 0,-1, 0, 0, 0),
"M vs. L at B" = c(0, 1, 0, 0, 1, 0),
"M vs. H at B" = c(0, 1,-1, 0, 1,-1),
"L vs. H at B" = c(0, 0,-1, 0, 0,-1))

library(multcomp)

summary(glht(fm, linfct = cm), test = adjusted(type="none"))

          Simultaneous Tests for General Linear Hypotheses

Fit: lm(formula = breaks ~ tension * wool, data = warpbreaks)

Linear Hypotheses:

                   Estimate Std. Error t value  p value
A vs. B at L == 0  16.3333     5.1573   3.167 0.002677 **
A vs. B at M == 0  -4.7778     5.1573  -0.926 0.358867
A vs. B at H == 0   5.7778     5.1573   1.120 0.268156
M vs. L at A == 0 -20.5556     5.1573  -3.986 0.000228 ***
M vs. H at A == 0  -0.5556     5.1573  -0.108 0.914665
L vs. H at A == 0  20.0000     5.1573   3.878 0.000320 ***
M vs. L at B == 0   0.5556     5.1573   0.108 0.914665
M vs. H at B == 0  10.0000     5.1573   1.939 0.058392 .
L vs. H at B == 0   9.4444     5.1573   1.831 0.073270 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- none method)


> If so, I realize that R gives me t tests for each coefficient. Now,
> for those I know I'm using the residual degrees of freedom. Would it
> then be more appropriate to use those, all with the same residual DF
> and apply a bonferroni correction, or, use the mean and SE estimate
> with the sample size for that particular treatment and perform an
> uncorrected one sample t-test to see if the value is different from 0?
I won't comment on whether to adjust and if so how, but you can implement various adjustments when summarizing. For example: summary(glht(fm, linfct = cm), test = adjusted(type="bonferroni")) Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = breaks ~ tension * wool, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value p value A vs. B at L == 0 16.3333 5.1573 3.167 0.02409 * A vs. B at M == 0 -4.7778 5.1573 -0.926 1.00000 A vs. B at H == 0 5.7778 5.1573 1.120 1.00000 M vs. L at A == 0 -20.5556 5.1573 -3.986 0.00205 ** M vs. H at A == 0 -0.5556 5.1573 -0.108 1.00000 L vs. H at A == 0 20.0000 5.1573 3.878 0.00288 ** M vs. L at B == 0 0.5556 5.1573 0.108 1.00000 M vs. H at B == 0 10.0000 5.1573 1.939 0.52553 L vs. H at B == 0 9.4444 5.1573 1.831 0.65943 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- bonferroni method)
> Sorry for the bonehead question, but it's a situation I haven't seen
> before.
>
> -Jarrett
>
> ______________________________________________
> R-help_at_r-project.org 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 ______________________________________________ R-help_at_r-project.org 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.
Received on Wed 05 Mar 2008 - 14:07:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Mar 2008 - 15:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive