[R] Poisson example from Snedechor & Cochran
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Nov 15 19:40:47 CET 2006
Christoph Scherber <Christoph.Scherber at agr.uni-goettingen.de> writes:
> Dear R users,
>
> I am trying to reproduce table 7.4.12 (page 131) from Snedechor &
> Cochran (eigth edition); the example is counts of weed seeds with a
> fitted Poisson distribution, tested for goodness-of-fit using a Chi-square:
>
> observed=c(3,17,26,16,18,9,3,5,0,1,0,0)
> expected=dpois(0:11,lambda=3.020408)*98
> chisq.test(observed,p=expected,rescale.p=T)
>
> Now the problem I have is that chisq.test gives me the chi-squared value
> of roughly 8.30 (which is the value given by Snedechor & Cochran), but I
> am wondering why the warning message occurs at the end of the test.
Because you have expected values less than 5.
BTW, the result given does not correspond to your code! You cannot
have 8 DF from testing a vector of length 12. The closest I can get is
> chisq.test(observed[1:9],p=c(expected[1:8]/98,1-sum(expected[1:8]/98)))
Chi-squared test for given probabilities
data: observed[1:9]
X-squared = 9.5561, df = 8, p-value = 0.2976
Warning message:
Chi-squared approximation may be incorrect in:
chisq.test(observed[1:9], p = c(expected[1:8]/98, 1 - sum(expected[1:8]/98)))
You can avoid the warning by using simulate.p=TRUE, but beware that
the result is still wrong because lambda is not really known, but
estimated from your data.
> Further, it is not clear to me how these calculations could be done
> using the full dataset of N=98 observations:
>
> observed.full=rep(0:11,c(3,17,26,16,18,9,3,5,0,1,0,0))
>
> What would the correct specification for a chisq.test against a poisson
> distribution look like in this case?
Tabulate it and you're back at square 1....
Alternatively, you can test for overdispersion (only), by looking at
var(observed.full)/mean(observed.full) which should follow an
approximate chi-square/f distribution (with f=N-1=97).
>
> ##
> Chi-squared test for given probabilities
>
> data: observed
> X-squared = 8.2628, df = 8, p-value = 0.4082
>
> Warning message:
> Chi-squared approximation may be incorrect in: chisq.test(observed, p =
> expected, rescale.p = T)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list