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)

1. 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).
2. Choose the significance level of the test, such as $$\alpha=0.05$$.

3. 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.

4. 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$$.)

5. 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$$.)
6. 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)?

# install.packages("gsheet")

# Height vs Hand Span
library(gsheet)
dat.hand <- gsheet2tbl(dat.hand.url)
## No encoding supplied: defaulting to UTF-8.
dat.hand <- as.data.frame(dat.hand)
dat.hand <- na.omit(dat.hand)
dat.hand$Gender_M_F <- factor(dat.hand$Gender_M_F, levels = c("F", "M"))

str(dat.hand)
## 'data.frame':    84 obs. of  5 variables:
##  $Table : int 1 1 1 1 1 1 2 2 2 2 ... ##$ Person     : int  1 4 5 6 7 9 1 2 3 4 ...
##  $Gender_M_F : Factor w/ 2 levels "F","M": 1 2 1 2 1 2 1 1 1 1 ... ##$ Height_in  : num  62 72 65 70 60 72.9 69.5 67 68.5 64.5 ...
##  $HandSpan_cm: num 17 22.5 19 21 18.5 22.5 19.5 20 20 20 ... ## - attr(*, "na.action")=Class 'omit' Named int [1:42] 2 3 8 17 18 27 34 35 36 44 ... ## .. ..- attr(*, "names")= chr [1:42] "2" "3" "8" "17" ... 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. # calculate the estimated mean and order M then F est.mean <- as.numeric(by(dat.hand$Height_in, dat.hand$Gender_M_F, mean)) # combine true US mean with our estimated mean height.true <- data.frame(Gender_M_F = unique(dat.hand$Gender_M_F)
, Height_in = c(64, 69.5, est.mean)
, TrueEst = c(rep("True", 2), rep("Est", 2)))
height.true
##   Gender_M_F Height_in TrueEst
## 1          F  64.00000    True
## 2          M  69.50000    True
## 3          F  65.41842     Est
## 4          M  69.80217     Est

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

#$library(ggplot2) p <- ggplot(data = dat.hand, aes(x = Gender_M_F, y = Height_in)) p <- p + geom_boxplot(alpha = 1/4) p <- p + geom_jitter(position = position_jitter(width = 0.1)) p <- p + geom_point(data = height.true, aes(colour = TrueEst, shape = TrueEst), size = 4, alpha = 3/4) print(p) library(ggplot2) p <- ggplot(data = dat.hand, aes(x = Height_in)) p <- p + geom_histogram(binwidth = 1) p <- p + geom_vline(data = height.true, aes(xintercept = Height_in, colour = TrueEst, linetype = TrueEst)) p <- p + facet_grid(Gender_M_F ~ .) print(p) ## Conduct the hypothesis tests # look at help for t.test # ?t.test # defaults include: alternative = "two.sided", conf.level = 0.95 (I’ve hidden some code from Chapter 02 defining a function to plot the t-distribution with shaded p-value.) ### Test female height equal to US (model example). # test females t.summary.F <- t.test(subset(dat.hand, Gender_M_F == "F", Height_in) , mu = 64) t.summary.F ## ## One Sample t-test ## ## data: subset(dat.hand, Gender_M_F == "F", Height_in) ## t = 3.2005, df = 37, p-value = 0.002815 ## alternative hypothesis: true mean is not equal to 64 ## 95 percent confidence interval: ## 64.52044 66.31640 ## sample estimates: ## mean of x ## 65.41842 names(t.summary.F) ## [1] "statistic" "parameter" "p.value" "conf.int" "estimate" ## [6] "null.value" "alternative" "method" "data.name" t.dist.pval(t.summary.F) Hypothesis test 1. 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$$ 2. Let $$\alpha=0.05$$, the significance level of the test and the Type-I error probability if the null hypothesis is true. 3. $$t_{s} = 3.201$$. 4. $$p=0.00282$$, this is the observed significance of the test. 5. Because $$p=0.00282 < 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 1. (3 p) As above, set up the hypothesis test for males, but whether UNM males are taller on average than the US population. ### Test male height greater than US (your turn). ## You'll need to modify the statement below to correspond ## to the hypothesis you wish to test # test males t.summary.M <- t.test(subset(dat.hand, Gender_M_F == "M", Height_in) , mu = 0 , alternative = "two.sided") t.summary.M ## ## One Sample t-test ## ## data: subset(dat.hand, Gender_M_F == "M", Height_in) ## t = 159.82, df = 45, p-value < 2.2e-16 ## alternative hypothesis: true mean is not equal to 0 ## 95 percent confidence interval: ## 68.92252 70.68183 ## sample estimates: ## mean of x ## 69.80217 t.dist.pval(t.summary.M) Hypothesis test 1. ’’ •$H_0: $versus$H_A: $2. Let $$\alpha=0.05$$, the significance level of the test and the Type-I error probability if the null hypothesis is true. 3.$t_{s} = $. 4.$p = $, this is the observed significance of the test. 5. Because$p = $, … Also, given your conclusion, state whether you could have made a Type-I or Type-II error. # Earth’s water example ## Questions to answer 1. (3 p) In class we sampled the beach ball and observed 20 of 30 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 = 1 n = 30 x = 20 dat.globe <- data.frame(type = c("Water", "Land"), freq = c(x, n - x), prop = c(x, n - x) / n) dat.globe ## type freq prop ## 1 Water 20 0.6666667 ## 2 Land 10 0.3333333 # binom.test() is an exact test for a binomial random variable b.summary <- binom.test(x = x, n = n, p = 0.5, conf.level = 0.95) b.summary ## ## Exact binomial test ## ## data: x and n ## number of successes = 20, number of trials = 30, p-value = 0.09874 ## alternative hypothesis: true probability of success is not equal to 0.5 ## 95 percent confidence interval: ## 0.4718800 0.8271258 ## sample estimates: ## probability of success ## 0.6666667 library(ggplot2) p <- ggplot(data = subset(dat.globe, type == "Water"), aes(x = type, y = prop)) p <- p + geom_hline(yintercept = c(0, 1), alpha = 1/4) p <- p + geom_bar(stat = "identity") 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") p <- p + scale_y_continuous(limits = c(0, 1)) p <- p + coord_flip() # flip the x and y axes for horizontal plot print(p) Hypothesis test 1. ’’ •$H_0: $versus$H_A: $2. Let $$\alpha=0.05$$, the significance level of the test and the Type-I error probability if the null hypothesis is true. 3.$t_{s} = $. 4.$p = $, this is the observed significance of the test. 5. Because$p = $, … Also, given your conclusion, state whether you could have made a Type-I or Type-II error. # African countries in the UN example 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: 1. Do you think the percentage of countries, among all those in the United Nations, that are in Africa is higher or lower than X? 2. Give your best estimate of the percentage of countries, among all those in the United Nations, that are in Africa. The data were compiled into a google doc which we read in below. # install.packages("gsheet") # Height vs Hand Span library(gsheet) dat.UN.Africa.url <- "docs.google.com/spreadsheets/d/1PkjIygZdtlopH6kvyle-KeoECsycHWyCaya92erlvaE" dat.UN.Africa <- gsheet2tbl(dat.UN.Africa.url) ## No encoding supplied: defaulting to UTF-8. dat.UN.Africa <- as.data.frame(dat.UN.Africa) dat.UN.Africa <- na.omit(dat.UN.Africa) dat.UN.Africa$PrimingNumber <- factor(dat.UN.Africa$PrimingNumber) dat.UN.Africa$HighLow       <- factor(dat.UN.Africa$HighLow) str(dat.UN.Africa) ## 'data.frame': 72 obs. of 4 variables: ##$ PrimingNumber: Factor w/ 2 levels "10","65": 1 1 1 1 1 1 1 1 1 1 ...
##  $HighLow : Factor w/ 3 levels "H","H ","L": 3 3 3 3 3 3 3 3 2 1 ... ##$ UN_Percentage: num  0 2 3 5 7 7 8 25 12 7 ...
##  $Class : chr "F16" "F16" "F16" "F16" ... Here are some summaries and plots. ## If we create a summary data.frame with a similar structure as our data, then we ## can annotate our plot with those summaries. # calculate the estimated mean and order M then F est.mean <- as.numeric(by(dat.UN.Africa$UN_Percentage, dat.UN.Africa$PrimingNumber, mean)) # combine true US mean with our estimated mean mean.UN.Africa <- data.frame(PrimingNumber = unique(dat.UN.Africa$PrimingNumber)
, UN_Percentage = est.mean)
mean.UN.Africa
##   PrimingNumber UN_Percentage
## 1            10      18.30171
## 2            65      38.37838
# histogram using ggplot
p <- ggplot(dat.UN.Africa, aes(x = UN_Percentage))
p <- p + geom_histogram(binwidth = 4)
p <- p + geom_rug()
p <- p + geom_vline(data = mean.UN.Africa, aes(xintercept = UN_Percentage, colour = "red"))
p <- p + facet_grid(PrimingNumber ~ .)
print(p)

p <- ggplot(dat.UN.Africa, aes(x = UN_Percentage, fill=PrimingNumber))
p <- p + geom_histogram(binwidth = 4, alpha = 0.5, position="identity")
p <- p + geom_rug()
p <- p + geom_vline(data = mean.UN.Africa, aes(xintercept = UN_Percentage, colour = PrimingNumber, linetype = PrimingNumber))
p <- p + geom_rug(aes(colour = PrimingNumber), alpha = 1/2)
print(p)

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.

1. (4 p) Set up the two-sample t-test and state the conclusions.
# two-sample t-test
t.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 = -4.3312, df = 58.136, p-value = 2.969e-05
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##       -Inf -12.32872
## sample estimates:
## mean in group 10 mean in group 65
##         18.30171         38.37838
t.dist.pval(t.summary.UN)

Hypothesis test

1. ’’
• $H_0:$ versus $H_A:$
2. Let $$\alpha=0.05$$, the significance level of the test and the Type-I error probability if the null hypothesis is true.

3. $t_{s} =$.

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

5. Because $p =$, …

Also, given your conclusion, state whether you could have made a Type-I or Type-II error.