Skip to content
Prev 275834 / 398506 Next

Contrasts with an interaction. How does one specify the dummy variables for the interaction

Daniel,
I want to use the contrast library because I want to be able to specify any arbitrary post-hoc contrast, e.g. Given a 3x2 table describing smoking (never, former, current) by sex (male,female), I can use a post-hoc contrast to compare the fraction of female former smokers to the fraction of male former smokers, or the fraction of male former smokers to the fraction of male current smokers, etc. To the best of my knowledge, post-hoc contrasts are the most flexible, and easiest way to specify arbitrary pre-specified comparisons.
John

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)
Is there a specific reason why you insist on using the contrast library? If
not:

# 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)

#Create contrasts

row<-factor(row)
column<-factor(column)
contrasts(row)<-contr.treatment(levels(row))
contrasts(column)<-contr.treatment(levels(column))

# Works for Terps

fit.terp<-glm(counts ~ row + column + row*column,
family=poisson(link="log"))
summary(fit.terp)

HTH,

Daniel Malter
University of Maryland, College Park
John Sorkin wrote: