I am writing a function that takes an object fulland reduced glmto summarize the results of the interaction of the variable of interest varofintand the interaction variable interaction_var(by executing lrtestand using the svycontrastobject fullto get the results varofintfor each level interaction_var). Sample data:
x <- data.frame(outcome=rbinom(100,1,.3),varofint=rnorm(100), interaction_var=sample(letters[1:3],100,replace=TRUE))
reduced <- glm(outcome~varofint+interaction_var,data=x)
full <- glm(outcome~varofint*interaction_var,data=x)
I would like to know the best way to extract the reference category for the specified ( full) glm model. I could do something like
levels(full$data$interaction_var)[1]
but will it be a "safe" method for extracting a reference data category into arguments contrasts? It seems that, given the choice of SAS contrast, this method may lead to a level interactionv_varthat is not used as a reference category in the model. Will the following be safer?
mf <- model.frame(full)
setdiff(rownames(contrasts(mf[, "interaction_var"])), colnames(contrasts(mf[, "interaction_var"])))
or similar
names(which(apply(contrasts(mf[, "interaction_var"]),1,function(.v){all(.v==0)})))
Am I missing an easier way to retrieve a link category?
source
share