Worksheet 2
Anu Olatunde (7981759)
2025-10-04
Question 1 [2 marks]
Q1(a)
Import the Class2 dataset, which contains the names, heights, majors, and SAT scores for one lab within a
larger statistics course.
Class2 <- read.csv("Class2 (1).csv")
View(Class2)
We would like to conduct a hypothesis test at the 1% level of significance to determine whether the true
mean SAT score of students in this course differs from 1250. SAT scores for students in this course follow a
normal distribution with unknown standard deviation.
Write the hypotheses for this test below. Replace the {} with either =, <, >, or \neq, to produce the not
equals sign.
H0 : µ
vs.
Ha : µ
We can use the t.test function to easily conduct a t-test in R. We type t.test(x, alternative = ...,
mu = ...), where:
• The vector x is the dataset we provide
• The argument alternative allows us to specify whether the test is supposed to be right-sided
(alternative = "greater"), left-sided (alternative = "less"), or two-sided (alternative =
"two.sided").
• The value mu is µ0 , the value of µ from the null hypothesis.
Use t.test to conduct the hypothesis test.
t.test(Class2$SAT, alternative = "two.sided", mu = 1250)
##
## One Sample t-test
##
## data: Class2$SAT
## t = 2.2149, df = 29, p-value = 0.03478
## alternative hypothesis: true mean is not equal to 1250
## 95 percent confidence interval:
1
## 1254.052 1351.748
## sample estimates:
## mean of x
##
1302.9
Type the P-value below.
0.03478.
Use the P-value to type the conclusion of the test below, in the context of this example.
Since the P-value is greater than our level of significance, we fail to reject the null hypothesis. At the 1%
level of significance, we have insufficient evidence that the true mean SAT score of students in this course
differs from 1250
Notice that t.test also produces a 95% confidence interval by default. The t.test function will always
produce a confidence interval, even if you are running a left- or right-sided test. Unless you are running a
two-sided test, you should ignore this output.
Now, suppose that we would like to calculate a 99% confidence interval for the true mean SAT score of
all students in this course. We can use the t.test function to produce a confidence interval by typing
t.test(x, alternative = "two.sided", conf.level = ...), where conf.level is our desired confidence level, written as a decimal.
Use t.test to calculate a 99% confidence interval for the true mean SAT score of all students in this course.
t.test(Class2$SAT, alternative = "two.sided", conf.level = 0.99)
##
## One Sample t-test
##
## data: Class2$SAT
## t = 54.552, df = 29, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 99 percent confidence interval:
## 1237.067 1368.733
## sample estimates:
## mean of x
##
1302.9
Type the confidence interval below.
(1237.067, 1368.733)
Q1(b)
Import the WeightLossF25 dataset, which contains the results from a study of 18 individuals who participated in a brief six-week weight loss study. Their weight (in kg) was measured at the beginning (Before)
and the end (After) of the study.
WeightLossF25 <- read.csv("WeightLossF25.csv")
We will conduct a hypothesis test at the 1% level of significance to determine if the weight loss strategies
from the study are effective. Differences are measured as before weight - after weight. Assume that the
appropriate normality conditions are satisfied.
2
Write the hypotheses for this test below. Replace the {} with either =, <, >, or \neq (which produces the
not equal sign).
H0 : µd
vs.
Ha : µd
We can use the t.test function to conduct the hypothesis test. We type t.test(x, y, paired = TRUE,
alternative = ...), where
• The vector x is dataset we provide for the first variable
• The vector y is the dataset we provide for the second variable
• The argument paired = TRUE tells R that this is a matched-pairs test
• The argument alternative allows us to specify whether the test is supposed to be right-sided
(alternative = "greater"), left-sided (alternative = "less"), or two-sided (alternative =
"two.sided").
Note that R will always measure the differences as first variable - second variable.
Use t.test to conduct the hypothesis test.
t.test(WeightLossF25$Before, WeightLossF25$After, paired = TRUE, alternative = "greater")
##
## Paired t-test
##
## data: WeightLossF25$Before and WeightLossF25$After
## t = 1.3458, df = 17, p-value = 0.09802
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
## -0.2828842
Inf
## sample estimates:
## mean difference
##
0.9666667
Use the P-value to type the conclusion of the test below, in the context of this example.
Since the Pvalue is greater than the level of significance, we fail to reject the null hypothesis. At the 1% level
of significance, we have insufficient evidence that the weight loss strategies from the study are effective
We can also use t.test to produce a confidence interval by setting the alternative to alternative =
"two.sided", and specifying the confidence level (as a decimal) with conf.level.
Use t.test to calculate a 99% confidence interval for the true mean weight loss using the weight loss
strategies from the study.
t.test(WeightLossF25$Before, WeightLossF25$After, paired = TRUE, alternative = "two.sided",
conf.level = 0.99)
##
## Paired t-test
##
## data: WeightLossF25$Before and WeightLossF25$After
## t = 1.3458, df = 17, p-value = 0.196
3
## alternative hypothesis: true mean difference is not equal to 0
## 99 percent confidence interval:
## -1.115118 3.048451
## sample estimates:
## mean difference
##
0.9666667
Type the confidence interval below:
(-1.12, 3.05)
Question 2 [10 marks]
Q2(a) [1 mark]
Import the CallsF25 dataset, which contains typical call times in minutes (recorded on Monday and Friday)
for a sample of customer service representatives, along with their employment level (Novice or Experienced).
CallsF25 <- read.csv("CallsF25.csv")
Q2(b) [2 marks]
Use t.test to determine, at the 5% level of significance, whether the true mean Monday call length at this
company is more than 7.4 minutes. Assume that Monday call lengths follow a normal distribution, with
unknown standard deviation.
t.test(CallsF25$Monday, alternative = "greater", mu = 7.4)
##
## One Sample t-test
##
## data: CallsF25$Monday
## t = 1.943, df = 59, p-value = 0.02839
## alternative hypothesis: true mean is greater than 7.4
## 95 percent confidence interval:
## 7.436389
Inf
## sample estimates:
## mean of x
##
7.66
Use the P-value to type your conclusion below, in the context of this example.
The Pvalue is 0.02839. Since this is less than the 5% significance level, we reject the null hypothesis. At 5%
level of significance, we have sufficient evidence to conclude that the true mean Monday call length at this
company is greater than 7.4 minutes
Q2(c) [1 mark]
Use t.test to calculate a 95% confidence interval for the true mean Monday call length.
4
t.test(CallsF25$Monday, alternative = "two.sided", conf.level = 0.95)
##
## One Sample t-test
##
## data: CallsF25$Monday
## t = 57.245, df = 59, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 7.392245 7.927755
## sample estimates:
## mean of x
##
7.66
Type the confidence interval below.
( 7.392, 7.928)
Q2(d) [3 marks]
Use t.test to determine, at the 5% level of significance, whether Monday call times differ from Friday call
times on average. Assume that differences in call times follow a normal distribution. Measure the differences
as Monday - Friday.
t.test(CallsF25$Monday, CallsF25$Friday, paired = TRUE, alternative = "two.sided")
##
## Paired t-test
##
## data: CallsF25$Monday and CallsF25$Friday
## t = -0.64088, df = 59, p-value = 0.5241
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.2933659 0.1510326
## sample estimates:
## mean difference
##
-0.07116667
Use the P-value to type your conclusion below.
The Pvalue is 0.5241. Since this is greater than the 5% significance level, we fail to reject the null hypothesis
and conclude that there is not enough evidence to suggest that Monday and Friday call times differ on average
Q2(e) [1 mark]
Use t.test to construct a 95% confidence interval for the true mean of the differences in call times between
Mondays and Fridays.
t.test(CallsF25$Monday, CallsF25$Friday, paired = TRUE, alternative = "two.sided", conf.level = 0.95)
5
##
## Paired t-test
##
## data: CallsF25$Monday and CallsF25$Friday
## t = -0.64088, df = 59, p-value = 0.5241
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.2933659 0.1510326
## sample estimates:
## mean difference
##
-0.07116667
Type the confidence interval below.
(-0.293, 0.151)
Q2(f) [2 marks]
Can you use the above confidence interval to conclude the test in (e)? If yes, what would your conclusion
be? and why? If not, explain why not.
Yes, we can use the confidence interval to conclude the test in (e). Since the 95% confidence interval for the
mean difference in call times between Mondays and Fridays is (-0.2934, 0.1510), and this interval includes
0, we fail to reject the null hypothesis. This means there is not enough evidence to conclude that Monday and
Friday call times differ on average. The presence of 0 in the interval suggests that the true mean difference
could be zero, indicating no significant difference.
6