Answered step by step
Verified Expert Solution
Question
1 Approved Answer
**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 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_squareStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started