[R] Contrasts with an interaction

John Sorkin JSorkin at grecc.umaryland.edu
Fri Oct 28 15:26:16 CEST 2011


Windows XP
R 2.12.1
contrast package.


I am trying to understand how to create contrasts for a model that contatains an interaction. I can get contrasts to work for a model without interaction, but not after adding the interaction. Please see code below. The last two contrast statements show the problem. I would appreciate someone letting me know what is wrong with the syntax of my contrast statements.
Thank you,
John


library(contrast)

# Create 2x2 contingency table.
counts=c(50,50,30,70)
row <-    gl(2,2,4)
column <- gl(2,1,4)
mydata <- data.frame(row,column,counts)
print(mydata)

# Show levels of 2x2 table
levels(mydata$row)
levels(mydata$column)


# Models, no interaction, and interaction
fitglm0 <- glm(counts ~ row + column,              family=poisson(link="log"))
fitglm  <- glm(counts ~ row + column + row*column, family=poisson(link="log"))

# Contrasts for model without interaction works fine!
anova(fitglm0)
summary(fitglm0)
con0<-contrast(fitglm0,list(row="1",column="1"))
print(con0,X=TRUE)

# Contrast for model with interaction does not work.
anova(fitglm)
summary(fitglm)
con<-contrast(fitglm,list(row="1",column="1")
print(con,X=TRUE)

# Nor does this work.
con<-contrast(fitglm,list(row="1",column="1",row:column=c("0","0")))
print(con,X=TRUE)




John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}



More information about the R-help mailing list