Question: EXERCISE 2 PLEASE!!!!!!! In a jupyter notebook named chisquared.ipynb, write some python code to confirm an assertion made in lecture: Suppose I draw a set

EXERCISE 2 PLEASE!!!!!!!
In a jupyter notebook named chisquared.ipynb, write some python code to confirm an
assertion made in lecture: Suppose I draw a set of N random variables {xi} from a normal
(Gaussian) distribution with mean and width . If I define as the weighted sum-of-
squares deviation from the mean:
=i=1N(xi-)2
Then will follow a x2 distribution with k=N degrees of freedom.
(k|)(k|)=12k2(k2)k2-1e-2
represents the gamma function, but it is easier to generate the x2 PDF directly using
scipy.stats.chi2.
For starters, have your code do the following
Set k=N=10 data points, =2.0 and =1.0.(But note that the x2 distribution
doesn't depend on and !)
Perform 1,000(or so) trials in which you sample NRVs{xi} using
numpy.random.normal. Calculate for each trial.
Plot the values in a histogram, using the density=True option.
Now, use scipy.stats.chi2(k) to superimpose the appropriate x2 PDF on your "data" to
confirm they agree.
Here are a few other things to try.
Vary =2.0 and =1.0, confirm they have no impact on the x2 distribution.
Vary N, confirm that the assertion still holds.
Suppose that, instead of taking as fixed, we determine by taking the mean of the
data points. Since we have determined from the data, the number of degrees of
freedom drops to k=N-1. Recompute and plot the distribution of Q and confirm that
scipy.stats.chi2(N-1) now describes the data.
Exercise 1.
In a jupyter notebook named chisquared.ipynb, write some python code to confirm an
assertion made in lecture: Suppose I draw a set of N random variables {xi} from a normal
(Gaussian) distribution with mean and width . If I define as the weighted sum-of-
squares deviation from the mean:
=i=1N(xi-)2
Then will follow a x2 distribution with k=N degrees of freedom.
(k|)(k|)=12k2(k2)k2-1e-2
represents the gamma function, but it is easier to generate the x2 PDF directly using
scipy.stats.chi2.
For starters, have your code do the following
Set k=N=10 data points, =2.0 and =1.0.(But note that the x2 distribution
doesn't depend on and !)
Perform 1,000(or so) trials in which you sample N RVs {xi} using
numpy.random.normal. Calculate for each trial.
Plot the values in a histogram, using the density=True option.
Now, use scipy.stats.chi2(k) to superimpose the appropriate x2 PDF on your "data" to
confirm they agree.
Here are a few other things to try.
Vary =2.0 and =1.0, confirm they have no impact on the x2 distribution.
Vary N, confirm that the assertion still holds.
Suppose that, instead of taking as fixed, we determine by taking the mean of the
data points. Since we have determined from the data, the number of degrees of
freedom drops to k=N-1. Recompute and plot the distribution of Q and confirm that
scipy.stats.chi2(N-1
EXERCISE 2 PLEASE!!!!!!! In a jupyter notebook

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!