Project 40: Two-Prop Z Test

Suppose we want to test the hypothesis (at the .05 level) that there is a difference between the proportion of adult males and females who spend more than 1 hour per week on YouTube.  We randomly sample 80 adult males and 100 adult females.  Forty of the men stated they spend more than 1 hour per week on YouTube while 25 of the women stated they spend more than 1 hour per week on YouTube.

Ho: Pm = Pf (Pm - Pf = 0)

Ha: Pm ≠ Pf (Pm - Pf ≠ 0)


Explanation:

pooledProp = (40 + 25)/(80 + 100) = 65/180 = .361

standardError = sqrt(.361*.639*(1/80+1/100)) = .072

statistic = phatM - phatF = 40/80 - 25/100 = .5 - .25 = .25

Since we have assumed in Ho that the proportion of men and women who are on YouTube for at least an hour are the same, the sampling distribution for the difference in proportions would have mean 0.  The sample sizes are large enough for the sampling distribution to be approximately normal (100*.361 = 36.1, 100*.639 = 63.9, 80*.361 = 28.88, 80*.639 = 51.12 are ALL at least 10).  The standard error was calculated above so the sampling distribution is shown below:

Since the p-value for the hypothesis test is low (less than alpha = .05) we reject Ho.  We get evidence that there is a difference in proportions of people spending at least one hour on YouTube per week between men and women.


Project 40: The variables 'x1', 'n1', 'x2', 'n2', and 'haDirection' have been initialized.  There are also working methods called normalcdf and invNorm.

x1 is the number of successes in the first group (40 in the first example)

n1 is the sample size of the first group (80 in the first example)

x2 is the number of successes in the second group (25 in the first example)

n2 is the sample size of the second group (100 in the first example)

haDirection represents the hypothesis being tested in Ha (< is 1, > is 2, and ≠ is 3).  haDirection was 3 in the example above.

Note: Look back at projects 1-4 to get additional explanation on the methods normalcdf and invNorm.

Task: Appropriately initialize the values 'z' and 'pValue' that represent the test statistic (z) and p-value for the given two proportion z-test.

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0