【发布时间】:2017-05-02 10:30:43
【问题描述】:
我正在处理一个数据集,并希望使用一些变量进行逐步逻辑回归,为此我使用 R 中的 add1() 函数。可以从此处的链接下载数据集的示例:https://drive.google.com/file/d/0B0N-Nc7kEi4bVjhDd1FDaEE5cEE/view?usp=sharing
因此,我使用以下方法拟合逻辑回归:
train <- read.csv('training.csv')
glm.model_step_1 <- glm(loan_status ~ acc_open_past_24mths + annual_inc + avg_cur_bal + bc_open_to_buy + delinq_2yrs + dti + inq_last_6mths + installment + int_rate + mo_sin_old_il_acct + mo_sin_old_rev_tl_op + mo_sin_rcnt_rev_tl_op + mo_sin_rcnt_tl + mort_acc + mths_since_last_delinq + mths_since_recent_bc + mths_since_recent_inq + num_accts_ever_120_pd + num_actv_bc_tl + num_actv_rev_tl + num_bc_tl + num_il_tl + num_op_rev_tl + num_tl_op_past_12m + pct_tl_nvr_dlq + percent_bc_gt_75 + pub_rec_bankruptcies + revol_bal + revol_util + term + total_acc + total_bc_limit + total_il_high_credit_limit + fico_mean + addr_state + emp_length + verification_status + Count_NA + Info_missing + Engineer + Teacher + Doctor + Professor + Manager + Director + Analyst + senior + lead + consultant + home_ownership_own + home_ownership_rent + purpose_debt_consolidation + purpose_medical + purpose_credit_card + purpose_other,
data = train,
family = binomial(link = 'logit'))
并使用add1() 函数进行前向选择。
add1(glm.model_step_1, scope = train)
此代码不起作用。我收到以下错误:
Error in factor.scope(attr(terms1, "factors"), list(add = attr(terms2, :
upper scope has term ‘NA’ not included in model
有谁知道如何解决这个错误?
之前在 datascience.stackexchange (https://datascience.stackexchange.com/questions/11604/checking-regression-coefficients-stability) 上提出的一个问题提到了检查 NA。数据集中没有任何 NA,可以通过运行 sapply(train, function(x) sum(is.na(x)) 来确认
【问题讨论】:
标签: r