New to posting to Stack so apologies for any issues.
I'm learning to get more comfortable in R and currently looking at using broom/purr to run multiple stat tests at one time. An example of my current data looks like this:
Subject | PreScoreTestA | PostScoreTestA | PreScoreTestB | PostScoreTestB | PreScoreTestC | PostScoreTestC |
---|---|---|---|---|---|---|
1 | 30 | 40 | 6 | 8 | 12 | 10 |
2 | 15 | 12 | 9 | 13 | 7 | 7 |
3 | 20 | 22 | 11 | 12 | 9 | 10 |
But over many subjects and more tests. I want to do a dependent t-test to see scores changed over the course of a training program, but don't want to run a test for each score.
I've seen a couple examples of people using group by, nest, and map to run multiple t-tests, but their data was in a longer format
Is there a way to achieve the same goal while in a wide format? Or will I need to use pivot_longer to change the data.
Thanks in advance!
ETA had an edit here but was giving incorrect results and so have removed Still looking for some help on the arguments and same length
ETA Version 2
I did find a workaround using pairwise.t.test (code below). It gives the same p-values as doing t.test across individual assessments. I'm curious why it'd be working for pairwise.t.test but not t.test. Please let me know if anyone was any ideas!
results <- testb %>%
pivot_longer(-Subject,
names_to = c("time", "test"), values_to = "score",
names_pattern = "(Pre|Post)(.*)") %>%
group_by(test) %>%
nest() %>%
mutate(ttests = map(.x=data, ~tidy(pairwise.t.test(.x$score, .x$time, paired = TRUE, p.adjust.method = "none")))) %>%
unnest(ttests)