How to do Chi-square test correctly using chisq.test()?
<p>I'm trying to perform Pearson Chi-square test on goodness of fit. Here is an example of fitting a Poisson distribution:</p>

<pre><code>data &lt;- rpois(200,50)
estimate &lt;- mean(data)
freq.os&lt;-table(data)
yfit &lt;- dpois(as.integer(names(freq.os)), estimate)

chisq.test(x = freq.os, p = yfit)
# Error in chisq.test(x = freq.os, p = yfit) : probabilities must sum to 1.
</code></pre>

<p>When I evaluate <code>sum(yfit)</code>, I get 0.999839.</p>

<p>So how to produce a set of probability values that add up to 1? Thank you!</p>

<hr>

<p><strong>EDIT</strong></p>

<p>Actually I found a work around:</p>

<pre><code>chisq.test(freq.os, yfit)
</code></pre>

<p>but I am very confused as to how <code>chisq.test()</code> works as it is telling me <code>df = 429</code>. I thought <code>df = n - k - 1</code>, which in this case should be 35, where <code>k = 1</code> for the lambda and <code>n = number</code> of terms in the chi-square sum. Where am I doing wrong?</p>