31.7k views
5 votes
A university conducted a survey of its recent graduates. The university wanted to

measure the quality of a new Engineering course. A survey was conducted during the
first offering of the course to evaluate its overall quality. The results of the survey
are shown below:
Needs Improvement: 55%
Meets Expectations: 30%
Excellent: 15%
The university made improvements to the course earlier this year. Then it conducted
another survey to evaluate how these improvements worked. A total of 500 students
were surveyed. Their results are shown below:
Needs Improvement: 175 students
Meets Expectations: 225 students
Excellent: 100 students

You want to perform a chi-squared test for goodness of fit, to see if students’ views have changed about the course. Which of the following python scripts prints the P-value and test statistic for the chi-squared test?

A university conducted a survey of its recent graduates. The university wanted to-example-1
User BudgieInWA
by
8.9k points

1 Answer

2 votes

Explanation:

To perform a chi-squared test for goodness of fit in Python and obtain the P-value and test statistic, you can use the scipy.stats module. Here's an example script that calculates the chi-squared test and prints the P-value and test statistic:

pythonCopy code

from scipy.stats import chi2_contingency # Observed frequencies from the first survey observed_freq_1 = [55, 30, 15] # Expected frequencies based on the proportions in the second survey total_students_2 = 500 expected_freq_2 = [total_students_2 * 0.55, total_students_2 * 0.3, total_students_2 * 0.15] # Perform chi-squared test chi2, p_value = chi2_contingency([observed_freq_1, expected_freq_2]) # Print the results print("Test statistic:", chi2) print("P-value:", p_value)

In this script, we use the chi2_contingency function from scipy.stats to perform the chi-squared test. We provide the observed frequencies from the first survey and the expected frequencies based on the proportions in the second survey. The function returns the test statistic and P-value, which we then print.

Note that this chi-squared test assumes that the observed and expected frequencies are independent. It also assumes that the expected frequencies are not too small (typically, no expected frequency should be less than 5) for the test to be valid.

User Reilas
by
7.9k points

No related questions found