i have a df that contains data for the nation and would like to see if the relationship between variables is different at smaller geographies (region, state).
i have tried using the subset argument of glm but this would be very repetitive as i have many regions and many dependent variables.
ex)
glm(formula = var ~ grade, data = df, subset = region == "north")
but say I have 10 regions and 10 vars and I want to be able to get the glm results either all-together but subset by region, or one region after the other, rather than having to run each glm combination separately. is this possible?
the values for var are all a number 1 – 100 and the values for grade are “A”, “B”, “c”, and “D”
my apologies if this doesn’t quite make sense.
I tried using subset generally,
glm(formula = var ~ grade, data = df, subset = region)
but this resulted in a contrast error
Error in 'contrasts<-'('*tmp*', value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels
Bethanie Stauffer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.