2
$\begingroup$

I am attempting to test the goodness of fit for a vector of count data to a binomial. To do so I am using the goodfit() function in the vcd package. When I run the function, however, it returns NaN for the p-value of the Chi-squared test. In my setup, I have a vector of count data with 75 elements.

> library(vcd)
> counts
 [1] 32 35 44 35 41 33 42 49 36 41 42 45 38 43 36 35 40 40 43 34 39 31 40 39 36 37 37 37 32 48 41 32 37 36 49 37 41 36 34 37 41 32 36 36 30 33 33 42 39 36 36 29 31
[54] 41 36 39 40 37 39 39 31 39 37 40 33 41 34 46 35 41 44 38 44 34 42
> test.gof <- goodfit(counts, type="binomial", 
+                     par=list(size=length(counts), prob=0.5))

Everything works fine, but when I inspect the goodfit() object I get the following:

> summary(test.gof)

 Goodness-of-fit test for binomial distribution

                      X^2 df  P(> X^2)
Pearson               NaN 75       NaN
Likelihood Ratio 21.48322 19 0.3107244
Warning message:
In summary.goodfit(test.gof) : Chi-squared approximation may be incorrect

I suspected it was a small sample size issue at first, but I also have a data set with 50 observations that does not return NaN for the p-value. I have also tried to switch the method in goodfit() to ML with similar results.

Why would this function be producing NaN in this case? Is there an alternative function to calculate GOF on count data?

Data used:

counts <- c(32, 35, 44, 35, 41, 33, 42, 49, 36, 41, 42, 45, 38, 43, 36, 
35, 40, 40, 43, 34, 39, 31, 40, 39, 36, 37, 37, 37, 32, 48, 41, 
32, 37, 36, 49, 37, 41, 36, 34, 37, 41, 32, 36, 36, 30, 33, 33, 
42, 39, 36, 36, 29, 31, 41, 36, 39, 40, 37, 39, 39, 31, 39, 37, 
40, 33, 41, 34, 46, 35, 41, 44, 38, 44, 34, 42)
$\endgroup$
0

0

Browse other questions tagged or ask your own question.