Hello, If the vector of observed frequencies is: ?f<-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability?:p11<-c(7.577864e-06, 1.999541e-04? ,1.833510e-03,? 9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01, 1.525880e-01, 1.689712e-01, 1.563522e-01,?? 1.232031e-01, 8.395000e-02, 5.009534e-02, 2.645857e-02,0.0205403) The sum of the probabilities is equal to one. But when I want to do the the Chi-square test, I get this error: probabilities must sum to one. Does anybody know the reason? Best Regards, pari
Chi-square test
4 messages · pari hesabi, Berend Hasselman, David L Carlson +1 more
On 20-02-2015, at 19:05, pari hesabi <statistics84 at hotmail.com> wrote: Hello, If the vector of observed frequencies is: f<-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11<-c(7.577864e-06, 1.999541e-04 ,1.833510e-03, 9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01, 1.525880e-01, 1.689712e-01, 1.563522e-01, 1.232031e-01, 8.395000e-02, 5.009534e-02, 2.645857e-02,0.0205403) The sum of the probabilities is equal to one. But when I want to do the the Chi-square test, I get this error: probabilities must sum to one.
print sum(p11)-1
Does anybody know the reason?
R FAQ 7.31 (http://cran.r-project.org/doc/FAQ/R-FAQ.html) Berend
Best Regards, pari
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
And probably why chisq.test has the rescale.p= argument. Your second problem with small expected values can be handled with simulate.p.value=.
chisq.test(f, p=p11)
Error in chisq.test(f, p = p11) : probabilities must sum to 1.
1-sum(p11)
[1] 4.3036e-08
chisq.test(f, p=p11, rescale.p=TRUE)
Chi-squared test for given probabilities data: f X-squared = 7.6268, df = 14, p-value = 0.9078 Warning message: In chisq.test(f, p = p11, rescale.p = TRUE) : Chi-squared approximation may be incorrect
chisq.test(f, p=p11, rescale.p=TRUE, simulate.p.value=TRUE)
Chi-squared test for given probabilities with simulated p-value (based
on 2000 replicates)
data: f
X-squared = 7.6268, df = NA, p-value = 0.7996
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Berend Hasselman
Sent: Friday, February 20, 2015 12:13 PM
To: pari hesabi
Cc: r-help at r-project.org
Subject: Re: [R] Chi-square test
On 20-02-2015, at 19:05, pari hesabi <statistics84 at hotmail.com> wrote: Hello, If the vector of observed frequencies is: f<-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11<-c(7.577864e-06, 1.999541e-04 ,1.833510e-03, 9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01, 1.525880e-01, 1.689712e-01, 1.563522e-01, 1.232031e-01, 8.395000e-02, 5.009534e-02, 2.645857e-02,0.0205403) The sum of the probabilities is equal to one. But when I want to do the the Chi-square test, I get this error: probabilities must sum to one.
print sum(p11)-1
Does anybody know the reason?
R FAQ 7.31 (http://cran.r-project.org/doc/FAQ/R-FAQ.html) Berend
Best Regards, pari
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
On Feb 20, 2015, at 10:05 AM, pari hesabi wrote:
Hello, If the vector of observed frequencies is: f<-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11<-c(7.577864e-06, 1.999541e-04 ,1.833510e-03, 9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01, 1.525880e-01, 1.689712e-01, 1.563522e-01, 1.232031e-01, 8.395000e-02, 5.009534e-02, 2.645857e-02,0.0205403) The sum of the probabilities is equal to one.
Well, the sum is close to 1.0 but not exact. There's a simple fix:
sum(p11)==1
[1] FALSE
sum( p11/sum(p11) )==1
[1] TRUE
But when I want to do the the Chi-square test, I get this error: probabilities must sum to one. Does anybody know the reason?
Numerical accuracy. See R-FAQ 7.31
David Winsemius Alameda, CA, USA