wlb_data |>
head()# A tibble: 6 × 2
worker_id wlb
<chr> <dbl>
1 worker1 27
2 worker2 37
3 worker3 25
4 worker4 54
5 worker5 39
6 worker6 25
RQ: For remote workers, is their average score on the Work-Life Balance (WLB) Scale below the scale’s midpoint of 45, indicating reasonable work–life balance?
Here’s what the first six rows of the data looks like:
wlb_data |>
head()# A tibble: 6 × 2
worker_id wlb
<chr> <dbl>
1 worker1 27
2 worker2 37
3 worker3 25
4 worker4 54
5 worker5 39
6 worker6 25
Work–Life Balance (wlb) scores can range between 15 and 75. Higher scores represent greater conflict between work commitments and life commitments, so good work–life balance is reflected in lower scores.
Here’s how we might plot this data (you’ll see more plotting options in Block 3):
wlb_data |>
ggplot(aes(x = wlb)) +
geom_boxplot() +
labs(
x = 'Work-life balance score'
)
Add in a couple extra lines of code, where in the theme() of the plot, we say “set the axis text on the y axis equal to a blank element”, and the same for the “axis ticks on the y axis” (the little horizontal lines).
wlb_data |>
ggplot(aes(x = wlb)) +
geom_boxplot() +
labs(
x = 'Work-life balance score'
) +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
We want to know whether remote workers’ work–life balance score is below the scale’s midpoint of 45, on average.
Thus our null hypothesis \(H_0\) is that the true average work–life balance score \(\mu\) (Greek letter mu, pronounced “mew”) is equal to 45, or formally
\[ H_0: \mu = 45 \]
And based on our RQ, we know that our alternative hypothesis \(H_1\) is that the average work–life balance score \(\mu\) is lower than 45, or formally
\[ H_1: \mu < 45 \]
To write this in plain text in your R script, you can write:
# H0: mu = 45
# H1: mu < 45The useful symbols for your alternative hypothesis are < (less than), > (greater than), and != (not equal to).
Use the function t.test(), and give it four pieces of information:
mu = the mean value we want to test againstalternative = two.sided, less, or greater; the direction of the \(H_1\)conf.level = 1 minus our \(\alpha\) level; in Psychology, this will nearly always be .95.t.test(
wlb_data$wlb,
mu = 45,
alternative = 'less',
conf.level = .95
)
One Sample t-test
data: wlb_data$wlb
t = -7, df = 76, p-value = 4e-10
alternative hypothesis: true mean is less than 45
95 percent confidence interval:
-Inf 39.1
sample estimates:
mean of x
37.2
To find out whether remote workers experience work–life balance that’s better (that is, lower) than the midpoint of the Work–Life Balance Scale, we ran a one-sided t-test against the null hypothesis that remote workers’ Work–Life Balance score is, on average, equal to 45. We were able to reject this H0; remote workers have a significantly lower Work–Life Balance score of 37.2 on average (\(t\)(76) = –7, \(p\) < .001, one-sided).
| Type of constraint | What to check for a one-sample t-test |
|---|---|
| Data requirements | The variable is numeric. |
| Assumption of independence | The obtained sample data are a random sample from the population of interest. |
| Assumption of normality | The sampling distribution of sample means is normally distributed. |
The variable we’re analysing should be interval, ratio, or integer data (that is, numeric).
The wlb variable is indeed numeric (specifically, it’s integer data!):
wlb_data$wlb [1] 27 37 25 54 39 25 41 44 42 31 53 40 28 48 34 35 46 45 42 46 44 36 42 34 33
[26] 17 29 40 51 34 40 34 18 30 30 34 48 44 33 32 43 42 27 27 39 44 34 46 40 28
[51] 39 21 52 59 31 22 42 33 64 35 43 35 26 37 53 37 61 41 26 42 24 20 38 30 35
[76] 36 28
The obtained sample data should be a random sample from the population of interest.
This is an issue of study design more than something we can check directly.
But we can at least check that each person contributed only one data point:
wlb_data |> head()# A tibble: 6 × 2
worker_id wlb
<chr> <dbl>
1 worker1 27
2 worker2 37
3 worker3 25
4 worker4 54
5 worker5 39
6 worker6 25
Yes, looks good!
The sampling distribution of sample means is normally distributed.
We can’t check this directly, because we don’t know the population. But we can check the normality of our given sample. If it matches a normal distribution pretty well, then so will the sampling distribution of sample means.
We can check normality with a Q-Q plot.
The closer the points are to the diagonal line, the better the variable matches an ideal normal distribution.
wlb_data |>
ggplot(aes(sample = wlb)) + # notice it's "sample", not "x"!
geom_qq() +
geom_qq_line() +
labs(
x = "Theoretical quantiles",
y = 'Sample quantiles'
)
The match to the diagonal is pretty good here! I’d be willing to assume sufficient normality.
If you’ve got a Q-Q plot you’re unsure about, compare it to the example plots in the green box below.
All of the Q-Q plots below show data that is sampled from different normal distributions. So all the plots below should be considered normal “enough”.
library(patchwork)
sim_normal <- function(){
# randomly sample from a uniform distribution some parameter values
n_obs <- round(runif(1, min = 10, max = 40))
mean <- runif(1, min = -10, max = 10)
sd <- abs(mean * round(runif(1, min = 1, max = 10)))
# ^ multiply SD by mean to get variability of the right magnitude
# simulate the data
df <- tibble(
x = rnorm(n_obs, mean = mean, sd = sd)
)
return(list(df)) # return as list so we end up with a list of dfs
}
make_qq <- function(dat){
# dat must contain continuous variable x
dat |>
ggplot(aes(sample = x)) +
geom_qq() +
geom_qq_line() +
labs(
x = "Theoretical quantiles",
y = 'Sample quantiles'
)
}
set.seed(1) # so your random numbers are the same as my random numbers
# generate set number of normally distributed datasets
dfs <- replicate(12, sim_normal())
# use patchwork's wrap_plots() to combine each dataset's qq plot into a single graphic
wrap_plots( sapply(dfs, make_qq) ) +
plot_layout(axes = "collect") # use only one axis label
(You don’t need to understand the code that created this graphic unless you want to.)
For t-tests, the appropriate measure of standardised effect size is Cohen’s D.
To compute this in R, first attach the effectsize package:
library(effectsize)This package gives us the function cohens_d(). Give it the exact same arguments you’d give t.test() (see summary above):
cohens_d(
wlb_data$wlb,
mu = 45,
alternative = 'less',
conf.level = .95
)Cohen's d | 95% CI
-------------------------
-0.80 | [-Inf, -0.58]
- Deviation from a difference of 45.
- One-sided CIs: lower bound fixed at [-Inf].
To find out whether remote workers experience work–life balance that’s better (that is, lower) than the midpoint of the Work–Life Balance Scale, we ran a one-sided t-test against the null hypothesis that remote workers’ Work–Life Balance score is, on average, equal to 45.
This test requires that the dependent variable be numeric, and since Work–Life Balance scores are integer values, we are satisfied that this requirement is met. This test also assumes independence: more specifically, that the sample data are sampled independently and at random from the population of interest. Based on the study design, we are willing to assume independence. Finally, the test assumes normality, specifically that the sampling distribution of sample means follows a normal distribution. If the sample itself follows a normal distribution, then it’s likely that the population and thus the sampling distribution of sample means will as well, so we check the normality of our sample. Based on a Q-Q plot, in which the observations show a good match to an ideal normal distribution, we are willing to assume normality.
Let us now address our research question. We were able to reject the H0 that remote workers’ Work–Life Balance score is equal to the scale midpoint of 45. We found that remote workers have a significantly lower Work–Life Balance score of 37.2 on average (\(t\)(76) = –7, \(p\) < .001, one-sided). With a Cohen’s D of –0.80, this difference represents a large effect.
The most important thing: Your decision about the null hypothesis should be clear.
You can make sure your decision is clear either by