Question: **Question 2.** Write a Python function Chi_square_distance(observed_counts, expected_counts) that computes the Chi-square distance between a table of observed counts and a table of expected counts.

**Question 2.** Write a Python function Chi_square_distance(observed_counts, expected_counts) that computes the Chi-square distance between a table of observed counts and a table of expected counts. Compute and print the distance.**Question 2.** Write a Python function Chi_square_distance(observed_counts, expected_counts) that computes the Chi-square

Question 1. Write Python code to compute the table of expected counts (under the hypotheses of no treatment effect). Call this table "expected_counts". Print the table. Note: If this takes you too long and you run out of patience, you can compute the table of expected counts "by hand". [12]: expected_counts = observed_counts.with_row(make_array("expected counts", 3, 146, 43.5, 161, 362)) expected_counts [12]: treatment dense_growth minimal_growth moderate_growth new_vellus no_growth Placebo 114 Rogaine 178 29 58 43.5 150423 172 301 362 expected counts 146 161 Now we need a measure of distance between the observed and expected tables. A commonly used measure is the Chi-square distance, defined as (observed_count - expected_count) expected_count Chi2 = 2 2 rows columns Question 2. Write a Python function Chi_square_distance(observed_counts, expected_counts) that computes the Chi-square distance between a table of observed counts and a table of expected counts. Compute and print the distance. [14]: def Chi_square_distance(observed_counts, expected_counts): chi_squared = ((observed_counts - expected_counts) **2)/(expected_counts) return chi_squared observed_chi_square = Chi_square_distance(observed_counts, expected_counts) observed_chi_square Question 1. Write Python code to compute the table of expected counts (under the hypotheses of no treatment effect). Call this table "expected_counts". Print the table. Note: If this takes you too long and you run out of patience, you can compute the table of expected counts "by hand". [12]: expected_counts = observed_counts.with_row(make_array("expected counts", 3, 146, 43.5, 161, 362)) expected_counts [12]: treatment dense_growth minimal_growth moderate_growth new_vellus no_growth Placebo 114 Rogaine 178 29 58 43.5 150423 172 301 362 expected counts 146 161 Now we need a measure of distance between the observed and expected tables. A commonly used measure is the Chi-square distance, defined as (observed_count - expected_count) expected_count Chi2 = 2 2 rows columns Question 2. Write a Python function Chi_square_distance(observed_counts, expected_counts) that computes the Chi-square distance between a table of observed counts and a table of expected counts. Compute and print the distance. [14]: def Chi_square_distance(observed_counts, expected_counts): chi_squared = ((observed_counts - expected_counts) **2)/(expected_counts) return chi_squared observed_chi_square = Chi_square_distance(observed_counts, expected_counts) observed_chi_square

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