The additional `-1` stems from the fact that we have a Poisson distribution
for which the uncertainties are derived from the number of events. The
test is not sensitive to the normalization, and therefore, we loose one degree
of freedom, cf. [Data Analysis in High Energy
Physics](https://www.wiley.com/en-us/Data+Analysis+in+High+Energy+Physics%3A+A+Practical+Guide+to+Statistical+Methods-p-9783527410583) by Behnke et at.
The additional `- 1` in the call of `chisquare` is necessary because the method
implicitly assumes that the total number of events is fixed. The method
therefore reduces the number of degrees of freedom by one. However, in our case,
the number of decays is not fixed and we have an additional degree
of freedom compared to what `chisquare` assumes. The `- 1` in the `ddof`
corrects for this.
If you run the `decay.py` you should see the following fit results.
<!-- console_output -->
...
...
@@ -616,11 +616,11 @@ Optimal parameters:
chi^2 from scipy:
chi2 / dof = 120.577 / 123
p-value = 0.519418
p-value = 0.544943
Manual chi^2 test:
chi2 / dof = 120.577 / 123
p-value = 0.519418
p-value = 0.544943
```
Congratulations! You have mastered the first steps to analyze experimental data