1
$\begingroup$

Is there a way to return a matrix of means for levels of a factor using effect() in R? I see if you simply call an effect object you get the values printed, but I would like a matrix of these values that can be operated on. You can do this for the lower and upper confidence intervals like this:

ef1 <- effect("factor", analysis1)
ef1$lower

but there doesn't seem to be a returnable matrix of means.

$\endgroup$
1
  • $\begingroup$ Which package is 'effect' in? $\endgroup$ Nov 4, 2012 at 4:05

1 Answer 1

2
$\begingroup$

It is always a good idea to inspect an R object with str or by directly looking at the print/summary method: in this case you can type effects:::summary.eff at R prompt and see how it works.

Here is a toy example, for a linear model (for a GLM, you'll need to take care of the type of fitted values, which can be on the link or response scale):

set.seed(98)
n <- 60
x <- runif(n)
g <- gl(2, n/2, n, labels=paste("g", 1:2, sep=""))
y <- 0.3 + 1.5 * x + 0.8 * as.numeric(g) + rnorm(n)
d <- data.frame(y, x, g)
xyplot(y ~ x, data=d, groups=g, type=c("p","r"))
summary(m <- lm(y ~ x + g, data=d))
library(effects)
summary(e <- effect("g", m))
data.frame(fit=e$fit, lci=e$lower, uci=e$upper, row.names=levels(g))

The last command yields the desired quantities:

        fit      lci      uci
g1 1.671264 1.266193 2.076336
g2 2.520784 2.115712 2.925855
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.