R-lrm(逻辑回归)错误无法使用“ lrm.fit”拟合模型

时间:2019-10-17 08:25:28

标签: r logistic-regression

将执行以下代码:

asp.net core

,但以下操作失败:

> mod1b <- lrm(dependent_variable ~ merged_dataset$Lag4_CPI, data = merged_dataset, na.action="na.delete")
> print(mod1b)
Logistic Regression Model

 lrm(formula = dependent_variable ~ merged_dataset$Lag4_CPI, data = merged_dataset, 
     na.action = "na.delete")

                       Model Likelihood     Discrimination    Rank Discrim.    
                          Ratio Test           Indexes           Indexes       
 Obs         19209    LR chi2    1305.57    R2       0.105    C       0.685    
  0          15465    d.f.             1    g        0.690    Dxy     0.369    
  1           3744    Pr(> chi2) <0.0001    gr       1.994    gamma   0.378    
 max |deriv| 4e-11                          gp       0.112    tau-a   0.116    
                                            Brier    0.146                     

                Coef    S.E.   Wald Z Pr(>|Z|)
 Intercept      -1.6305 0.0210 -77.82 <0.0001 
 merged_dataset  0.2809 0.0079  35.77 <0.0001 

同时执行此模型

> mod1b <- lrm(dependent_variable ~ merged_dataset$Lag4_CPI + quarterYear.x, data = merged_dataset, na.action="na.delete")
singular information matrix in lrm.fit (rank= 39 ).  Offending variable(s):
quarterYear.x=2017 4 
Warning message:
In lrm(dependent_variable ~ merged_dataset$Lag4_CPI + quarterYear.x,  :
  Unable to fit model using “lrm.fit”
> print(mod1b)
Error in 1:ns : argument of length 0

并使用glm执行:

> mod1b <- lrm(dependent_variable ~ quarterYear.x, data = merged_dataset, na.action="na.delete")
> print(mod1b)
Logistic Regression Model

 lrm(formula = dependent_variable ~ quarterYear.x, data = merged_dataset, 
     na.action = "na.delete")

                       Model Likelihood     Discrimination    Rank Discrim.    
                          Ratio Test           Indexes           Indexes       
 Obs         19209    LR chi2    2821.65    R2       0.218    C       0.746    
  0          15465    d.f.            38    g        0.947    Dxy     0.492    
  1           3744    Pr(> chi2) <0.0001    gr       2.579    gamma   0.503    
 max |deriv| 3e-10                          gp       0.154    tau-a   0.154    
                                            Brier    0.130                     

                      Coef    S.E.   Wald Z Pr(>|Z|)
 Intercept            -1.4663 0.1601 -9.16  <0.0001 
 quarterYear.x=2008 3 -0.0657 0.2225 -0.30  0.7678  
 quarterYear.x=2008 4  0.1500 0.2068  0.73  0.4683  
 quarterYear.x=2009 1 -0.0208 0.2506 -0.08  0.9340  
 quarterYear.x=2009 2 -0.0681 0.2437 -0.28  0.7798  
 quarterYear.x=2009 3 -0.2177 0.2528 -0.86  0.3891  
 quarterYear.x=2009 4 -0.1368 0.2514 -0.54  0.5862  
 quarterYear.x=2010 1  1.7921 0.1906  9.40  <0.0001 
 quarterYear.x=2010 2  1.7773 0.1893  9.39  <0.0001 
 quarterYear.x=2010 3  1.5728 0.1906  8.25  <0.0001 
 quarterYear.x=2010 4  1.6011 0.1861  8.60  <0.0001 
 quarterYear.x=2011 1  1.8365 0.1979  9.28  <0.0001 
 quarterYear.x=2011 2  1.6809 0.1916  8.77  <0.0001 
 quarterYear.x=2011 3  1.5499 0.1884  8.23  <0.0001 
 quarterYear.x=2011 4  1.5944 0.1932  8.25  <0.0001 
 quarterYear.x=2012 1  0.7949 0.2047  3.88  0.0001  
 quarterYear.x=2012 2  0.6866 0.2029  3.38  0.0007  
 quarterYear.x=2012 3  0.4700 0.2113  2.22  0.0261  
 quarterYear.x=2012 4  0.1778 0.2251  0.79  0.4295  
 quarterYear.x=2013 1 -0.5261 0.2296 -2.29  0.0219  
 quarterYear.x=2013 2 -0.5155 0.2283 -2.26  0.0239  
 quarterYear.x=2013 3 -0.3346 0.2173 -1.54  0.1236  
 quarterYear.x=2013 4  0.0757 0.1908  0.40  0.6914  
 quarterYear.x=2014 1 -0.3843 0.1970 -1.95  0.0511  
 quarterYear.x=2014 2 -0.2848 0.1960 -1.45  0.1462  
 quarterYear.x=2014 3 -0.3608 0.1971 -1.83  0.0671  
 quarterYear.x=2014 4 -0.5849 0.2033 -2.88  0.0040  
 quarterYear.x=2015 1 -0.3867 0.1945 -1.99  0.0468  
 quarterYear.x=2015 2 -0.7632 0.2031 -3.76  0.0002  
 quarterYear.x=2015 3 -0.7042 0.2007 -3.51  0.0005  
 quarterYear.x=2015 4 -0.6335 0.1971 -3.21  0.0013  
 quarterYear.x=2016 1 -0.5354 0.1949 -2.75  0.0060  
 quarterYear.x=2016 2 -0.6899 0.1977 -3.49  0.0005  
 quarterYear.x=2016 3 -1.2847 0.2197 -5.85  <0.0001 
 quarterYear.x=2016 4 -0.9774 0.2065 -4.73  <0.0001 
 quarterYear.x=2017 1 -0.9550 0.2035 -4.69  <0.0001 
 quarterYear.x=2017 2 -1.1674 0.2133 -5.47  <0.0001 
 quarterYear.x=2017 3 -0.9355 0.2036 -4.60  <0.0001 
 quarterYear.x=2017 4 -0.8023 0.2098 -3.82  0.0001 

有任何想法为什么会发生这种情况以及如何解决?

0 个答案:

没有答案