0

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

Ing1996
  • 1
  • 1
  • Variables: gender extremist_vote resid_model1 stateofeconomy self_placement_extreme interaction_resid_1 age education income electoral_system election_loser polity_IV module1 module4; Two Examples: 1 0 -.1628964 2 0 0 36 5 1 1 10 1 0 2 0 -.179169 3 0 0 36 4 1 1 10 1 0 – Ing1996 Jan 02 '20 at 18:27
  • 1
    Really need to provide some data. It would help to include library(ictreg.joint). Looks like you are referencing the residuals in a model that is not provided, maybe it's part of your data set? – markhogue Jan 02 '20 at 18:40
  • is there a possibility to upload a smaller dataset? Yes, one would need those two: install.packages("list") library(list). Yes, the residuals are another variable that exists in my dataset. – Ing1996 Jan 02 '20 at 19:15
  • 1
    Good question: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – markhogue Jan 02 '20 at 19:17
  • Thanks a lot. I created a GitHub account and you should be able to find the subsample here: https://github.com/KlaDen1996/Rep – Ing1996 Jan 02 '20 at 19:25

1 Answers1

0

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.

markhogue
  • 1,056
  • 1
  • 6
  • 16
  • 1
    First of all thanks for your efforts, I really appreciate it. Unfortunately, my complete dataset consists of of more than 61' observations and this is only election year that I used as subsample. I will add an additional dataset with an election where some people voted extremist. This is also why module1 = 1 because this election study is from the first module, I will add another from module4. Interestingly, the normal logit regression has no problems and runs smoothly included all the observations hinting at the fact that there are no missings that would be excluded otherwise. – Ing1996 Jan 03 '20 at 11:19
  • I've added the R and Stata file on GitHub (http://github.com/KlaDen1996/Rep). The following code is then needed: `subsample2studies_2 <- as.data.frame(subsample2studies)` – Ing1996 Jan 03 '20 at 11:30
  • I'm stuck, but here are some observations: 1) the error you're getting is probably due to this function calling `lm.fit` or related function. For example, https://stackoverflow.com/questions/46621335/error-in-lm-fit-0-non-na-cases-appears-after-running-r-script-successfully-m. 2) The `treat` argument may need to be 0 and 1 rather than 1 and 2. I changed all the gender 2's to 0 and get an exciting new error message - `Error in eigen(sigma, symmetric = TRUE) : infinite or missing values in 'x' In addition: Warning message: glm.fit: fitted probabilities numerically 0 or 1 occurred ` – markhogue Jan 03 '20 at 16:29
  • revised answer based on `glm` being the source of the error. – markhogue Jan 04 '20 at 04:42
  • Yes, you were perfectly right it seems like the dichotomy (1,2) was the problem. I've recoded it as well and interestingly get a different error than you got (based on the complete sample): `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`. – Ing1996 Jan 04 '20 at 09:28
  • I've tried to change some things in the ictreg function but I still get the error. – Ing1996 Jan 04 '20 at 09:34
  • If you look through the code (you can see it all in the console by typing `ictreg.joint` (no `()`, then you see the call to `glm`. That's why I put that in the answer - I think if you get a glm that works with your data, the `ictreg.joint` problem will likely be solved as well. – markhogue Jan 04 '20 at 15:37
  • Thanks for the hint that's really cool. I wasn't aware of that option. However, I think that the glm is not the problem as the error that I get occurs later in the code (`ictreg.joint`)? If I run a simple glm this also works without any problems. – Ing1996 Jan 05 '20 at 14:00
  • This is where the error occurs: `pllik.const <- -Inf ; counter <- 0 ; nPar <- ncol(x.all) ; llik.const <- obs.llik.binom.std(par, J = J, y = y.all, treat = t, o = o, x = x.all, constrained = constrained, outcome.reg = outcome.reg) ; while (((llik.const - pllik.const) > 10^(-4)) & (counter < maxIter)) {` ... – Ing1996 Jan 05 '20 at 14:06