'How to get the names of factor levels corresponding to fixed effect regression coefficients for a GAM in R?

I have a gam in R (mgcv package) with 7 parameters, and one of them is a fixed effect with 30 levels (30 names). I want to analyse the regression coefficients for each name (person), but R numbers each level (so 1-29, and the 30th one is the reference level), so I can't figure out which person corresponds to which regression coefficient.

# model looks like this:
mymod <- gam(response ~ s(x1) + s(x2) + s(x3) + s(x4) + x5 + x6 + x7_person, offset=offset, data=mydata, method="REML", select="TRUE")

# neither of these give me the name of each person
mymod$coefficients
summary(mymod)$p.coeff

So instead of x7_personSam, x7_personSue (for example), I get x7_person1, x7_person2, etc.

I need to be able to find the metadata that corresponds to each person's regression coefficient, and also figure out which person doesn't have a regression coefficient because they are the reference level.

Is there a way to make R print the name of each factor level, as it appears in the data?

Thanks!



Solution 1:[1]

Figured it out - the factor variables have to be wrapped in factor() within the GAM call. I had converted all the factor variables from characters to factors before running the gam, but for some reason they still need the + factor(x7_person) wrapper

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 leslie roberson