We can have R do all this math for us using t.test()
formula: in the format outcome ~ group
data: tibble containing outcome and group
var.equal: TRUE (Student’s) or FALSE (Welch’s)
Student’s test results
fit_s <-t.test(formula = eval ~ track,data = tratings,var.equal =TRUE)library(easystats)model_parameters(fit_s)## Two Sample t-test## ## Parameter | Group | track = 1 | track = 2 | Difference | 95% CI | t(92) | p## ---------------------------------------------------------------------------------------## eval | track | 3.87 | 4.12 | -0.25 | [-0.51, 0.00] | -1.99 | 0.049## ## Alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
1
Be sure to set var.equal=TRUE to use Student’s approach
“A Student’s independent samples t-test found that tenure-track professors’ average eval (M=3.87) was significantly lower than non-tenure-track professors’ average eval (M=4.12), t(92)=–1.99, p=.049. The difference was estimated to be –0.25, 95% CI: [–0.51, 0.00].”
Welch’s approach in R
fit_w <-t.test(formula = eval ~ track,data = tratings,var.equal =FALSE)model_parameters(fit_w)## Welch Two Sample t-test## ## Parameter | Group | track = 1 | track = 2 | Difference | 95% CI## -----------------------------------------------------------------------## eval | track | 3.87 | 4.12 | -0.25 | [-0.50, -0.01]## ## Parameter | t(21.62) | p## ----------------------------## eval | -2.19 | 0.040## ## Alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
1
Be sure to set var.equal=FALSE to use Welch’s approach
“A Welch’s independent samples t-test found that tenure-track professors’ average eval (M=3.87) was significantly lower than non-tenure-track professors’ average eval (M=4.12), t(21.62)=–2.19, p=.040. The difference was estimated to be –0.25, 95% CI: [–0.50, –0.01].”
Paired groups
Sometimes observations in our groups are related
Obs. X in G1 is related somehow to obs. X in G2
e.g., repeated measures of the same person or thing
If we ignore these relationships in our modeling…
Our SE estimates will tend to be too low
Therefore, our \(p\)-values and CIs will be incorrect
Paired samples \(t\)-test
To fix this, we can calculate the paired differences
\[\Delta_i = x_{1i} - x_{2i}\]
Then we do a one-sample \(t\)-test on the differences
This effect size measure is often referred to as Cohen’s \(d\)
Other options include Hedge’s \(g\) and Glass’ \(\Delta\)
Unstandardized difference
model_parameters(fit_s)## Two Sample t-test## ## Parameter | Group | track = 1 | track = 2 | Difference | 95% CI | t(92) | p## ---------------------------------------------------------------------------------------## eval | track | 3.87 | 4.12 | -0.25 | [-0.51, 0.00] | -1.99 | 0.049## ## Alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
Tenure track professors’ average teaching evaluations were 0.25 units lower (on a scale from 1 to 5) than were non-tenure track professors’, 95% CI: [–0.51, 0.00].
Cohen’s \(d\)
cohens_d(eval ~ track, data = tratings)## Cohen's d | 95% CI## --------------------------## -0.56 | [-1.12, 0.00]## ## - Estimated using pooled SD.
Tenure track professors’ average teaching evaluations were 0.56 standard deviations lower than were non-tenure track professors’, 95% CI: [–1.12, 0.00].
Dependent samples
When comparing the means of dependent/paired samples…
We use the SD of the paired differences in the denominator
\[ES = \frac{\bar{x}_1 - \bar{x}_2}{s_{\Delta}}\]
This is often referred to as a paired Cohen’s \(d\)
Example
model_parameters(fit_p)## Paired t-test## ## Parameter | Difference | t(33) | p | 95% CI## -----------------------------------------------------------------------## Pair(endpoint, baseline) | -0.42 | -3.86 | < .001 | [-0.64, -0.20]## ## Alternative hypothesis: true mean difference is not equal to 0cohens_d(Pair(endpoint, baseline) ~1, data = social)## Cohen's d | 95% CI## --------------------------## -0.66 | [-1.03, -0.29]
Patients’ social problems were 0.42 units (or 0.66 standard deviations) lower at the endpoint compared to baseline.