0
我正在運行一個邏輯迴歸,包含755個觀察值和16個變量。我正在使用glm函數進行變量選擇。 glm已經找到了8個變量的最佳模型。我希望這些變量被迫留在中,並使用glm和step來查找下一個最佳的9變量模型(見下文)。我想這樣做,直到我完成了9-16變量模型 (全部選定的16個變量)的前向選擇。R正向選擇強制變量保留在方程
我的代碼看起來像
飽和模型
full=glm(PREVAP ~ SEX + TOTCHOL + AGE + SYSBP + DIABP + as.factor(CURSMOKE)
+ CIGPDAY + BMI + as.factor(DIABETES) + as.factor(BPMEDS) + HEARTRTE +
GLUCOSE + as.factor(EDUC) + TIME + HDLC + LDLC, data=training,
family=binomial(link="logit"))
summary(full)
anova(full,test="Chisq")
full.forward <- step(null,
scope=list(lower=null,upper=full),direction="forward",
family=binomial(link="logit"))
這給我的8個因子模型 我需要強制這些因素在接下來的模型,並使用正向選擇找到的9個因子的模型。怎麼做?
我被告知bestglm和glmnet也允許這個,但我不知道這些包。
你能幫忙嗎?這些軟件包有很多選項。
真誠, 瑪麗A.馬里昂
是否有可能像做 GLM(full.forward,數據=訓練,家族=二項式(鏈接= 「Logit模型」))? 我收到一個錯誤。 eval(expr,envir,enclos)中的錯誤:找不到對象'type'我有沒有保留family = binomial logit鏈接的問題。 –
嘗試'glm(formula(full.forward),data = training,family = binomial(link =「logit」))'' –