set up
load packages
library(googlesheets4)
library(janitor)
library(tidyverse)
library(patchwork)
library(ggeasy)
library(jmv)read data from google sheets
group1 <- read_sheet("https://docs.google.com/spreadsheets/d/1ogQxc3UCprTsAy2FOpNZ49Bls9a36Zn5hFgJcvVbB2k/edit#gid=960922745")
group2 <- read_sheet("https://docs.google.com/spreadsheets/d/17E7vFbpD4KI2fW6tN_VOu0Sy2FWNb6d0BqJkkK4DGXk/edit")data wrangling
clean
clean names, add variables for group, year, pID, move new variables to the front of the df.
group1 <- group1 %>%
clean_names() %>%
mutate(group = "group1", year = "2021") %>%
mutate(p_ID = paste0("p", "1g", row_number())) %>%
relocate(group, .after = timestamp) %>%
relocate(p_ID, .before = group) %>%
relocate(year, .after = group)
group2 <- group2 %>%
clean_names() %>%
mutate(group = "group2", year = "2021") %>%
mutate(p_ID = paste0("p", "2g", row_number())) %>%
relocate(group, .after = timestamp) %>%
relocate(p_ID, .before = group) %>%
relocate(year, .after = group) bind group 1 & 2
join group 1 and group 2 data together
all <- rbind(group1, group2)make long
separate df for each domain, rename task variables and make long
fine
fine <- all %>%
select(1:3, contains("draw"))
fine <- fine %>%
rename(BabyA_triangle = baby_a_draw_a_triangle, BabyA_circle = baby_a_draw_a_circle,
BabyB_triangle = baby_b_draw_a_triangle, BabyB_circle = baby_b_draw_a_circle)
fine_long <- fine %>%
pivot_longer(names_to = c("infant", "task"), values_to = "rating", names_sep = "_", 4:7) %>%
mutate(condition = "fine")gross
gross <- all %>%
select(1:3, contains("walking"))
gross <- gross %>%
rename(BabyA_up = baby_a_walking_up_stairs, BabyA_down = baby_a_walking_down_stairs,
BabyB_up = baby_b_walking_up_stairs, BabyB_down = baby_b_walking_down_stairs)
gross_long <- gross %>%
pivot_longer(names_to = c("infant", "task"), values_to = "rating", names_sep = "_", 4:7) %>%
mutate(condition = "gross")play
play <- all %>%
select(1:3, contains("book"), contains("blocks"), contains("puzzle"))
play <- play %>%
rename(BabyA_book = baby_a_turning_the_pages_of_a_book,
BabyA_blocks1 = baby_a_putting_together_duplo_blocks,
BabyA_blocks2 = baby_a_pulling_apart_duplo_blocks,
BabyA_puzzle = baby_a_putting_together_a_puzzle,
BabyB_book = baby_b_turning_the_pages_of_a_book,
BabyB_blocks1 = baby_b_putting_together_duplo_blocks,
BabyB_blocks2 = baby_b_pulling_apart_duplo_blocks,
BabyB_puzzle = baby_b_putting_together_a_puzzle)
play_long <- play %>%
pivot_longer(names_to = c("infant", "task"), values_to = "rating", names_sep = "_", 4:11) %>%
mutate(condition = "play")self
self <- all %>%
select(1:3, contains("shoes"), contains("zipping"))
self <- self %>%
rename(BabyA_shoes = baby_a_taking_shoes_off,
BabyA_zip = baby_a_zipping_a_bag,
BabyB_shoes = baby_b_taking_shoes_off,
BabyB_zip = baby_b_zipping_a_bag)
self_long <- self %>%
pivot_longer(names_to = c("infant", "task"), values_to = "rating", names_sep = "_", 4:7) %>%
mutate(condition = "self")bind domains
bind all domains back together
all_long <- rbind(fine_long, gross_long, play_long, self_long)
glimpse(all_long)## Rows: 7,160
## Columns: 7
## $ timestamp <dttm> 2021-02-21 14:32:04, 2021-02-21 14:32:04, 2021-02-21 14:32…
## $ p_ID <chr> "p1g1", "p1g1", "p1g1", "p1g1", "p1g2", "p1g2", "p1g2", "p1…
## $ group <chr> "group1", "group1", "group1", "group1", "group1", "group1",…
## $ infant <chr> "BabyA", "BabyB", "BabyA", "BabyB", "BabyA", "BabyB", "Baby…
## $ task <chr> "triangle", "triangle", "circle", "circle", "triangle", "tr…
## $ rating <dbl> 3, 1, 3, 3, 4, 1, 4, 3, 3, 2, 4, 3, 3, 1, 4, 4, 2, 1, 2, 3,…
## $ condition <chr> "fine", "fine", "fine", "fine", "fine", "fine", "fine", "fi…
plots and stats
fine plots
fine_plot <- all_long %>%
filter(condition == "fine") %>%
group_by(group,infant) %>%
summarise(meanrating = mean(rating, na.rm = TRUE)) %>%
ggplot(aes(x = group, y = meanrating, fill = group)) +
geom_col() +
facet_wrap(~infant) +
labs(subtitle = "Group 1: Baby A preterm, Baby B full term \n Group 2: Baby A full term, Baby B pre term", title = "fine motor", caption = "Group1 N = 173; Group2 N = 185") +
easy_remove_legend()## `summarise()` has grouped output by 'group'. You can override using the `.groups` argument.
fine_plotfine stats
fineBabyA <- fine_long %>%
filter(infant == "BabyA")
fineBabyB <- fine_long %>%
filter(infant == "BabyB")
# do the ratings of group 1 and 2 differ for BabyA
ttestIS(formula = rating ~ group, data = fineBabyA)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ───────────────────────────────────────────────────────────────
## Statistic df p
## ───────────────────────────────────────────────────────────────
## rating Student's t -4.958742 702.0000 0.0000009
## ───────────────────────────────────────────────────────────────
# do the ratings of group 1 and 2 differ for BabyB
ttestIS(formula = rating ~ group, data = fineBabyB)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ─────────────────────────────────────────────────────────────────
## Statistic df p
## ─────────────────────────────────────────────────────────────────
## rating Student's t 0.5671496 ᵃ 700.0000 0.5707944
## ─────────────────────────────────────────────────────────────────
## ᵃ Levene's test is significant (p < .05), suggesting a
## violation of the assumption of equal variances
gross plots
gross_plot <- all_long %>%
filter(condition == "gross") %>%
group_by(group,infant) %>%
summarise(meanrating = mean(rating, na.rm = TRUE)) %>%
ggplot(aes(x = group, y = meanrating, fill = group)) +
geom_col() +
facet_wrap(~infant) +
labs(subtitle = "Group 1: Baby A preterm, Baby B full term \n Group 2: Baby A full term, Baby B pre term", title = "gross motor", caption = "Group1 N = 173; Group2 N = 185") +
easy_remove_legend()## `summarise()` has grouped output by 'group'. You can override using the `.groups` argument.
gross_plotgross stats
grossBabyA <- gross_long %>%
filter(infant == "BabyA")
grossBabyB <- gross_long %>%
filter(infant == "BabyB")
# do the ratings of group 1 and 2 differ for BabyA
ttestIS(formula = rating ~ group, data = grossBabyA)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ──────────────────────────────────────────────────────────────────
## Statistic df p
## ──────────────────────────────────────────────────────────────────
## rating Student's t -5.443021 ᵃ 704.0000 < .0000001
## ──────────────────────────────────────────────────────────────────
## ᵃ Levene's test is significant (p < .05), suggesting a
## violation of the assumption of equal variances
# do the ratings of group 1 and 2 differ for BabyB
ttestIS(formula = rating ~ group, data = grossBabyB)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t 1.788977 ᵃ 704.0000 0.0740484
## ────────────────────────────────────────────────────────────────
## ᵃ Levene's test is significant (p < .05), suggesting a
## violation of the assumption of equal variances
play plots
play_plot <- all_long %>%
filter(condition == "play") %>%
group_by(group,infant) %>%
summarise(meanrating = mean(rating, na.rm = TRUE)) %>%
ggplot(aes(x = group, y = meanrating, fill = group)) +
geom_col() +
facet_wrap(~infant) +
labs(subtitle = "Group 1: Baby A preterm, Baby B full term \n Group 2: Baby A full term, Baby B pre term", title = "play", caption = "Group1 N = 173; Group2 N = 185") +
easy_remove_legend()## `summarise()` has grouped output by 'group'. You can override using the `.groups` argument.
play_plotplay stats
playBabyA <- play_long %>%
filter(infant == "BabyA")
playBabyB <- play_long %>%
filter(infant == "BabyB")
# do the ratings of group 1 and 2 differ for BabyA
ttestIS(formula = rating ~ group, data = playBabyA)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t -11.25441 1406.000 < .0000001
## ────────────────────────────────────────────────────────────────
# do the ratings of group 1 and 2 differ for BabyB
ttestIS(formula = rating ~ group, data = playBabyB)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t 2.945735 ᵃ 1404.000 0.0032750
## ────────────────────────────────────────────────────────────────
## ᵃ Levene's test is significant (p < .05), suggesting a
## violation of the assumption of equal variances
self plots
self_plot <- all_long %>%
filter(condition == "self") %>%
group_by(group,infant) %>%
summarise(meanrating = mean(rating, na.rm = TRUE)) %>%
ggplot(aes(x = group, y = meanrating, fill = group)) +
geom_col() +
facet_wrap(~infant) +
labs(subtitle = "Group 1: Baby A preterm, Baby B full term \n Group 2: Baby A full term, Baby B pre term", title = "self help", caption = "Group1 N = 173; Group2 N = 185") +
easy_remove_legend()## `summarise()` has grouped output by 'group'. You can override using the `.groups` argument.
self_plotself stats
selfBabyA <- self_long %>%
filter(infant == "BabyA")
selfBabyB <- self_long %>%
filter(infant == "BabyB")
# do the ratings of group 1 and 2 differ for BabyA
ttestIS(formula = rating ~ group, data = selfBabyA)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t -7.368628 704.0000 < .0000001
## ────────────────────────────────────────────────────────────────
# do the ratings of group 1 and 2 differ for BabyB
ttestIS(formula = rating ~ group, data = selfBabyB)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t 1.892721 ᵃ 700.0000 0.0588073
## ────────────────────────────────────────────────────────────────
## ᵃ Levene's test is significant (p < .05), suggesting a
## violation of the assumption of equal variances
all tasks
all_long %>%
group_by(group,infant) %>%
summarise(meanrating = mean(rating, na.rm = TRUE)) %>%
ggplot(aes(x = group, y = meanrating, fill = group)) +
geom_col() +
facet_wrap(~infant) +
labs(subtitle = "Group 1: Baby A preterm, Baby B full term \n Group 2: Baby A full term, Baby B pre term", title = "all tasks", caption = "Group1 N = 173; Group2 N = 185") +
easy_remove_legend()## `summarise()` has grouped output by 'group'. You can override using the `.groups` argument.
all stats
allBabyA <- all_long %>%
filter(infant == "BabyA")
allBabyB <- all_long %>%
filter(infant == "BabyB")
# do the ratings of group 1 and 2 differ for BabyA
ttestIS(formula = rating ~ group, data = allBabyA)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ────────────────────────────────────────────────────────────────
## Statistic df p
## ────────────────────────────────────────────────────────────────
## rating Student's t -14.57867 3522.000 < .0000001
## ────────────────────────────────────────────────────────────────
# do the ratings of group 1 and 2 differ for BabyB
ttestIS(formula = rating ~ group, data = allBabyB)##
## INDEPENDENT SAMPLES T-TEST
##
## Independent Samples T-Test
## ───────────────────────────────────────────────────────────────
## Statistic df p
## ───────────────────────────────────────────────────────────────
## rating Student's t 2.991223 3514.000 0.0027979
## ───────────────────────────────────────────────────────────────
combo plots
library(patchwork)fine_gross <- fine_plot + gross_plot
fine_grossself_play <- self_plot + play_plot
self_play