Rename this template, fill out the author and date lines, and knit it once before you start. Submit both the knitted file and the .Rmd on Canvas. Use α = .05 and two-tailed tests unless a question says otherwise.

I tested the knitting, and this knits fine.

1) [2 pts] Review and choosing the right t-test

1a. [0.5 pts] A population has a mean of μ = 100. A sample of n = 9 has a mean of 106 and a standard deviation of s = 12. Compute the t statistic and the df.

Calculating t and df

# 1a: Calculate the test statistic and degrees of freedom
t <- (106 - 100) / (12 / sqrt(9))
df <- 9 - 1

t
## [1] 1.5
df
## [1] 8

The test statistic is 1.5 and the degrees of freedom is 8.

1b. [0.5 pts] Use qt() to find the critical t for the test in 1a (two-tailed, α = .05). Reject or fail to reject H0?

Critical value and my decision based on it:

t_crit <- qt(0.975, df = 8)
t_crit
## [1] 2.306004
abs(t) > t_crit
## [1] FALSE

Your answer:

Based on this, we fail to reject H0, because the absolute t statistic is smaller than the critical t value.

1c. [1 pt] For each study, say whether you would use a one-sample, independent samples, or paired samples t-test, and why.

    1. The same 30 participants complete a reaction-time task with and without caffeine.
    1. Exam scores are compared between students in two different sections of a course.
    1. A researcher tests whether GT students sleep a different amount than the national average of 7 hours.

Your answer: ## (i) I would use a paired samples t-test for this, because the same participants are completing both conditions. ## (ii) I would use an independent samples t-test, because two separate groups of students are being compared. ## (iii) I would use a one-sample t-test, because the sample mean is compared to a known population mean of 7 hours.

2) [3 pts] Independent samples t-test (ToothGrowth)

The built-in ToothGrowth data has tooth length (len) for 60 guinea pigs that got vitamin C either as orange juice (supp = “OJ”) or as ascorbic acid (supp = “VC”), 30 in each group. Does tooth length differ between the two supplements?

2a. [0.75 pts] Split len into two vectors, one for OJ and one for VC. Compute each group’s mean, SD, and n.

Finding the group statistics:

OJ <- ToothGrowth$len[ToothGrowth$supp == "OJ"]
VC <- ToothGrowth$len[ToothGrowth$supp == "VC"]

mean(OJ)
## [1] 20.66333
sd(OJ)
## [1] 6.605561
length(OJ)
## [1] 30
mean(VC)
## [1] 16.96333
sd(VC)
## [1] 8.266029
length(VC)
## [1] 30

The mean, standard deviation, and length for OJ are 20.66333, 6.605561, and 30, respectively. For VC, they are 16.96333, 8.266029, and 30, respectively.

2b. [0.75 pts] By hand in R, compute the pooled SD, the t statistic (OJ − VC), and the df.

Pooled SD, t statistic, and df

n1 <- length(OJ)
n2 <- length(VC)

s1 <- sd(OJ)
s2 <- sd(VC)

sp <- sqrt(((n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2))

t <- (mean(OJ) - mean(VC)) / (sp * sqrt(1/n1 + 1/n2))

df <- n1 + n2 - 2

sp
## [1] 7.482001
t
## [1] 1.915268
df
## [1] 58

The resulting sp is 7.482001, t is 1.915268, and df is 58.

2c. [0.75 pts] Use qt() to find the critical t. Reject or fail to reject H0? State your conclusion in words.

Critical value and conclusion:

t_crit <- qt(0.975, df = df)

t_crit
## [1] 2.001717
abs(t) > t_crit
## [1] FALSE

Your answer: ## The critical t is 2.001717. We fail to reject H0, because there is a statistically significant difference in tooth length between the orange juice and ascorbic acid groups. t = 1.915 is smaller than the critical value (approximately 2.002), and p = .061 is greater than .05. The orange juice group has a higher mean tooth length.

2d. [0.75 pts] Check your work with t.test(len ~ supp, data = ToothGrowth, var.equal = TRUE). Report t, df, and the p-value. Does the 95% CI include 0? Is that consistent with your decision in 2c?

Verify with t.test()

t.test(len ~ supp, data = ToothGrowth, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  len by supp
## t = 1.9153, df = 58, p-value = 0.06039
## alternative hypothesis: true difference in means between group OJ and group VC is not equal to 0
## 95 percent confidence interval:
##  -0.1670064  7.5670064
## sample estimates:
## mean in group OJ mean in group VC 
##         20.66333         16.96333

Your answer: ## The independent samples t-test results in approximately t=1/915, df=58, and p=0.0604, with no statistically significant difference in tooth length between the orange juice and ascorbic acid groups. The 95% confidence interval includes 0, and this is consistent with failing to reject the H0.

3) [3 pts] Paired samples t-test (mindfulness and stress)

Twelve students rated their stress (0–40) before and after a 4-week mindfulness program. Run the chunk below to create the data.

stress <- data.frame(
  before = c(14, 16, 16, 22, 10, 23, 18, 29, 30, 32, 29, 24),
  after  = c( 8,  8, 15, 17,  7, 16, 18, 27, 26, 28, 31, 20)
)

3a. [0.75 pts] Why is a paired samples t-test the right choice here? State H0 and H1.

Stating hypotheses:

Your answer: ## A paired samples t-test is the right choice here, because the same 12 students were measured before and after the mindfulness program. The observations are dependent.

H0: The population mean difference in stress scores is 0.

H1: The population mean difference in stress scores is not 0.

3b. [0.75 pts] Create a difference column (after − before). By hand in R, compute the mean difference, the SD of the differences, the t statistic, and the df.

Calculating difference scores:

stress$diff <- stress$after - stress$before

mean_diff <- mean(stress$diff)
sd_diff <- sd(stress$diff)
n <- length(stress$diff)

t <- mean_diff / (sd_diff / sqrt(n))
df <- n - 1

mean_diff
## [1] -3.5
sd_diff
## [1] 2.90767
t
## [1] -4.169784
df
## [1] 11

The resulting mean difference is -3.5, the resulting SD of the differences is 2.90767, the t statistic is -4.169784, and the df is 11.

3c. [0.75 pts] Run t.test() with paired = TRUE. Report t, df, and the p-value, and state your conclusion in words.

running paired samples t-test:

t.test(stress$after, stress$before, paired = TRUE)
## 
##  Paired t-test
## 
## data:  stress$after and stress$before
## t = -4.1698, df = 11, p-value = 0.001563
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -5.347445 -1.652555
## sample estimates:
## mean difference 
##            -3.5

Your answer: ## The test results in t = -4.170, df = 11, and p=0.00156. We reject H0. There is a statistically significant difference in stress scores before and after the mindfulness program. The stress scores decreased after the program.

3d. [0.75 pts] Now run t.test() on the difference column with mu = 0. Compare the result to 3c. Why do they match?

Testing the difference scores

t.test(stress$diff, mu = 0)
## 
##  One Sample t-test
## 
## data:  stress$diff
## t = -4.1698, df = 11, p-value = 0.001563
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -5.347445 -1.652555
## sample estimates:
## mean of x 
##      -3.5

Your answer: ## The results are identical to those in 3c because a paired samples t-test calculates the differences between each participant’s two scores and tests whether the mean difference is significantly different from 0.

4) [2 pts] Effect size and write-up

4a. [0.5 pts] Compute Cohen’s d for Question 2 (use the pooled SD) and for Question 3 (use the SD of the differences). Label each as small, medium, or large.

Calculating Cohen’s d for both tests:

d2 <- (mean(OJ) - mean(VC)) / sp
d3 <- mean(stress$diff) / sd(stress$diff)

d2
## [1] 0.4945201
d3
## [1] -1.203713

Your answer: ## The Cohen’s d for the first test is 0.4945201 (a medium effect) and the Cohen’s d for the second test is -1.203713 (a large effect).

4b. [1 pt] Write one results sentence for Question 2 and one for Question 3, including t(df), p, and d.

Your answer: ## Question 2: An independent samples t-test resulted in no statistically significant difference in tooth length between the orange juice and ascorbic acid groups, t(58) = 1.92, p = 0.061, d = 0.50.

Question 3: A paired samples t-test resulted in a statistically significant decrease in stress scores following the mindfulness program, t(11) = -4.17, p = 0.002, and d=-1.20.

4c. [0.5 pts] Suppose someone wrongly ran an independent samples t-test on the stress data: t.test(stress\(after, stress\)before, var.equal = TRUE). Run it and compare its p-value to your paired test. Why does the paired test find the effect when this one does not?

comparing independent and paired tests:

t.test(stress$after, stress$before, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  stress$after and stress$before
## t = -1.1094, df = 22, p-value = 0.2792
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.042826   3.042826
## sample estimates:
## mean of x mean of y 
##  18.41667  21.91667

Your answer: ## The independent samples t-test results are t= -1.109, df = 22, p = 0.279. Unlike the paired samples test, this result is NOT statistically significant. The paired test takes into account the relationship between each participant’s before/after scores. This reduces variability and makes it eaiser to identify the change in stress.