Jorvik77
Jorvik77

Reputation: 352

GLHT for multiple regression coefficients in R

I have run a GLM binomial model

fit <- glm(highlow ~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10,
       family="binomial")

To test the null hypothesis of V1 = V2 I have used the following code.

glht.mod <- glht(fit, linfct = c("V1 - V2 = 0"))
summary(glht.mod) 

My question is can I test whether V1 = V2 = V3 (null hypothesis of all three coefficients being equal - note this is not the same as testing whether V1 = V2 and V2 = V3 in separate iterations)?

If it is any help, I am able to achieve this in SAS using the following code

proc logistic;
   model highlow = V1 V2 V3 V4 V5 V6 V7 V8 V9 V10;
   test1: V1 = V2;
   test2: V1 = V2 = V3;
run;

Upvotes: 1

Views: 579

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

A possibile solution for your problem:

set.seed(1)
n <- 1000
highlow <- factor(runif(n)>0.5)
X <- matrix(rnorm(n*10),nrow=n)
df <- data.frame(highlow, X)
names(df) <- c("highlow", paste("V",1:10,sep=""))

fit <- glm(highlow ~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10,
       family="binomial", data=df)

library(car)
linearHypothesis(fit, c("V1-V2", "V2-V3"), c(0,0))


################
Linear hypothesis test

Hypothesis:
V1 - V2 = 0
V2 - V3 = 0

Model 1: restricted model
Model 2: highlow ~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10

  Res.Df Df  Chisq Pr(>Chisq)
1    991                     
2    989  2 0.2761      0.871

Upvotes: 1

Related Questions