Quantcast

Query : Chi Square goodness of fit test

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Query : Chi Square goodness of fit test

priti desai
I want to calculate chi square test of goodness of fit to test,
Sample coming from Poisson distribution.

please copy this script in R & run the script
The R script is as follows

########################## start
#########################################

No_of_Frouds<-
c(4,1,6,9,9,10,2,4,8,2,3,0,1,2,3,1,3,4,5,4,4,4,9,5,4,3,11,8,12,3,10,0,7)


N <- length(No_of_Frouds)

# Estimation of Parameter


lambda<- sum(No_of_Frouds)/N
lambda

pmf  <- dpois(i, lambda, log = FALSE)

step_function  <- ppois(i, lambda, lower.tail = TRUE, log.p = FALSE)

# Chi-Squared Goodness of Fit Test

# Ho: The data follow a Poisson distribution Vs H1: Not Ho


Frauds <- c(1:13)

counts<-  c(2,3,3,5,7,2,1,1,2,3,2,1,1,0)  # Observed frequency

Expected
<-c(0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.7817821
03,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.2344006
79,0.095299266,0.035764993)

chisq.test(counts, Expected, simulate.p.value =FALSE, correct = FALSE)



######################### end ########################################


The result of R is as follows

  Pearson's Chi-squared test

data:  counts and poisson_fit
X-squared = 70, df = 65, p-value = 0.3135

Warning message:
Chi-squared approximation may be incorrect in: chisq.test(counts,
poisson_fit, simulate.p.value = FALSE, correct = FALSE)



But I have done calculations in Excel. I am getting different answer.

Observed  = 2,3,3,5,7,2,1,1,2,3,2,1,1,0
Expected=0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.78
1782103,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.23
4400679,0.095299266,0.035764993


 Estimated Parameter  =4.878788

Chi square stat =  0.000113


My excel answer tally with the book which I have refer for excel.  
Please tell me the correct calculations in R.
########################################################################
######################

Awaiting your positive reply.

Regards.
Priti.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Query : Chi Square goodness of fit test

Jacques Veslot-2
 > chisq.test(counts, p=Expected/sum(Expected), simulate.p.value =FALSE, correct = FALSE)

         Chi-squared test for given probabilities

data:  counts
X-squared = 40.5207, df = 13, p-value = 0.0001139

Warning message:
l'approximation du Chi-2 est peut-être incorrecte in: chisq.test(counts, p = Expected/sum(Expected),
simulate.p.value = FALSE,

but the use of Chi2 test is incorrect since some of Expected frequencies are lower than 5.

-------------------------------------------------------------------
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
-------------------------------------------------------------------


priti desai a écrit :

> I want to calculate chi square test of goodness of fit to test,
> Sample coming from Poisson distribution.
>
> please copy this script in R & run the script
> The R script is as follows
>
> ########################## start
> #########################################
>
> No_of_Frouds<-
> c(4,1,6,9,9,10,2,4,8,2,3,0,1,2,3,1,3,4,5,4,4,4,9,5,4,3,11,8,12,3,10,0,7)
>
>
> N <- length(No_of_Frouds)
>
> # Estimation of Parameter
>
>
> lambda<- sum(No_of_Frouds)/N
> lambda
>
> pmf  <- dpois(i, lambda, log = FALSE)
>
> step_function  <- ppois(i, lambda, lower.tail = TRUE, log.p = FALSE)
>
> # Chi-Squared Goodness of Fit Test
>
> # Ho: The data follow a Poisson distribution Vs H1: Not Ho
>
>
> Frauds <- c(1:13)
>
> counts<-  c(2,3,3,5,7,2,1,1,2,3,2,1,1,0)  # Observed frequency
>
> Expected
> <-c(0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.7817821
> 03,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.2344006
> 79,0.095299266,0.035764993)
>
> chisq.test(counts, Expected, simulate.p.value =FALSE, correct = FALSE)
>
>
>
> ######################### end ########################################
>
>
> The result of R is as follows
>
>   Pearson's Chi-squared test
>
> data:  counts and poisson_fit
> X-squared = 70, df = 65, p-value = 0.3135
>
> Warning message:
> Chi-squared approximation may be incorrect in: chisq.test(counts,
> poisson_fit, simulate.p.value = FALSE, correct = FALSE)
>
>
>
> But I have done calculations in Excel. I am getting different answer.
>
> Observed  = 2,3,3,5,7,2,1,1,2,3,2,1,1,0
> Expected=0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.78
> 1782103,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.23
> 4400679,0.095299266,0.035764993
>
>
>  Estimated Parameter  =4.878788
>
> Chi square stat =  0.000113
>
>
> My excel answer tally with the book which I have refer for excel.  
> Please tell me the correct calculations in R.
> ########################################################################
> ######################
>
> Awaiting your positive reply.
>
> Regards.
> Priti.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Query : Chi Square goodness of fit test

priti desai
In reply to this post by priti desai
If we have the data base of frauds given below


 no. of  frauds = variable

variable
<-c(4,1,6,9,9,10,2,4,8,2,3,0,1,2,3,1,3,4,5,4,4,4,9,5,4,3,11,8,12,3,10,0,
7)

pmf  <- dpois(i, lambda, log = FALSE)  # prob. mass function of variable

How to apply chi-square goodness of fit to test, Sample coming from
Poisson distribution.
How to calculate observed frequencies & expected frequencies, after that
how to calculate chi 2 test and interpret the result  



The formula which I have used & answer which I am getting is as follows,


chisq.test(variable, p=pmf, simulate.p.value =FALSE, correct = FALSE)



        Chi-squared test for given probabilities

data:  No_of_Frouds
X-squared = 1.043111e+15, df = 32, p-value < 2.2e-16

Warning message:
Chi-squared approximation may be incorrect in: chisq.test(No_of_Frouds,
p = pmf, simulate.p.value = FALSE, correct = FALSE)
 


But the answer is not correct.

Please suggest me the correct variable, calculations & formula in R.

 Awaiting your positive reply.
 
  Regards,
  Priti.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Loading...