# How to determine a probabiltiy vector for a chi sqare goodnes of fit test?

I have numerical vectors of data that represent number of emails per day send by user (one variable). I want to run a simulation where I will be able to simulate mail creation process for about 30 users, and so I need a distribution to generate data sets. I analysed data and found that this data follows a negative binomial distribution (I used the fitdist R package to find parameters mu and size). I want to verify if the observed data and data generated by this model follow the same distribution.

1. Should I use a chi square test goodness of fit test to compare this two datasets? Will my null hypothesis be that data follow the same distribution, so if I get that p-value is P<0.05 then I confirm that H0 is correct.

2. When I perform the chi square test, the first parameter is a vector of data, and the second parameter is a probability vector. How can I produce this probability vector, or can I pass just two vectors of data (empirical set and generated set of data) for comparison ?

Example in R:

N1 <- rpois(500, lambda = 4)

> table(N1)
N1
0   1   2   3   4   5   6   7   8   9  10  11
9  37  71 113  87  87  46  26  16   5   2   1


I transformed this frequency table in order to group freq. higher than 9 into one bin (since there is smallest number of occurences, and to avoid chi square test error)

> nf<-c(9,37,71,113,87,87,46,26,16,8)

> of<-dpois(0:9, lambda = 4)   / generated expected freq for poisson with lambda(mean) 4

> of
> [1] 0.01831564 0.07326256 0.14652511 0.19536681 0.19536681 0.15629345 0.10419563 0.05954036 0.02977018
[10] 0.01323119


(I used Excel to find this probability of freq correct :)), then I applied a chi square test with rescale parameter to scale freq possibility sume to 1

> chisq.test(nf, p = of, rescale.p = TRUE)

Chi-squared test for given probabilities

data:  nf
X-squared = 6.1301, df = 9, p-value = 0.7268


• @explorer There a few problems here. First, you need vectors of probabilities or frequencies (see my edit above), not raw samples from rpois(). Second, the goodness-of-fit test will not work if your frequencies are around 5 or below. The Chi estimates will not be accurate below that point. Third, if the test statistic is significant, that means you should reject the null hypothesis (so, conclude that the distributions are likely different). If the test statistic is not significant, that means you fail to reject the null hypothesis (so, the conclude the distributions are likely the same). Commented Oct 11, 2020 at 22:30