# long-format data: one row per participant per time point
df <- data.frame(
id = factor(
x = c(1, 1, 2, 2, 3, 3, 4, 4),
labels = c("alice", "bob", "chris", "diana")
),
time = factor(
x = c(1, 2, 1, 2, 1, 2, 1, 2),
labels = c("time1", "time2")
),
wm = c(3, 4, 6, 6, 9, 12, 7, 9)
)
# wide-format data: one row per participant
df2 <- longToWide(df, wm ~ time)
# three equivalent ways to run the same test
pairedSamplesTTest(formula = wm ~ time, data = df, id = "id")
pairedSamplesTTest(formula = wm ~ time + (id), data = df)
pairedSamplesTTest(formula = ~ wm_time1 + wm_time2, data = df2)
# one-sided test: is time2 larger than time1?
pairedSamplesTTest(formula = wm ~ time, data = df, id = "id", one.sided = "time2")
# missing value: that participant is removed with a warning
df$wm[1] <- NA
pairedSamplesTTest(formula = wm ~ time, data = df, id = "id")
# missing row: that participant is also removed with a warning
df <- df[-1, ]
pairedSamplesTTest(formula = wm ~ time, data = df, id = "id")
Run the code above in your browser using DataLab