Last updated: 2026-05-19 20:00:26 using pinned data version from: 2026-05-15 18:36:17
Users can load data by running (requires one-time google drive authentication):
Code
library(tidyverse)
library(pins)
library(nanoparquet)
library(googledrive)

# Load the board of pinned data sets (authenticated users only)
board <- board_gdrive(path = as_id("1OZlphhu6vYm1A2Bm2-zD7a4luS5nGWgS")) 

# To see available pinned data
board %>% pin_list()

# To read a specific data pin into memory
ds <- board %>% pin_read("imu_raw_samples") %>%
  filter(nap_period == 0, exclude_period == 0)

Usable data

Code
usable_data <- ds %>% count(id, session) %>% mutate(usable_hours = n/3600)
recording_duration <- ds %>% group_by(id, session) %>% 
  mutate(recording_hours = as.numeric(max(time) - min(time))) %>% 
  slice_head(n = 1) %>% ungroup
  
usable_data %>% left_join(recording_duration) %>% 
  get_summary_stats(usable_hours, recording_hours, show = c("mean", "sd","min","max")) %>% 
  flextable() %>% autofit()

Usable data and total recording length in hours

variable

n

mean

sd

min

max

usable_hours

28

6.385

1.996

1.199

9.466

recording_hours

28

9.274

2.728

1.232

12.316

Code
usable_data  %>% 
  ggplot(aes(x = usable_hours)) + 
  geom_histogram() + 
  scale_x_binned(name = "Hours", limits = c(2,14))
recording_duration  %>% 
  ggplot(aes(x = recording_hours)) + 
  geom_histogram() + 
  scale_x_binned(name = "Hours", limits = c(2,14))

Usable hours after exclusions

Usable hours after exclusions

Recording length in hours

Recording length in hours

Infant Position Frequency by Age (Overall)

Code
ds_sum <- ds %>% group_by(id, session) %>% 
  mutate(total_samples = n()) %>% group_by(id, session, pos) %>% 
  summarize(pos_n  = n(), total_samples = mean(total_samples)) %>% ungroup
ds_sum <- ds_sum %>% complete(nesting(id, session), pos, fill = list(pos_n = 0, total_samples = 1))
ds_sum$pos_prop = ds_sum$pos_n/ds_sum$total_samples*100
ds_sum$session = as.numeric(ds_sum$session)

ds_sum %>% group_by(pos, session) %>% 
  get_summary_stats(pos_prop, show = c("mean", "sd","min","max")) %>% 
  select(-variable) %>% flextable() %>% autofit()

Position summary statistics

session

pos

n

mean

sd

min

max

1

Supine

14

25.430

17.165

8.322

58.046

2

Supine

9

15.335

10.302

3.956

35.125

3

Supine

5

11.218

10.087

1.922

25.343

1

Prone

14

19.794

13.419

2.168

53.195

2

Prone

9

9.736

3.694

3.257

15.002

3

Prone

5

11.802

2.444

10.066

15.904

1

Sitting

14

33.177

13.518

12.819

53.703

2

Sitting

9

43.748

10.718

32.400

60.394

3

Sitting

5

37.510

7.848

25.139

44.118

1

Standing

14

10.158

8.236

1.326

33.114

2

Standing

9

20.781

6.835

8.784

31.995

3

Standing

5

29.638

6.951

20.757

38.755

1

Held

14

11.441

4.541

3.704

20.746

2

Held

9

10.400

5.651

2.494

19.508

3

Held

5

9.832

5.086

3.273

15.978

Code
ggplot(ds_sum, aes(x = session, y = pos_prop, color = pos)) + 
  stat_summary(position = position_dodge(.1)) + 
  stat_summary(geom = "line", position = position_dodge(.1)) + 
  ylim(0,101) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_color_manual(values = pal, name ="") + 
  theme(legend.position = "bottom")
ggplot(ds_sum, aes(x = session, y = pos_prop, fill = pos)) + 
  stat_summary(geom = "bar", position = "stack") + 
  ylim(0,101) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_fill_manual(values = pal, name ="") + 
  theme(legend.position = "bottom")

Position means and SE

Position means and SE

Position distribution

Position distribution

Infant Position Frequency by Age (Individual)

Code
ggplot(ds_sum, aes(x = session, y = pos_prop, color = pos, group = id)) + 
  facet_wrap(~ pos) + 
  geom_point() + geom_line() +  
  ylim(0,100) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_color_manual(values = pal, name ="") + 
  theme(legend.position = "none")

Infant Restraint Frequency by Age (Overall)

Code
ds_sum_restraint <- ds %>% group_by(id, session) %>% 
  mutate(total_samples = n()) %>% group_by(id, session, restraint) %>% 
  summarize(restraint_n  = n(), total_samples = mean(total_samples)) %>% ungroup
ds_sum_restraint <- ds_sum_restraint %>% complete(nesting(id, session), restraint, fill = list(restraint_n = 0, total_samples = 1))
ds_sum_restraint$restraint_prop = ds_sum_restraint$restraint_n/ds_sum_restraint$total_samples*100
ds_sum_restraint$session = as.numeric(ds_sum_restraint$session)

ds_sum_restraint %>% group_by(restraint, session) %>% 
  get_summary_stats(restraint_prop, show = c("mean", "sd","min","max")) %>% 
  select(-variable) %>% flextable() %>% autofit()

Restraint summary statistics

session

restraint

n

mean

sd

min

max

1

Restrained

14

25.260

12.212

11.638

53.168

2

Restrained

9

25.424

15.525

5.402

55.081

3

Restrained

5

28.435

9.345

12.556

36.106

1

Unrestrained

14

74.740

12.212

46.832

88.362

2

Unrestrained

9

74.576

15.525

44.919

94.598

3

Unrestrained

5

71.565

9.345

63.894

87.444

Code
ggplot(ds_sum_restraint, aes(x = session, y = restraint_prop, color = restraint)) + 
  stat_summary(position = position_dodge(.1)) + 
  stat_summary(geom = "line", position = position_dodge(.1)) + 
  ylim(0,101) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_color_manual(values = restraint_pal, name ="") + 
  theme(legend.position = "bottom")
ggplot(ds_sum_restraint, aes(x = session, y = restraint_prop, fill = restraint)) + 
  stat_summary(geom = "bar", position = "stack") + 
  ylim(0,101) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_fill_manual(values = restraint_pal, name ="") + 
  theme(legend.position = "bottom")

Restraint means and SE

Restraint means and SE

Restraint distribution

Restraint distribution

Infant Restraint Frequency by Age (Individual)

Code
ggplot(ds_sum_restraint, aes(x = session, y = restraint_prop, color = restraint, group = id)) + 
  facet_wrap(~ restraint) + 
  geom_point() + geom_line() +  
  ylim(0,100) + ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  scale_color_manual(values = restraint_pal, name ="") + 
  theme(legend.position = "none")

Posture by restraint

Code
ds_sum_posrest <- ds %>% group_by(id, session) %>% 
  mutate(total_samples = n()) %>% group_by(id, session, pos, restraint) %>% 
  summarize(posrest_n  = n(), total_samples = mean(total_samples)) %>% ungroup
ds_sum_posrest <- ds_sum_posrest %>% complete(nesting(id, session), restraint, pos, fill = list(posrest_n = 0, total_samples = 1))
ds_sum_posrest$prop = ds_sum_posrest$posrest_n/ds_sum_posrest$total_samples*100
ds_sum_posrest$session = as.numeric(ds_sum_posrest$session)

ggplot(ds_sum_posrest, aes(x = session, y = prop, color = pos)) + 
  stat_summary(position = position_dodge(.1)) + 
  stat_summary(geom = "line", position = position_dodge(.1)) + 
  facet_wrap(~ restraint) + 
  ylab("% of time") + xlab("Session") +
  scale_x_continuous(breaks = 1:3, labels = c("7 mo","9 mo","11 mo"), limits = c(0.5,3.5)) + 
  coord_cartesian(ylim = c(0,55)) + 
  scale_color_manual(values = pal, name ="") + 
  theme(legend.position = "bottom")