Question: Module Four Discussion: Hypothesis Testing for the Difference in Two Population Proportions This notebook contains the step - by - step directions for your Module
Module Four Discussion: Hypothesis Testing for the Difference in Two Population Proportions
This notebook contains the stepbystep directions for your Module Four discussion. It is very important to run through the steps in order. Some steps depend on the outputs of earlier steps. Once you have completed the steps in this notebook, be sure to answer the questions about this activity in the discussion for this module.
Reminder: If you have not already reviewed the discussion prompt, please do so before beginning this activity. That will give you an idea of the questions you will need to answer with the outputs of this script.
Initial post due Thursday
Step : Generating sample data
This block of Python code will generate two samples, both of size that you will use in this discussion. The datasets will be unique to you and therefore your answers will be unique as well. The numpy module in Python allows you to create a data set using a Normal distribution. The data sets will be saved in Python dataframes and will be used in later calculations.
Click the block of code below and hit the Run button above.
import pandas as pd
import numpy as np
# create randomly chosen values from a normal distribution. arbitrarily using mean and standard deviation
diameterssample nprandom.normal
# convert the array into a dataframe with the column name "diameters" using pandas library
diameterssampledf pdDataFramediameterssample columnsdiameters
diameterssampledf diameterssampledfround
# create randomly chosen values from a normal distribution. arbitrarily using mean and standard deviation
diameterssample nprandom.normal
# convert the array into a dataframe with the column name "diameters" using pandas library
diameterssampledf pdDataFramediameterssample columnsdiameters
diameterssampledf diameterssampledfround
# print the dataframe to see the first observations note that the index of dataframe starts at
printDiameters data frame of the first sample showing only the first five observations
printdiameterssampledfhead
print
printDiameters data frame of the second sample showing only the first five observations
printdiameterssampledfhead
Diameters data frame of the first sample showing only the first five observations
diameters
Diameters data frame of the second sample showing only the first five observations
diameters
Step : Performing hypothesis test for the difference in population proportions
The ztest for proportions can be used to test for the difference in proportions. The proportionsztest method in statsmodels.stats.proportion submodule runs this test. The input to this method is a list of counts meeting a certain condition given in the problem statement and a list of sample sizes for the two samples.
Counts Python list that is assigned the number of observations in each sample with diameter values less than
n Python list that is assigned the total number of observations in each sample.
Click the block of code below and hit the Run button above.
from statsmodels.stats.proportion import proportionsztest
# number of observations in the first sample with diameter values less than
count lendiameterssampledfdiameterssampledfdiameters
# number of observations in the second sample with diameter values less than
count lendiameterssampledfdiameterssampledfdiameters
# counts Python list
counts count count
# number of observations in the first sample
n lendiameterssampledf
# number of observations in the second sample
n lendiameterssampledf
# n Python list
n n n
# perform the hypothesis test. output is a Python tuple that contains teststatistic and the twosided Pvalue.
teststatistic, pvalue proportionsztestcounts n
printteststatistic roundteststatistic,
printtwo tailed pvalue roundpvalue,
teststatistic
two tailed pvalue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
