[R] Simple effects with Design / rms ols() function
Ista Zahn
izahn at psych.rochester.edu
Thu Jan 21 18:59:29 CET 2010
Hi everyone,
I'm having some difficulty getting "simple effects" for the ols()
function in the rms package. The example below illustrates my
difficulty -- I'll be grateful for any help.
#make up some data
exD <- structure(list(Gender = structure(c(1L, 2L, 1L, 2L, 1L, 1L, 1L,
2L, 1L, 2L, 2L, 2L, 1L, 2L), .Label = c("F", "M"), class = "factor"),
UCS = c(3.11111111111111, 3.5, 3.77777777777778, 2.875, 3.55555555555556,
2.44444444444444, 2.57142857142857, 3.11111111111111, 3.28571428571429,
3.11111111111111, 2.77777777777778, 2.77777777777778, 3.22222222222222,
2.77777777777778), GPA = c(3.4, 3.1, 2.9, 2.6, 2.7, 3.2,
3.1, 3.7, 2.8, 3, 2.2, 3.3, 3.4, 3.9)), .Names = c("Gender",
"UCS", "GPA"), class = "data.frame", row.names = c(NA, -14L))
## here is how I usually get simple effects with lm()
contrasts(exD$Gender) # check which is the reference group (reference group = F)
m.lm.f <- lm(GPA ~ Gender*UCS, data=exD) # run the model. UCS
coefficient is for females
summary(m.lm.f)
contrasts(exD$Gender) <- contr.treatment(2, base=2) # set reference
group to male
m.lm.m <- lm(GPA ~ Gender*UCS, data=exD) # run the model. UCS
coefficient is for males
summary(m.lm.m)
## try to do the eqivelent with ols ##
library(rms)
dd <- datadist(exD)
options(datadist="dd")
dd$limits["Adjust to", "Gender"] <- "F"
(m.ols.f <- ols(GPA ~ Gender*UCS, data=exD)) # run the model with
gender adjusted to f
dd$limits["Adjust to", "Gender"] <- "M"
(m.ols.m <- ols(GPA ~ Gender*UCS, data=exD)) # run the model with
gender adjusted to m. UCS coefficient is the same.
# Summary gives me results consistent with the lm results, but I want
the actual coefficients
summary(m.ols.f)
summary(m.ols.m)
#OK, so I could do
(m.ols.f1 <- ols(GPA ~ UCS, data=exD, subset=Gender=="F")) #but this
uses df=5 instead of df=10.
Question: How can I find simple effects of UCS for males and for females?
Thanks,
Ista
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
More information about the R-help
mailing list