Mathematical Science Department
Fall 2025
Appalachian State University
STT3850: Statistical Data Analysis I
Assessment: Problem Set
Instructor: Dr. Ian Anthony Forde ()

Instructions:

This problem set consists of 6 questions. Answer all questions. Show all working, including calculations, reasoning, and any visualizations used. You may use R or Python for computations and code, but ensure your code is clearly presented and results are interpreted in context. Use a significance level of alpha = 0.05 unless otherwise specified.

Question 1.

A cereal company claims that the mean sugar content of its cereal boxes is 9 g. A nutritionist measures sugar in 10 randomly selected boxes: [8.5, 9.1, 9.4, 8.9, 9.0, 8.7, 9.2, 8.8, 9.3, 8.6].

- Test whether the mean sugar content differs from 9 g at alpha = 0.05. (4 marks)

For this question. I’m going to use a two-tail t-test because the population standard deviation is unknown and the sample size is small.

The null hypothesis Ho is that the true mean of the cereal boxes is equal to 9 grams.
- Ho: mu = 9

The alternative hypothesis Ha is that the true mean of the cereal boxes is not equal to 9 grams.
- Ha: mu does not equal 9

The main assumption for this test is that the data comes from a normal distribution. I’m going to load in the data and then use a normal QQ plot to test this assumption.

# read in the data
cerealdata <- c(8.5, 9.1, 9.4, 8.9, 9.0, 8.7, 9.2, 8.8, 9.3, 8.6)

# making qqplot
qqnorm(cerealdata)
qqline(cerealdata)

The data adheres to the straight line, suggesting that it does come from a normal distribution.

Because the assumption is met, I’m going to continue with the t-test.

# run t-test
t.test(cerealdata, mu = 9)
## 
##  One Sample t-test
## 
## data:  cerealdata
## t = -0.52223, df = 9, p-value = 0.6141
## alternative hypothesis: true mean is not equal to 9
## 95 percent confidence interval:
##  8.733415 9.166585
## sample estimates:
## mean of x 
##      8.95

The output shows that the p-value is 0.6929, which is not less than our alpha of 0.05, so I’ll fail to reject the null hypothesis and conclude that there is not sufficient evidence to suggest that the true mean of the cereal boxes is not equal to 9 grams.

Question 2.

A factory claims the average time to assemble a product is 14 minutes. Assembly times from 15 workers are: [13.2, 14.5, 15.0, 14.1, 13.8, 14.3, 15.1, 13.9, 14.6, 13.7, 14.4, 14.9, 13.6, 15.2, 14.0].

- Test whether the true mean exceeds 14 minutes. (4 marks)

For this question, I’m going to use a one-tailed t-test because the population standard deviation is unknown, the sample is small, and I’m asked to test whether the true mean exceeds 14 minutes.

The null hypothesis Ho is that the true average time to assemble a product is equal to 14 minutes.
- Ho: mu = 14

The alternative hypothesis Ha is that the true average time to assemble a product is greater than 14 minutes.
- Ha: mu > 14

The main assumption for this test is that the data comes from a normal distribution. I’m going to load in the data and then use a normal QQ plot to test this assumption.

# read in the data
assemblydata <- c(13.2, 14.5, 15.0, 14.1, 13.8, 14.3, 15.1, 13.9, 14.6, 13.7, 14.4, 14.9, 13.6, 15.2, 14.0)

# making qqplot
qqnorm(assemblydata)
qqline(assemblydata)

The data adheres to the straight line, suggesting that it does come from a normal distribution.

Because the assumption is met, I’m going to continue with the t-test.

# run t-test
t.test(assemblydata, mu = 14, alternative = "greater")
## 
##  One Sample t-test
## 
## data:  assemblydata
## t = 1.8509, df = 14, p-value = 0.0427
## alternative hypothesis: true mean is greater than 14
## 95 percent confidence interval:
##  14.01388      Inf
## sample estimates:
## mean of x 
##  14.28667

The output shows that the p-value is 0.0427, which is less than our alpha of 0.05, so I’ll reject the null hypothesis and conclude that there is sufficient evidence to suggest that the true mean of the product assembly time is greater than 14 minutes.

Question 3.

Two fertilizers are tested for crop yield (kg). Fertilizer A: [42, 45, 47, 44, 46, 43, 48]. Fertilizer B: [38, 40, 41, 39, 42, 37, 40].

  • Test whether the mean yields differ using the correct two sample t-test. (4 marks)

I’m going to use an independent sample t-test to test for differences between the mean yields of fertilizer because fertilizer A and fertilizer B are independent.

The null hypothesis Ho is that the true mean crop yield is the same for Fertilizer A and Fertilizer B.
- Ho: mu(fertilizer A) = mu(fertilizer B)

The alternative hypothesis Ha is that the true mean crop yields differ between Fertilizer A and Fertilizer B.
- Ha: mu(fertilizer A) does not equal mu(fertilizer B)

To get started, I need to put the data in two numeric vectors and create a dataframe.

FertilizerA <- c(42, 45, 47, 44, 46, 43, 48)
FertilizerB <- c(38, 40, 41, 39, 42, 37, 40)

fertilizerdata <- data.frame(
 group = rep(c("Fertilizer A", "Fertilizer B"), each = 7),
 weight = c(FertilizerA, FertilizerB)
 )

fertilizerdata
##           group weight
## 1  Fertilizer A     42
## 2  Fertilizer A     45
## 3  Fertilizer A     47
## 4  Fertilizer A     44
## 5  Fertilizer A     46
## 6  Fertilizer A     43
## 7  Fertilizer A     48
## 8  Fertilizer B     38
## 9  Fertilizer B     40
## 10 Fertilizer B     41
## 11 Fertilizer B     39
## 12 Fertilizer B     42
## 13 Fertilizer B     37
## 14 Fertilizer B     40

Now, I need to check the independence, normality, and equal variance assumptions of the independent sample t-test.

Independence is plausible because the observations in fertilizer A and fertilizer B are separate from one another and do not influence each other.

I’ll use a Shapiro-Wilk normality test for fertilizer A and B to test the normality assumption.

# fertilizer a
with(fertilizerdata, shapiro.test(weight[group == "Fertilizer A"]))
## 
##  Shapiro-Wilk normality test
## 
## data:  weight[group == "Fertilizer A"]
## W = 0.978, p-value = 0.9493
# fertilizer b
with(fertilizerdata, shapiro.test(weight[group == "Fertilizer B"]))
## 
##  Shapiro-Wilk normality test
## 
## data:  weight[group == "Fertilizer B"]
## W = 0.97962, p-value = 0.9577

The P-values from the Shapiro-Wilk test are both greater than alpha (0.05), so I’ll fail to reject the null hypothesis that the two samples are from a normal distribution, which tells me that the normality assumption is met.

Finally, I’ll test the equal variance assumption using a F-test.

res.ftest <- var.test(weight ~ group, data = fertilizerdata)
res.ftest
## 
##  F test to compare two variances
## 
## data:  weight by group
## F = 1.5806, num df = 6, denom df = 6, p-value = 0.5921
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.2715999 9.1989701
## sample estimates:
## ratio of variances 
##           1.580645

The F-test p-value is above alpha, so I’ll fail to reject the null hypothesis that the variances are equal, which tells me that the equal variance assumption is met.

Now, I can run the independent sample t-test!

res <- t.test(FertilizerA, FertilizerB, var.equal = TRUE)
res
## 
##  Two Sample t-test
## 
## data:  FertilizerA and FertilizerB
## t = 5.2034, df = 12, p-value = 0.0002207
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  3.155457 7.701686
## sample estimates:
## mean of x mean of y 
##  45.00000  39.57143

This output shows a p-value of less than 0.05, therefore I reject the null hypothesis that the mean yields of the two fertilizer groups are equal. There is sufficient evidence to suggest that the mean crop yield differs between Fertilizer A and Fertilizer B.

Question 4.

A fitness program measures resting heart rate before and after training: Before [72, 75, 70, 78, 74, 73, 76], After [68, 72, 67, 74, 70, 69, 73].

  • Test whether the program reduces heart rate using a paired t-test. (4 marks)

We’re using a paired-sample t-test for this question because the data is paired before and after data that is not independent.

The null hypothesis Ho is that the true reduction in heart rate is zero.
- Ho: mu (before - after) = 0

The alternative hypothesis Ha is that the true reduction in heart rate is greater than zero.
- Ha: mu (before - after) > 0

To get started, I need to put my data in a dataframe.

before <-c(72, 75, 70, 78, 74, 73, 76)
after <-c(68, 72, 67, 74, 70, 69, 73)
heartrate <- data.frame(
group = rep(c("before", "after"), each = 7),
weight = c(before, after)
)
print(heartrate)
##     group weight
## 1  before     72
## 2  before     75
## 3  before     70
## 4  before     78
## 5  before     74
## 6  before     73
## 7  before     76
## 8   after     68
## 9   after     72
## 10  after     67
## 11  after     74
## 12  after     70
## 13  after     69
## 14  after     73

Now, I need to test the paired observations, independence, and normality of the difference assumptions.

The paired observations assumption is met because each “before” measurement is paired with the corresponding “after” measurement from the same participant.

Additionally, the independence assumption is met because each participant’s heart rate measurements do not influence any other participant’s measurements.

Finally, to test the normality of the difference assumption, I’m going to run a Shapiro-Wilk test.

d <- with(heartrate,
 weight[group == "before"] - weight[group == "after"])
# Shapiro-Wilk normality test for the differences
shapiro.test(d) 
## 
##  Shapiro-Wilk normality test
## 
## data:  d
## W = 0.66444, p-value = 0.001497

The p-value from the Shapiro-Wilk test is significant (p = 0.001497), indicating that the differences are not normally distributed. This means that the normality of the differences assumption for the paired t-test is not met. Because of this, I’m going to use the Wilcoxon signed-rank test as an alternative because it does not require this assumption.

wilcox.test(before, after, paired = TRUE, alternative = "greater")
## Warning in wilcox.test.default(before, after, paired = TRUE, alternative =
## "greater"): cannot compute exact p-value with ties
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  before and after
## V = 28, p-value = 0.009611
## alternative hypothesis: true location shift is greater than 0

The output from the Wilcoxon signed-rank test shows a p-value less than alpha (0.05), indicating that I should reject the null hypothesis and conclude that there is significant evidence to indicate that the true reduction in heart rate is greater than zero.

Question 5.

A smoothie shop wants to know if preferences for four flavors are equal. Observed counts: Strawberry 32, Mango 28, Berry 25, Green 15.

  • Perform a Chi-square goodness-of-fit test. (4 marks)

We’re using a chi-square goodness of fit test to compare the observed distribution of smoothie flavor counts to the expected distribution, and we have discrete data with two or more categories.

The null hypothesis Ho is that there is no significant difference between the observed and expected value of smoothie flavor counts
- Ho: p(strawberry) = p(mango) = p(berry) = p(green) = 1/4

The alternative hypothesis Ha is that smoothie preferences are not equal across flavors.
- Ha: at least one p does not equal 1/4

The chi-square goodness-of-fit test assumes that observations are independent, the data are categorical, and all expected counts are at least 5. All of these assumptions are met in this problem.

Now, I’ll perform the chi-square goodness of fit test.

flavors <- c(32,28,25, 15)
res <- chisq.test(flavors, p = c(1/4, 1/4, 1/4, 1/4))
res
## 
##  Chi-squared test for given probabilities
## 
## data:  flavors
## X-squared = 6.32, df = 3, p-value = 0.09704

The chi-square goodness-of-fit test produced a p-value greater than 0.05, so I fail to reject the null hypothesis. I’ll conclude that there is no significant evidence that preferences for the four smoothie flavors differ from equal proportions.

Question 6.

A company studies whether customer satisfaction level (Low, Medium, High) is independent of store type (Online, In-store). Data: Online [22, 35, 18], In-store [28, 30, 17].

  • Conduct a Chi-square test of independence. (4 marks)

We’re using a chi-square test of independence to see if customer satisfaction (low, medium, high) depends on store type (online vs. in-store). Since we have counts for each combination of categories, this test is appropriate for checking whether the two variables are related.

The null hypothesis Ho is that customer satisfaction level is independent of store type.
- Ho: the distribution of low, medium, and high satisfaction is the same for online and in-store stores.

The alternative hypothesis Ha is that customer satisfaction level is not independent of store type.
- Ha: the distribution of satisfaction differs between online and in-store stores.

The chi-square test of independence assumes that observations are independent, the data are categorical, and all expected counts are at least 5. All of these assumptions are met in this problem.

Now, I’ll create a contingency table and perform the chi-square test of independence.

Contintable <- matrix(c(22, 35, 18, 28, 30, 17), ncol = 2, byrow = FALSE)
colnames(Contintable) <- c("Online", "In-store")
rownames(Contintable) <- c("Low", "Medium", "High")

Contintable
##        Online In-store
## Low        22       28
## Medium     35       30
## High       18       17
res <- chisq.test(Contintable)
res
## 
##  Pearson's Chi-squared test
## 
## data:  Contintable
## X-squared = 1.1332, df = 2, p-value = 0.5675

The chi-square test of independence produced a p-value greater than 0.05, so I fail to reject the null hypothesis. I’ll conclude that there is no significant evidence that customer satisfaction level differs by store type. Satisfaction appears to be independent of whether the store is Online or In-store.

End of Problem Set