Question: Using Python code, Chi-Square Goodness of fit Please access and review section 6.3.5 in the OpenIntro Statistics textbook: Diez, D., etinkaya-Rundel, M. & Barr, C

Using Python code, Chi-Square Goodness of fit

Please access and review section 6.3.5 in the OpenIntro Statistics textbook:

Diez, D., etinkaya-Rundel, M. & Barr, C (2019). OpenIntro Statistics (4th Ed.). https://leanpub.com/openintro-statistics

Given the information in section 6.3.5, write python code for the following:

  • Calculate the expected values based on the geometric distribution with a probability of 53.2%
  • Compare the expected vs. the observed values from the textbook using the Chi-Square distribution
  • Reach a conclusion
  • Explain what is the business impact of the conclusion
  • After running this code and installing the scipy and importing chisquare libraries the error message is "--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[14], line 4 2 chi2 = 0 3 p_value = 0 ----> 4 chi2, p_value = chisquare(observed_values, expected_values) File ~\anaconda3\Lib\site-packages\scipy\stats\_stats_py.py:7553, in chisquare(f_obs, f_exp, ddof, axis) 7428 def chisquare(f_obs, f_exp=None, ddof=0, axis=0): 7429 """Calculate a one-way chi-square test. 7430 7431 The chi-square test tests the null hypothesis that the categorical data (...) 7551 7552 """ -> 7553 return power_divergence(f_obs, f_exp=f_exp, ddof=ddof, axis=axis, 7554 lambda_="pearson") File ~\anaconda3\Lib\site-packages\scipy\stats\_stats_py.py:7394, in power_divergence(f_obs, f_exp, ddof, axis, lambda_) 7388 if diff_gt_tol: 7389 msg = (f"For each axis slice, the sum of the observed " 7390 f"frequencies must agree with the sum of the " 7391 f"expected frequencies to a relative tolerance " 7392 f"of {rtol}, but the percent differences are: " 7393 f"{relative_diff}") -> 7394 raise ValueError(msg) 7396 else: 7397 # Ignore 'invalid' errors so the edge case of a data set with length 0 7398 # is handled without spurious warnings. 7399 with np.errstate(invalid='ignore'): ValueError: For each axis slice, the sum of the observed frequencies must agree with the sum of the expected frequencies to a relative tolerance of 1e-08, but the percent differences are: 0.004941533766167396"

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 Mathematics Questions!