Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : 0 (non-NA) cases but there is NO NA

杀马特。学长 韩版系。学妹 提交于 2021-02-11 13:53:40

问题


I've got a really annoying problem that I tried to solve multiple days but I wasn't able. The code that I want to run is the following:

subsample2 <- as.data.frame(subsample)

m.extremistvote <- ictreg.joint(formula = resid_model1 ~ stateofeconomy + self_placement_extreme +
                      interaction_resid_1 + age + education + income + electoral_system + election_loser +
                      polity_IV + module1 + module4,
                               J=3,
                               data=extremist2, 
                               treat="gender",
                               outcome="extremist_vote",
                               constrained=TRUE,
                               maxIter = 5000)
summary(m.extremistvote)

However, I keep getting the following error message:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases"

But I've got not clue why this is the case... my dataset has no missings. I've checked this with multiple commands in R and STATA. Additionally, I tried to solve it with variations of this:

na.action=na.omit

But I'm still getting the error. I planed to attach a subsample of my STATA dataset that I exported into Rdata but I don't know where I can attach or upload something. I will try to add it. If you have any questions or need more of my code, I'm happy to provide it.

If anyone could help me, I would be more than thankful...

Edit:

Can somebody help me with this error that came after we solved the Error in lm.fit : Fehler in while (((llik.const - pllik.const) > 10^(-4)) & (counter < maxIter)) { : Fehlender Wert, wo TRUE/FALSE nötig ist in English something like Mistake in while (((llik.const - pllik.const) > 10^(-4)) & (counter < maxIter)) { : Missing value, where TRUE/FALSE is necessary? I would be really thankful as I still couldn't find the problem.

Best wishes, Klara


回答1:


Problem seems to be NA's created in the logistic regression. Using glm shows where the NA's appear.

glm_mod <- glm(formula = resid_model1 ~ stateofeconomy + self_placement_extreme +
  interaction_resid_1 + age + education + income + electoral_system + election_loser +
  polity_IV + module1 + module4,
data = subsample2
)
summary(glm_mod)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-0.12129  -0.06407   0.03418   0.06221   0.09203  

Coefficients: (4 not defined because of singularities)
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)            -0.521852   0.012550 -41.581  < 2e-16 ***
stateofeconomy         -0.079185   0.002531 -31.284  < 2e-16 ***
self_placement_extreme  0.290719   0.006678  43.535  < 2e-16 ***
interaction_resid_1     0.207318   0.038027   5.452 6.05e-08 ***
age                     0.006897   0.000125  55.171  < 2e-16 ***
education               0.047107   0.001637  28.769  < 2e-16 ***
income                  0.056425   0.001449  38.945  < 2e-16 ***
electoral_system              NA         NA      NA       NA    
election_loser         -0.141062   0.007631 -18.485  < 2e-16 ***
polity_IV                     NA         NA      NA       NA    
module1                       NA         NA      NA       NA    
module4                       NA         NA      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.004036176)

    Null deviance: 40.4291  on 1207  degrees of freedom
Residual deviance:  4.8434  on 1200  degrees of freedom
AIC: -3220.9

Number of Fisher Scoring iterations: 2

This isn't a complete answer because it doesn't say how to fix it, but there are four coefficients not defined because of singularities - whatever that means.



来源:https://stackoverflow.com/questions/59568194/error-in-lm-fitx-y-offset-offset-singular-ok-singular-ok-0-non

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!