对比度只能应用于R中的系数

对比度只能应用于R中的系数,r,R,我试图将逻辑回归拟合到我的数据中,但我得到以下错误: logistic <- lm(response ~., data = df_without, family='binomial') Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels 我的数据帧以.Rdata文件

我试图将逻辑回归拟合到我的数据中,但我得到以下错误:

logistic <- lm(response ~., data = df_without, family='binomial')

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

我的数据帧以.Rdata文件的形式提供

sessionInfo()


我知道只有代码的答案会被版主追查并严加处理,但这确实说明了这一点:

 # I did download the excessively large file
> table(df_without[ complete.cases(df_without), 'pymnt_plan'])

        n    y 
   0 1231    0 

如果删除了缺失的观测值(如
lm
中的情况),某些变量是否可能只有一个级别?试试
summary(na.omit(df_without)[sapply(df_without,is.factor)])
(未经测试)哦,你可能缺少一个
g
真的吗?一个10.87 MB的文件????。。。因此
logistic@BenBolker:嗯,也许不是。有三列缺少大量数据:
$mths\u since\u last\u delinq$mths\u since\u record$mths\u since\u last\u major\u derog
,因此我怀疑需要集中精力理解这到底意味着什么。就风险评估而言,从未有过拖欠或“derog”(不管“derog”是什么,但听起来并不好)可能是一个有利的特征。正确的答案可能是。。。首先看看你的数据;不要等到你得到一个不好的结果。
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.1 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  splines   stats     graphics  grDevices utils         datasets  methods   base     

other attached packages:
 [1] Amelia_1.7.3        Rcpp_0.11.6         randomForest_4.6-10 e1071_1.6-4         plyr_1.8.2         
 [6] gbm_2.1.1           survival_2.38-1     glmnet_2.0-2            foreach_1.4.2       Matrix_1.2-0       
[11] caret_6.0-47        ggplot2_1.0.1       lattice_0.20-31     lubridate_1.3.3     RJDBC_0.2-5        
[16] rJava_0.9-6         DBI_0.3.1          

loaded via a namespace (and not attached):
 [1] compiler_3.2.0      nloptr_1.0.4        class_7.3-12        iterators_1.0.7     tools_3.2.0        
 [6] digest_0.6.8        lme4_1.1-7          memoise_0.2.1       nlme_3.1-120        gtable_0.1.2       
[11] mgcv_1.8-6          brglm_0.5-9         SparseM_1.6         proto_0.3-10        BradleyTerry2_1.0-6
[16] stringr_1.0.0       gtools_3.5.0        grid_3.2.0          nnet_7.3-9          foreign_0.8-63     
[21] minqa_1.2.4         reshape2_1.4.1      car_2.0-25          magrittr_1.5        scales_0.2.4       
[26] codetools_0.2-11    MASS_7.3-40         pbkrtest_0.4-2      colorspace_1.2-6    quantreg_5.11      
[31] stringi_0.4-1       munsell_0.4.2 
 # I did download the excessively large file
> table(df_without[ complete.cases(df_without), 'pymnt_plan'])

        n    y 
   0 1231    0