I’m trying to compute Wald tests for interaction terms in a generalized additive model (gam in mgcv package) using R. The documentation for regTermTest says that the function takes a model with coef and vcov methods, but putting a gam model in doesn’t seem to work. How can I get this method to work? If it can’t be done, is there another simple way to compute the same values in R?
lm model works
model <- lm(sysbp~pmper10*se_race4,data=mesa)
regTermTest(model,"pmper10:se_race4")
# Wald test for pmper10:se_race4
# in lm(formula = sysbp ~ pmper10 * se_race4, data = mesa)
# F = 3.940545 on 3 and 43621 df: p= 0.0080253
but gam model does not
model <- gam(sysbp~pmper10*se_race4,data=mesa)
regTermTest(model,"pmper10:se_race4")
# Error in solve.default(V) : 'a' is 0-diml
This will work if you use the library
gambut notmgcv.The
regTermTestfunction relies on extracting the'assign'attribute from the model matrix for a given model.aa <- attr(model.matrix(model), "assign")[okbeta]
This object
aais used to construct the indices when creatingVA
gamobject from the packagemgcvdoes not have this attribute. Using the example fromsurvey::regTermTestIf we use the package gam
Gives the output
While
Gives the error reported by the OP.