Include your answers in this document in the sections below the rubric.

Rubric

Answer the questions with the two data examples.

Mechanics of a hypothesis test (review)

Set up the null and alternative hypotheses in words and notation.

In words: ``The population mean for [what is being studied] is different from [value of \(\mu_0\)].’’ (Note that the statement in words is in terms of the alternative hypothesis.)

In notation: \(H_0: \mu=\mu_0\) versus \(H_A: \mu \ne \mu_0\) (where \(\mu_0\) is specified by the context of the problem).

Choose the significance level of the test, such as \(\alpha=0.05\).

Compute the test statistic, such as \(t_{s} = \frac{\bar{Y}-\mu_0}{SE_{\bar{Y}}}\), where \(SE_{\bar{Y}}=s/\sqrt{n}\) is the standard error.

Determine the tail(s) of the sampling distribution where the \(p\)-value from the test statistic will be calculated (for example, both tails, right tail, or left tail). (Historically, we would compare the observed test statistic, \(t_{s}\), with the critical value\(t_{\textrm{crit}}=t_{\alpha/2}\) in the direction of the alternative hypothesis from the \(t\)-distribution table with degrees of freedom \(df = n-1\).)

State the conclusion in terms of the problem.

Reject \(H_0\) in favor of \(H_A\) if \(p\textrm{-value} < \alpha\).

Fail to reject \(H_0\) if \(p\textrm{-value} \ge \alpha\). (Note: We DO NOT accept\(H_0\).)

Check assumptions of the test (next week).

Height data for our class

Is the population mean height of UNM students eligible to take Stat 427/527 different from the US average for men (5 ft 9 1/2 in) or women (5 ft 4 in)?

# Height vs Hand Spandat_hand <-read_csv("ADA1_CL_13_Data-CorrHandSpan.csv") %>%na.omit() %>%mutate(Gender_M_F =factor(Gender_M_F, levels =c("F", "M")) )

Rows: 378 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Semester, Gender_M_F
dbl (4): Table, Person, Height_in, HandSpan_cm
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Plot the estimated mean from our class sample versus the true US mean.

## If we create a summary data.frame with a similar structure as our data, then we## can annotate our plot with those summaries.est_mean <- dat_hand %>%group_by( Gender_M_F ) %>%summarize(Height_in =mean(Height_in) , .groups ="drop_last" ) %>%ungroup() %>%mutate(TrueEst ="Est" )true_mean <-tribble(~Gender_M_F, ~Height_in, ~TrueEst , "F", 64.0, "True" , "M", 69.5, "True" )trueest_mean <- est_mean %>%bind_rows( true_mean )trueest_mean

# A tibble: 4 × 3
Gender_M_F Height_in TrueEst
<chr> <dbl> <chr>
1 F 65.2 Est
2 M 70.3 Est
3 F 64 True
4 M 69.5 True

Here’s two ways to plot our data, annotating the observed and hypothesized means.

The following object is masked from 'package:dplyr':
combine

lay <-rbind(c(1, 2, 2) # let Plot 2 take twice as much horizontal space as Plot 1 )grid.arrange(grobs =list(p1, p2) , layout_matrix = lay , top ="Two ways to display the data" )

Conduct the hypothesis tests (example)

# look at help for t.test# ?t.test# defaults include: alternative = "two.sided", conf.level = 0.95

Model example: Test female height equal to US.

# test femalest_summary_F <-t.test( dat_hand %>%filter(Gender_M_F =="F") %>%pull(Height_in) , mu =64 , alternative ="two.sided" )t_summary_F

One Sample t-test
data: dat_hand %>% filter(Gender_M_F == "F") %>% pull(Height_in)
t = 5.2102, df = 106, p-value = 9.351e-07
alternative hypothesis: true mean is not equal to 64
95 percent confidence interval:
64.76972 65.71533
sample estimates:
mean of x
65.24252

``The population mean height for females at UNM eligible to take Stat 427/527 is different from the US population value of \(\mu_0=64\) inches.’’

\(H_0: \mu = 64\) versus \(H_A: \mu \ne 64\)

Let \(\alpha = 0.05\), the significance level of the test and the Type-I error probability if the null hypothesis is true.

\(t_{s} = 5.21\).

\(p = 9.35\times 10^{-7}\), this is the observed significance of the test.

Because \(p = 9.35\times 10^{-7} < 0.05\), we have sufficient evidence to reject \(H_0\), concluding that the observed mean height is different than the US population mean.

Questions to answer

(3 p) As above, set up the hypothesis test for males, but whether UNM males are taller on average than males in the US population.

Your turn: Test male height greater than US.

## You'll need to modify the statement below to correspond## to the hypothesis you wish to test# test malest_summary_M <-t.test( dat_hand %>%filter(Gender_M_F =="M") %>%pull(Height_in) , mu =0 , alternative ="two.sided" )t_summary_M

One Sample t-test
data: dat_hand %>% filter(Gender_M_F == "M") %>% pull(Height_in)
t = 279.52, df = 129, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
69.79972 70.79490
sample estimates:
mean of x
70.29731

e_plot_ttest_pval(t_summary_M)

Hypothesis test

``’’

$H_0: $ versus $H_A: $

Let \(\alpha=0.05\), the significance level of the test and the Type-I error probability if the null hypothesis is true.

$t_{s} = $.

$p = $, this is the observed significance of the test.

Because $p = $, …

Also, given your conclusion, state whether you could have made a Type-I or Type-II error and why it is one but not the other.

Earth’s water example

Questions to answer

(3 p) In class we sampled the beach ball and observed 21 of 35 observations were water. Conduct a hypothesis test to determine whether the proportion of water on the beach ball is different from the amount of water on the earth’s surface (71%).

## notes for prop.test() and binom.test()# x = number of "successes"# n = total sample size#n = 2#x = 1x =21n =21+14dat_globe <-tribble(~type , ~freq , ~prop , "Water" , x , x / n , "Land" , n - x , (n - x) / n )dat_globe

# A tibble: 2 × 3
type freq prop
<chr> <dbl> <dbl>
1 Water 21 0.6
2 Land 14 0.4

# # prop.test() is an asymptotic (approximate) test for a binomial random variable# p_summary <- prop.test(x = x, n = n, conf.level = 0.95)# p_summary# binom.test() is an exact test for a binomial random variableb_summary <-binom.test(x = x, n = n, conf.level =0.95)b_summary

Exact binomial test
data: x and n
number of successes = 21, number of trials = 35, p-value = 0.3105
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.4211177 0.7612919
sample estimates:
probability of success
0.6

library(ggplot2)p <-ggplot(data = dat_globe %>%filter(type =="Water"), aes(x = type, y = prop))p <- p +geom_hline(yintercept =c(0, 1), alpha =1/4)p <- p +geom_bar(stat ="identity", fill ="gray60")p <- p +geom_errorbar(aes(min = b_summary$conf.int[1], max = b_summary$conf.int[2]), width=0.25)p <- p +geom_hline(yintercept =0.71, colour ="red", linetype =2)p <- p +scale_y_continuous(limits =c(0, 1))p <- p +coord_flip() # flip the x and y axes for horizontal plotp <- p +labs(caption ="Red line is 71%. Black bar is 95% CI.")print(p)

Hypothesis test

``’’

$H_0: $ versus $H_A: $

Let \(\alpha=0.05\), the significance level of the test and the Type-I error probability if the null hypothesis is true.

$z = $.

$p = $ (p-value), this is the observed significance of the test.

Because $p = $ (p-value), …

Also, given your conclusion, state whether you could have made a Type-I or Type-II error and why it is one but not the other.

African countries in the UN example

In previous years we conducted the following experiment; we will look at Fall 2019, where the priming effect was the weakest.

Previously in class we collected data using a randomized experiment. We provided a priming number (X = 10 or 65, not actually a random number) then asked you two questions:

Do you think the percentage of countries represented in the United Nations that are from Africa is higher or lower than X?

Give your best estimate of the percentage of countries represented in the United Nations that are from Africa.

The data were compiled into a google doc which we read in below as a csv file.

# UN Africa surveydat_UN_Africa <-read_csv("ADA1_CL_18_UN_MembershipSurvey.csv") %>%na.omit() %>%mutate(PrimingNumber =factor(PrimingNumber) , HighLow =factor(HighLow) ) %>%filter( Class =="F19" )

Rows: 198 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): HighLow, Class
dbl (2): PrimingNumber, UN_Percentage
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

A priori, before we observed the data, we hypothesized that those who were primed with a larger number (65) would provide a higher percentage (UN_Percentage) than those with the lower number (10). Therefore, this is a one-sided test.

(4 p) Set up the two-sample t-test and state the conclusions.

# two-sample t-testt_summary_UN <-t.test( UN_Percentage ~ PrimingNumber , data = dat_UN_Africa , alternative ="less" )t_summary_UN

Welch Two Sample t-test
data: UN_Percentage by PrimingNumber
t = -2.9877, df = 47.438, p-value = 0.00222
alternative hypothesis: true difference in means between group 10 and group 65 is less than 0
95 percent confidence interval:
-Inf -4.463638
sample estimates:
mean in group 10 mean in group 65
17.97222 28.15152

e_plot_ttest_pval(t_summary_UN)

Hypothesis test

``’’

$H_0: $ versus $H_A: $

Let \(\alpha=0.05\), the significance level of the test and the Type-I error probability if the null hypothesis is true.

$t_{s} = $.

$p = $, this is the observed significance of the test.

Because $p = $, …

Also, given your conclusion, state whether you could have made a Type-I or Type-II error and why it is one but not the other.