The T test function in R is very simple to use and the problem gives
us all the information needed to run it. The simple script is
t.test(“sample”,mu)
Here is the problem to solve: The following are ages of 7 randomly
chosen patrons seen leaving the Beach Comber in South Mission Beach at
7pm! We assume that the data comes from a normal distribution and would
like to test the claim that the mean age of the distribution of Beach
Comber patrons is different than 21. Conduct a 6 step hypothesis test to
test this claim.
25, 19, 37, 29, 40, 28, 31
6 Step Hypothesis
1. State the Hypotheses
Null Hypothesis = The mean age of patrons at the Beach Comber is
21
Alternative Hypothesis = The mean age of patrons at the Beach Comber
is not 21
2. Significance Level
The common significance level is complementary to the confidence
interval used by the t test. In the case of this problem as confidence
interval of 95% (conf.level = 0.95) equates to a signicance level of
0.05
3. Choose Appropriate Test Statistic
Due to the small sample size and unknown standard deviation the
T-Test would be the most apt statistical test for determining whether
the Null hypothesis is true or false.
4. Decision Rule
The decision rule to determine the validity of the Null hypothesis
for a T-Test is to determine whether the calculated t-value (TV) is
greater than or less than the critical t-value (CritTV).
# If P-value > alpha then Null Hypothesis is TRUE
# If P-value <= alpha then Alternative Hypothesis is TRUE
5. Calculate the Test Statistic and P-Value
The t.test() function in R will conduct the test and return the
resulting determination. We can verify by comparing the P-value outcome
to alpha (in this case alpha = 0.05)
# Define the known data
ages = c(25, 19, 37, 29, 40, 28, 31)
mu = 21
# Setup and run the T-test
ttest_1 = t.test(ages,mu = mu, conf.level = 0.95)
# Display the results
print(ttest_1)
##
## One Sample t-test
##
## data: ages
## t = 3.3093, df = 6, p-value = 0.01622
## alternative hypothesis: true mean is not equal to 21
## 95 percent confidence interval:
## 23.30816 36.40613
## sample estimates:
## mean of x
## 29.85714
6. Decision and Conclusion
The t.test() outcome states that the “alternative hypothesis: true
mean is not equal to 21”. This is confirmed by the P-value of 0.01622
being less than the alpha of 0.05.
In conclusion, the null hypothesis that the mean value of the age of
patrons at the Beach Comber is 21, is false.