[R] The 'test.terms' argument in 'regTermTest' in package 'survey'

Thomas Lumley tlumley at u.washington.edu
Thu Aug 19 17:40:12 CEST 2004


On Thu, 19 Aug 2004, Almirall, Daniel wrote:

>
> This is a question regarding the 'regTermTest' function in the 'survey' package.  Imagine Z as a three level factor variable, and code ZB and ZC as the two corresponding dummy variables.  X is a continuous variable.  In a 'glm' of Y on Z and X, say, how do the two test specifications
>
> 	test.terms = c("ZB:X","ZC:X")  # and
> 	test.terms = ~ ZB:X + ZC:X
>
> in 'regTermTest' differ?  I thought that both would return the same joint (Wald) test for the two Z:X interactions.  Why does the second one specify a 1 degree of freedom test?  The code below should help clarify my question.

What's happening is that the terms() function is reordering the variables.
The version with ~ZB:X +ZC:X uses attr(terms(~ZB:X+ZC:X),"term.labels"),
which turns out to be c("ZB:X","X:ZC").  This will cause problems when you
have more than one interaction term listed. Ugh.

A workaround in simple cases like this is to take advantage of R's
ability to make indicator variables.  You don't really have two
interactions, just two terms describing one interaction.

   glm3<-glm(Y~factor(Z)*X,family=binomial)
   regTermTest(glm3, ~factor(Z):X)

	-thomas

>
> Thanks much,
> Danny
>
>
>
>
> ## I'm currently using: R Version 1.9.1 / Windows 2000 / P4/2.8 Ghz
>
> Z <- as.factor(rep(LETTERS[1:3],20))
> Y <- rep(0:1, 30)
> X <- rnorm(60)
>
> glm1 <- glm(Y ~ Z + X + Z:X, family=binomial)
> summary(glm1)$coeff
>
> regTermTest( model=glm1 , test.terms=~Z:X)
>
> ZB <- ifelse(Z=="B",1,0)
> ZC <- ifelse(Z=="C",1,0)
>
> glm2 <- glm(Y ~ ZB + ZC + X + ZB:X + ZC:X, family=binomial)
> summary(glm2)$coeff 		## Okay, same as glm1
>
> regTermTest( model=glm2 , test.terms= c("ZB:X","ZC:X"))
> regTermTest( model=glm2 , test.terms= ~ ZB:X + ZC:X)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list