Hypothesis Tests II

Activity 20

Author

Solution

Overview

Activity 20 continues our discussion of hypothesis testing which is a framework for using statistics to make decisions. This activity focuses on writing two-sided hypothesis tests and interpreting the results.


Needed Packages

The following loads the packages that are needed for this activity.

# load packages
library(tidyverse)
library(skimr)


Tasks

This is a 2 day activity!

Question 1

Write the hypothesis test for each scenario and interpret the results in the context of the problem.

Helpful notation: \(\neq\), \(\mu_{variable}\), \(\pi_{variable}\), \(\beta_{variable}\)

1a: Manufacturing

Suppose a certain manufacturing plant wants to switch to a faster machine for producing widgets. However, they only want to switch machines if it does not increase the proportion of defective widgets (a small mechanical device) produced per month.

To test this, they measure the proportion of defective widgets produced with the new machine for one month (prop 1) and the proportion of defective widgets produced with the old machine for one month (prop 2) and check to see if there is a difference (prop 1 - prop 2).

Using alpha = 0.10, test this claim.

\[H_0: \pi_{new} - \pi_{old} = 0\]

\[H_A: \pi_{new} - \pi_{old} \neq 0\]

The results of the experiment are shown below:

What is your conclusion in the context of the problem?

Assuming there is no difference in the proportion of defective widgets produced between the new and old machine, there is a 20.94% chance of seeing data as extreme as mine. At the 0.1 significance level, we fail to reject the null hypothesis. We conclude that the proportion of defective widgets is the same, meaning the new machine does not increase the rate of defective widgets.


1b: Biology

Suppose a biologist believes that a new fertilizer will increase the growth of plants over a one-month period compared to the typical growth. The average growth without fertilizer is 20 inches.

To test this, she applies the fertilizer to each of the plants in her laboratory for one month and tests if the growth is more than 20 inches.

State the hypothesis:

\[H_0: \mu_{growth} = 20\]

\[H_A: \mu_{growth} \neq 20\]

The results of the experiment are shown below:

Using alpha = 0.02, what is your conclusion in the context of the problem?

Assuming that the average growth of plants over a one-month period is equal to 20 inches, there is a 1.8% chance of seeing data as extreme as mine. At the alpha = 0.02 significance level we reject the null hypothesis. We conclude the growth is not equal to 20, since our sample statistic is 21.13 the new fertilizer did indeed increase the growth of plants.


1c: Clinical Trials

Suppose a doctor believes that a new drug is able to reduce blood pressure in obese patients. To test this, he measures the systolic blood pressure of 40 patients before and after using the new drug for one month to determine if there is a difference (ie: blood pressure before drug - blood pressure after drug).

Use a hypothesis test at the alpha = 0.05 significance level to determine if the drug reduces blood pressure in obese patients.

\[H_0: \mu_{before} - \mu_{after} = 0\]

\[H_A: \mu_{before} - \mu_{after} \ne 0\]

The results of the experiment are shown below:

What is your conclusion in the context of the problem?

Assuming there is no change in blood pressure ub obese patients after taking the drug, there is a 0.12% chance of seeing data as extreme as mine. At the 0.05 significance level we reject the null. We conclude that there is a difference in blood pressure from taking the drug. Since the sample mean difference is -1.19, that implies that the drug actually INCREASED the blood pressure. It did not decrease blood pressure as the doctor believed.


Question 2

Conduct hypothesis tests from start to finish.

The Behavioral Risk Factor Surveillance System (BRFSS) is an annual telephone survey of 350,000 adults in the United States. As its name implies, the BRFSS is designed to identify risk factors in the adult population and report emerging health trends. The BRFSS Web site (http://www.cdc.gov/brfss) contains a complete description of the survey, including the research questions that motivate the study and many interesting results derived from the data.

The sample data is saved in data/cdc.rda.

  • genhlth, respondents were asked to evaluate their general health, responding either excellent, very good, good, fair, or poor;
  • exerany variable indicates whether the respondent exercised in the past month (1) or did not (0);
  • hlthplan indicates whether the respondent had some form of health coverage (1) or did not (0);
  • smoke100 variable indicates whether the respondent had smoked at least 100 cigarettes in their lifetime (1) or not (0);
  • height is respondent’s height in inches;
  • weight is respondent’s weight in pounds;
  • wtdesire is respondent’s desired weight in pounds;
  • age is respondent’s age in years;
  • gender coded m for male and f for female.
load("data/cdc.rda")

2a:

Many unofficial sources report a global average height for women as 5 feet 3 inches. Is there significant evidence that adult US women are taller than the global average of 5 feet 3 inches (63 inches)? Use significance level \(\alpha = 0.01\).

Step 1. Formulate your hypothesis:

\[H_0: \mu_{women height} = 63\] \[H_A: \mu_{women height} \ne 63\]

Step 2: Pick a significance level. Let’s use = 0.01

Step 3: Our distribution under \(H_0\) is the t-distribution

Step 4/5: Compute the test statistic and p-value.

# hypothesis test
women <- cdc %>% 
  filter(gender == "f")

#hypothesis test
t.test(women$height, mu = 63, conf.level = 0.99)

    One Sample t-test

data:  women$height
t = 50.117, df = 10430, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 63
99 percent confidence interval:
 64.29744 64.43806
sample estimates:
mean of x 
 64.36775 

Step 6: Draw conclusions in the context of your problem

Assuming the average height of US women is 63 inches, there is almost a 0% chance of seeing data as extreme as mine. At the 0.01 significance level we reject the null hypothesis. We conclude the average height of US women is not 63 inches, in fact since our sample mean is 64.37 we conclude US women are taller than the national average women.

Alternative interpretation

Assuming the average height of US women is 63 inches, there is almost a 0% chance of seeing data as extreme as mine. At the 0.01 significance level we reject the null hypothesis. We conclude the average height of US women is not 63 inches, in fact since we are 90% confident that US women are between 64.3 64.41 inches tall, we condlud that US women are taller than the national average.

2b:

Is there significant evidence that the proportion of adult US women considering herself in excellent health is more than the proportion of adult US men considering himself in excellent health? Use significance level \(\alpha = 0.02\).

State your hypothesis:

\[H_0: \pi_{women} - \pi_{men} = 0\] \[H_A: \pi_{women} - \pi_{men} \ne 0\]

cdc %>% 
  count(gender)
# A tibble: 2 × 2
  gender     n
  <fct>  <int>
1 m       9569
2 f      10431
cdc %>% 
  count(gender, genhlth)
# A tibble: 10 × 3
   gender genhlth       n
   <fct>  <fct>     <int>
 1 m      excellent  2298
 2 m      very good  3382
 3 m      good       2722
 4 m      fair        884
 5 m      poor        283
 6 f      excellent  2359
 7 f      very good  3590
 8 f      good       2953
 9 f      fair       1135
10 f      poor        394
prop.test(x = c(2359, 2298), n = c(10431, 9569),
          conf.level = 0.98, correct = FALSE)

    2-sample test for equality of proportions without continuity correction

data:  c(2359, 2298) out of c(10431, 9569)
X-squared = 5.4742, df = 1, p-value = 0.0193
alternative hypothesis: two.sided
98 percent confidence interval:
 -2.792614e-02 -6.920304e-05
sample estimates:
   prop 1    prop 2 
0.2261528 0.2401505 

Draw conclusions in the context of your problem.

Assuming that the proportion of US women that consider themselves in excellent health is equal to the proportion of US men that consider themselves in excellent health, there is a 1.93% chance of seeing data as extreme as mine. At the 0.02 significance level we reject the null hypothesis. We conclude there is a difference in the proportion of US women and US men that consider themselves in excellent health, based on our sample proportions, a higher proportion of men consider themselves in excellent health.


2c:

Is there significant evidence that adults in the U.S. that are smokers weight more than adults in the U.S. that are nonsmokers? Use significance level \(\alpha = 0.10\) to test if there is a difference between the average weight of smokers and the average weight of non-smokers.

State your hypothesis:

\[H_0: \mu_{smoker} - \mu_{nonsmoker} = 0\] \[H_A: \mu_{smoker} - \mu_{nonsmoker} \ne 0\]

cdc_smoker <- cdc %>% 
  filter(smoke100 == "yes")

cdc_nonsmoker <- cdc %>% 
  filter(smoke100 == "no")

t.test(x = cdc_smoker$weight, 
       y = cdc_nonsmoker$weight, 
       conf.level = 0.90)

    Welch Two Sample t-test

data:  cdc_smoker$weight and cdc_nonsmoker$weight
t = 7.7541, df = 19726, p-value = 9.324e-15
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
 3.464235 5.329752
sample estimates:
mean of x mean of y 
 172.0043  167.6073 

Draw conclusions in the context of your problem.

Assuming adults in the U.S. that are smokers weight the same as adults in the U.S. that are nonsmokers, there is almost a 0% chance of seeing data as extreme as mine. At the 0.10 significance level we reject the null hypothesis. We conclude there is a difference in weight between smokers and nonsmokers, since our sample mean of smokers (172.0) is higher than our sample mean of nonsmokers (167.6), the average weight of smokers is more than nonsmokers.


Optional Challenges

Do not have to complete.

For adult US men, is there a linear relationship between weight and desired weight? If there is one, then what is the magnitude of the relationship? May help to refer to Chapter 13 in the textbook.


We will use a linear model to answer this question.

\[\widehat{weight} = \beta_0 + \beta_1 \left(desired-weight\right)\]

Use a hypothesis test for \(\beta_1\) with a significance level of 0.05 to test if there is a relationship. — Use lm() and summary().

\[H_0: \beta_1 = 0\] \[H_A: \beta_1 \ne 0\]

We will also construct a 95% confidence interval for \(\beta_1\) to estimate the size/magnitude of the relationship. — Use lm() and confint().

# subset the data for the population of interest 
cdc_men <- cdc %>% 
  filter(gender == "m")

# check if a linear relationship is appropriate by plotting line of best fit using method = "lm"
ggplot(data = cdc_men, aes(wtdesire, weight))+
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

# correlation to determine linear relationship
cdc_men %>% 
  select(weight, wtdesire) %>% 
  cor()
            weight  wtdesire
weight   1.0000000 0.7676732
wtdesire 0.7676732 1.0000000
# now fit a linear model
model_men <- lm(weight ~ wtdesire, data = cdc_men)


# use summary(model) to get p-value to evaluate hypothesis test
summary(model_men)

Call:
lm(formula = weight ~ wtdesire, data = cdc_men)

Residuals:
    Min      1Q  Median      3Q     Max 
-545.23  -10.46   -5.46    7.82  287.82 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.592407   1.646898  -0.967    0.334    
wtdesire     1.068854   0.009122 117.169   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 23.42 on 9567 degrees of freedom
Multiple R-squared:  0.5893,    Adjusted R-squared:  0.5893 
F-statistic: 1.373e+04 on 1 and 9567 DF,  p-value: < 2.2e-16
# construct 95% CI for slope using confint() (default is 0.95)
confint(model_men, level = 0.95)
                2.5 %   97.5 %
(Intercept) -4.820677 1.635862
wtdesire     1.050973 1.086736

p-value: <2e-16

Assuming there is no relationship between weight and desired weight for US men, there is almost a 0% chance of seeing data as extreme as ours. At the 0.05 significance level, we reject the null hypothesis. There is a linear relationship between weight and weight desired.

95% CI: [1.05 , 1.09 ]

For US men, we are 95% confident that for each additional pound that a man desires to lose the predicted weight of the male increases by somewhere between 1.05 and 1.09 pounds.