<-50
muEx1<-10
sigmaEx1<-16
n
<-(46-muEx1)/(sigmaEx1/sqrt(n))) (teststat
[1] -1.6
<-qt(0.025,n-1)) (tcrit
[1] -2.13145
The null hypothesis is a statement about the population parameter. Usually, the status quo. In research, it states no effect or no relationship between variables. The null hypothesis includes some form of the equality sign (i.e., \(\geq\), \(\leq\), or \(=\)).
The alternative hypothesis directly contradicts the null hypothesis. In research, it states the prediction of the effect or relationship. The alternative includes non-equality signs (i.e., \(>\), \(<\), or \(\ne\)).
To conduct hypothesis testing:
For means use:
\(H_o: \mu \leq 0\); \(Ha: \mu > \mu_o\) right-tail probability
\(H_o: \mu \geq 0\); \(Ha: \mu < \mu_o\) left-tail probability
\(H_o: \mu = 0\); \(Ha: \mu \ne \mu_o\) two-tail probability
For proportions use:
\(H_o: P \leq 0\); \(Ha: P > P_o\) right-tail probability
\(H_o: P \geq 0\); \(Ha: P < P_o\) left-tail probability
\(H_o: P = 0\); \(Ha: P \ne P_o\) two-tail probability
Specify the confidence level (i.e., how likely you would be to see non-extreme data, when assuming the null is true. False negative tolerance) and significance level (i.e. how likely you would be to see extreme data, when assuming the null is true. False positive tolerance). Confidence levels are usually set at, \(0.90\), \(0.95\), or \(0.99\), which correspond to \(10\)%, \(5\)%, and \(1\)% significant levels, respectively.
Calculate the test statistic.
For a test on means use \(t_{df}= \frac {\bar x-\mu_o}{s/\sqrt{n}}\), where \(df=n-1\), \(\bar x\) is the sample mean, \(\mu_o\) is the hypothesized value of \(\mu\), \(s\) is the sample standard deviation, and \(n\) is the sample size.
For a test on proportions use \(z= \frac {\bar p- P_o}{\sqrt {P_o(1-P_o)/ n}}\), where \(\bar p\) is the sample proportion, \(P_o\) is the hypothesized value of the population proportion \(P\), and \(n\) is the sample size.
Find the p-value (i.e., the likelihood of getting the observed or more extreme data, assuming the null hypothesis is true). (Substitute \(t\) for \(z\) if using proportions)
For a right-tail test, the \(p\)-value is \(P(T\geq t)\).
For a left-tail test, the \(p\)-value is \(P(T\leq t)\).
For a two-tail test, the \(p\)-value is \(2P(T\geq t)\) if \(t>0\) or \(2P(T\leq t)\) if \(t<0\).
The decision rule is to reject the null hypothesis when the \(p-value<\alpha\), and not to reject when \(p-value \geq alpha\).
t.test()
generates a \(t\)-test for a vector of values. Use the alternative argument to specify “greater”, “less” or “two.sided” test. The mu argument specifies the hypothesized value for the mean. The conf.level sets the confidence level of the test (0.9,0.95,0.99, etc.).
prop.test()
generates a proportion test when provided the number of successes and sample size.
The following exercises will help you test your knowledge on Hypothesis Testing. In particular, the exercises work on:
Stating Null and Alternate Hypothesis.
Determine the statistical validity of the null hypothesis.
Conducting t-tests in R.
Answers are provided below. Try not to peak until you have a formulated your own answer and double checked your work for any mistakes.
Consider the following hypothesis: \(H_{o}: \mu=50\), \(H_{a}: \mu \neq 50\). A sample of \(16\) observations yields a mean of \(46\) and a standard deviation of \(10\). Calculate the value of the test statistic. At a \(5\)% significance level, does the population mean differ from \(50\)?
Consider the following hypothesis: \(H_{o}: \mu \geq 100\), \(H_{a}: \mu < 100\). You take a sample from a normally distributed population that yields the values in the table below. Conduct a test at a \(1\)% significance level to prove the hypothesis.
96 | 102 | 93 | 87 | 92 | 82 |
210 | 220 | 299 | 220 | 290 | 280 | 233 | 221 | 292 | 299 |
According to a www.nps.gov, the period of time between Old Faithful’s eruptions is on average is \(92\) minutes. Use the built in faithful R data set and a two tail test to determine whether this claim is true.
To test if the population proportion differs from \(0.4\), a scientist draws a random sample of \(100\) observations and obtain a sample proportion of \(0.48\). Specify the competing hypothesis. At a \(5\)% significance level, does the population proportion differ from \(0.4\)?
When taking a sample of \(320\) observations, \(128\) result in success.Test the following hypothesis \(H_{o}: p \geq 0.45\), \(H_{a}: p < 0.45\) at a \(5\)% significance level.
Determine if more than \(50\)% of the observations in a population are below \(10\) with the sample data below. Conduct the test at a \(1\)% significance level.
8 | 12 | 5 | 9 | 14 | 11 | 9 | 3 | 7 | 12 |
According to www.worldatlas.com, \(5\)% of the population has hazel color eyes. Use the built in HairEyeColor R data set and a two tail test to determine whether this claim is true.
In R we can calculate the t-statistic.
<-50
muEx1<-10
sigmaEx1<-16
n
<-(46-muEx1)/(sigmaEx1/sqrt(n))) (teststat
[1] -1.6
<-qt(0.025,n-1)) (tcrit
[1] -2.13145
Since the t-statistic is greater than the critical value of \(-2.13\), we can’t reject the null. We can also estimate the p-value to confirm this finding. Recall that the P-value is the likelihood of obtaining a sample mean at least as extreme as the one derived from the given sample.
2*pt(teststat,n-1)
[1] 0.130445
Let’s start by creating an object to store the values of our sample.
<-c(96,102,93,87,92,82) sample2
Now we can construct the t-stat and calculate the critical value.
<-mean(sample2)
mean2<-sd(sample2)
standard2<- length(sample2)
n2<-(mean2-100)/(standard2/sqrt(n2))) (tstat2
[1] -2.816715
Lastly, we can calculate the p-value.
pt(tstat2,n2-1)
[1] 0.0186262
We can also verify our result using the t.test()
function in R.
t.test(sample2,alternative = "less",mu = 100,conf.level = 0.99)
One Sample t-test
data: sample2
t = -2.8167, df = 5, p-value = 0.01863
alternative hypothesis: true mean is less than 100
99 percent confidence interval:
-Inf 101.557
sample estimates:
mean of x
92
Let’s create the object in R with the data.
<-c(210,220,299,220,290,280,233,221,292,299) sample3
Using the t.test()
function we find:
t.test(sample3,alternative="greater",mu=210,conf.level=0.9)
One Sample t-test
data: sample3
t = 3.8333, df = 9, p-value = 0.002004
alternative hypothesis: true mean is greater than 210
90 percent confidence interval:
239.6593 Inf
sample estimates:
mean of x
256.4
The claim that the duration between eruptions is \(92\) minutes can be rejected at a \(10\)%, \(5\)%, and \(1\)% significance level.
Once more calculate the t-test in R with the t.test()
function.
t.test(faithful$waiting,alternative = "two.sided",mu=92, conf.level = 0.99)
One Sample t-test
data: faithful$waiting
t = -25.601, df = 271, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 92
99 percent confidence interval:
68.75871 73.03541
sample estimates:
mean of x
70.89706
In R we can calculate the test statistic \(\frac {\bar{p}-p_{o}}{\sqrt {p_{o}(1-p_{o})/n}}\).
<-(0.48-0.4)/sqrt(0.4*(1-0.4)/100)) (pstat
[1] 1.632993
Now we can use the pnorm()
function in R to get the p-value. Since it is a two-tailed test we multiply the probability by 2.
2*pnorm(pstat,lower.tail = F)
[1] 0.1024704
We once again create the test statistic in R.
<-(0.4-0.45)/sqrt(0.45*(1-0.45)/320)) (pstat2
[1] -1.797866
With the statistic, we can now find the p-value:
pnorm(pstat2,lower.tail = T)
[1] 0.0360991
Let’s create an object to store the values.
<-c(8,12,5,9,14,11,9,3,7,12) values
Now, let’s count how many values are below \(10\) and calculate the proportion.
sum(values<10)/length(values)
[1] 0.6
Lastly, we find the test-statistic and p-value:
<-(0.6-0.5)/sqrt(0.5*(1-0.5)/10)
pstat3pnorm(pstat3,lower.tail = F)
[1] 0.2635446
We can also use the prop.test()
function in R to confirm our result.
prop.test(6,10,p=0.5,alternative = "greater", conf.level = 0.99,
correct=F)
1-sample proportions test without continuity correction
data: 6 out of 10, null probability 0.5
X-squared = 0.4, df = 1, p-value = 0.2635
alternative hypothesis: true p is greater than 0.5
99 percent confidence interval:
0.2724654 1.0000000
sample estimates:
p
0.6
The number of people with Hazel eyes is calculated as:
<-sum(HairEyeColor[,3,1]+HairEyeColor[,3,2])) (s
[1] 93
The total number of people in the survey is given by:
<-sum(HairEyeColor)) (t
[1] 592
We can use the prop.test()
function once more:
prop.test(93,592,p=0.05,alternative = "two.sided", conf.level = 0.95, correct=F)
1-sample proportions test without continuity correction
data: 93 out of 592, null probability 0.05
X-squared = 142.94, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.05
95 percent confidence interval:
0.1300037 0.1886070
sample estimates:
p
0.1570946