2
$\begingroup$
 > dput(t)
 structure(c(125L, 25L, 28L, 8L, 0L, 68L, 13L, 9L, 10L, 0L), .Dim = c(5L, 
 2L), .Dimnames = list(c("Married", "Widowed", "Divorced", "Never married", 
 "Other"), c("control", "case")))
 > t
               control case
 Married           125   68
 Widowed            25   13
 Divorced           28    9
 Never married       8   10
 Other               0    0
 > chisq.test(t)
    Pearson's Chi-squared test

 data:  t
 X-squared = NaN, df = 4, p-value = NA

 Warning messages:
 1: In chisq.test(t, simulate.p.value = TRUE) :
   cannot compute simulated p-value with zero marginals
 2: In chisq.test(t, simulate.p.value = TRUE) :
   Chi-squared approximation may be incorrect

I am trying to see whether marital status affects a person's disease status. However, when I run the Pearson test, I get the above errors. Is this happening because I only have 2 categories for the disease status (i.e: control or case)? What is another appropriate test that I can use instead?

$\endgroup$
2
  • $\begingroup$ Pearson (here Karl Pearson) deserves upper case P. $\endgroup$
    – Nick Cox
    Commented Jan 6, 2015 at 10:28
  • 3
    $\begingroup$ This is a statistical question masquerading as an r question. $\endgroup$ Commented Jan 6, 2015 at 13:08

1 Answer 1

6
$\begingroup$

This is not specific to R and in fact you are being told what is wrong. To spell it out, two of the terms in the chi-square statistic,

$\Sigma (\text{observed} - \text{expected})^2 / \text{expected}$

reduce to $(0 - 0)^2/0$, as the total of a row or column (depending on how the frequencies are displayed) is $0$. That is what is meant by "zero marginal". You could see this for yourself by doing the chi-square test by hand, but regardless of that the R function won't sum (or ignore) indeterminate terms with zero divisor.

Having two categories for disease status is irrelevant to that outcome, except that you need at least two categories to apply the test at all.

The easiest solution is to omit the corresponding category. I'd counsel flagging that you did so in any formal report. There are various obvious consequences: if other researchers had a populated "other" category, then what you are doing is necessarily not quite the same as what they did. Presumably "other"s are possible in principle, just not present in your sample. (In this case, I can't readily imagine what that other would be, but perhaps it is there for people writing in something else or declining to give an answer.)

$\endgroup$
4
  • $\begingroup$ I've recently had similar problems with all-zero variables that in principle could have taken non-zero values. Is there a more general sense of how to proceed? Is there a Bayesian approach? $\endgroup$ Commented Jan 6, 2015 at 17:01
  • $\begingroup$ @ssdecontrol There is always a Bayesian approach. In fact, there are always lots of Bayesian approaches. Aren't you taking courses with Andrew Gelman? $\endgroup$
    – Nick Cox
    Commented Jan 6, 2015 at 18:24
  • $\begingroup$ it's more a matter of "is there a principled Bayesian approach that someone smarter than me has already put time and effort into developing." Yes, I took a course with him last semester but it was a "soft" one. And I had him in mind when I wrote that comment; I was thinking maybe there was some kind of smooth "partial variable omission" that could be achieved in some kind of multilevel model. The only thing I can think of doing is an imputation, but that would only make sense if I have a very strong theoretical sense of the distribution of the rare-but-not-always-zero variable. $\endgroup$ Commented Jan 6, 2015 at 18:29
  • 1
    $\begingroup$ One crude method would shrink the frequencies inwards and so replace sampling zeros with positive frequencies. A kind of sensitivity analysis might replace either zero with 1 to see what difference it makes. $\endgroup$
    – Nick Cox
    Commented Jan 6, 2015 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.