r - logistic regression backwards selection - Cross Validated
i new r , trying polish logistic regression. testing if risk factors(cruise, age, sex, , year) have significant effect on dependent variable, mps infection (named mps_binary). have total of 4 cruises (5, 7, 9, 11), 3 years, thirteen ages, , 2 sexes (1 or 0).
i able run full model following command:
>mylogit<-glm(mps_binary~ age * sex * cruise * year, data=mps,family="binomial") from have p-values, can identify significant risk factors , interactions. data shows significant p-value interaction between cruise 7 , year. following backwards selection, need run model again original risk factors , significant terms. having increasing difficulty isolating cruise 7 cruise data run interaction year. have tried using command:
>mylogit<-glm(mps_binary~age+sex+year+cruise+mps$cruise7*year,data=mps,family="binomial") but this, of course, not recognize cruise 7 , receive error message: error in model.frame.default(formula = mps_binary ~ age + sex + cruise + : invalid type (null) variable 'mps$cruise7'.
my question how can run logistic regression of risk factors, , significant interaction between year , cruise 7? cannot figure out how isolate cruise 7 interaction year. please let me know if need more information, thank you!
you shouldn't this. general rule of thumb advises against thinking of categorical variables individual levels during model selection.
stepwise model selection frowned upon, it's problematic when use p-values / significance criteria instead of measure penalizes more complicated models aic or bic.
if really want break out 7th cruise own variable way create dummy variable:
mps$cruise7 = ifelse(as.numeric(mps$cruise) == 7, 1, 0) then can use other variable. @ point you'll have trouble non-broken-out cruise variable, you'll need break out each of individual levels (see tidyr::spread) , treat them individually... well, 1 level reference , gets lumped in intercept (thanks commenters!); inadvisable not impossible. standard approach not break out individual cruises.
Comments
Post a Comment