Search code examples
rpoissonp-valuegoodness-of-fit

How do I test the data to fit to the Poisson distribution with goodfit?


I have a data set with car arrivals per minute.

I drew a histogram and fit to the Poisson distribution with the following R codes.

#Aladdin Arrivals
Datast <- read.csv("Vehiclecount.csv", header = T, sep=";", dec=",")
hist(Datast$Arrival, xlab="Arrivals", 
  probability = TRUE,col=16, ylim = c(0,0.2), xlim =c(0, 30),    
  main = "Arrivals from Aladdin Street")
lines(dpois(x=0:25, lambda=13.20), col=2,lwd=3)
legend("topright", c("Probability of Vehicle Arrivals ", 
    "Poisson Distribution Curve"),  fill=c(col=16, col=2))

The code above successfully ran and I got the fitted lines over the histogram.

But when I want to use the goodfit() function to know how the p-value is I got following error;

"Error in optimize(chi2, range(count)) : 'xmin' not less than 'xmax'”

dfs <- dpois(x=1:25, lambda=13.20)
summary(dfs)
goodfit(dfs, type="poisson", method="MinChisq")

How I can solve this issue ? Is there another function to use?


Solution

  • You're applying goodfit (you should say it's from the vcd package, BTW) to the wrong thing. The first argument should be your count data: try

    vcd::goodfit(Datast$Arrival, type="poisson")