Preparation
Load packages
library(kableExtra)
library(formattable)
library(readxl)
library(tidyr)
library(dplyr)
library(magrittr)
library(ggplot2)
library(ggrepel)
library(broom)
library(RColorBrewer)
library(gridExtra)
USV data
usv <- bind_rows(
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'C5:G14', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `8` = X__2) %>%
gather(`8`, key = 'age_days', value = 'fileno') %>%
rename(`8` = X__3) %>%
gather(`8`, key = 'age1', value = 'number') %>%
rename(`8` = X__4) %>%
gather(`8`, key = 'age2', value = 'frequency') %>%
rename(`8` = X__5) %>%
gather(`8`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'C5:K14', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `10` = X__6) %>%
gather(`10`, key = 'age_days', value = 'fileno') %>%
rename(`10` = X__7) %>%
gather(`10`, key = 'age1', value = 'number') %>%
rename(`10` = X__8) %>%
gather(`10`, key = 'age2', value = 'frequency') %>%
rename(`10` = X__9) %>%
gather(`10`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'C5:O14', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `12` = X__10) %>%
gather(`12`, key = 'age_days', value = 'fileno') %>%
rename(`12` = X__11) %>%
gather(`12`, key = 'age1', value = 'number') %>%
rename(`12` = X__12) %>%
gather(`12`, key = 'age2', value = 'frequency') %>%
rename(`12` = X__13) %>%
gather(`12`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'A27:G36', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `8` = X__4) %>%
gather(`8`, key = 'age_days', value = 'fileno') %>%
rename(`8` = X__5) %>%
gather(`8`, key = 'age1', value = 'number') %>%
rename(`8` = X__6) %>%
gather(`8`, key = 'age2', value = 'frequency') %>%
rename(`8` = X__7) %>%
gather(`8`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'A27:K36', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `10` = X__8) %>%
gather(`10`, key = 'age_days', value = 'fileno') %>%
rename(`10` = X__9) %>%
gather(`10`, key = 'age1', value = 'number') %>%
rename(`10` = X__10) %>%
gather(`10`, key = 'age2', value = 'frequency') %>%
rename(`10` = X__11) %>%
gather(`10`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'MALES-M', range = 'A27:O36', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `12` = X__12) %>%
gather(`12`, key = 'age_days', value = 'fileno') %>%
rename(`12` = X__13) %>%
gather(`12`, key = 'age1', value = 'number') %>%
rename(`12` = X__14) %>%
gather(`12`, key = 'age2', value = 'frequency') %>%
rename(`12` = X__15) %>%
gather(`12`, key = 'age3', value = 'duration') %>%
mutate(sex = 'M', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A5:E13', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `8` = X__2) %>%
gather(`8`, key = 'age_days', value = 'fileno') %>%
rename(`8` = X__3) %>%
gather(`8`, key = 'age1', value = 'number') %>%
rename(`8` = X__4) %>%
gather(`8`, key = 'age2', value = 'frequency') %>%
rename(`8` = X__5) %>%
gather(`8`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A5:I13', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `10` = X__6) %>%
gather(`10`, key = 'age_days', value = 'fileno') %>%
rename(`10` = X__7) %>%
gather(`10`, key = 'age1', value = 'number') %>%
rename(`10` = X__8) %>%
gather(`10`, key = 'age2', value = 'frequency') %>%
rename(`10` = X__9) %>%
gather(`10`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A5:M13', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `12` = X__10) %>%
gather(`12`, key = 'age_days', value = 'fileno') %>%
rename(`12` = X__11) %>%
gather(`12`, key = 'age1', value = 'number') %>%
rename(`12` = X__12) %>%gather(`12`, key = 'age2', value = 'frequency') %>%
rename(`12` = X__13) %>%
gather(`12`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'KO') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A21:E30', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `8` = X__2) %>%
gather(`8`, key = 'age_days', value = 'fileno') %>%
rename(`8` = X__3) %>%
gather(`8`, key = 'age1', value = 'number') %>%
rename(`8` = X__4) %>%
gather(`8`, key = 'age2', value = 'frequency') %>%
rename(`8` = X__5) %>%
gather(`8`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A21:I30', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `10` = X__6) %>%
gather(`10`, key = 'age_days', value = 'fileno') %>%
rename(`10` = X__7) %>%
gather(`10`, key = 'age1', value = 'number') %>%
rename(`10` = X__8) %>%
gather(`10`, key = 'age2', value = 'frequency') %>%
rename(`10` = X__9) %>%
gather(`10`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration')),
read_excel(path = 'SHANK3 USV DATA (12.08.17) AM.xlsx',
sheet = 'FEMALES-M', range = 'A21:M30', col_names = FALSE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1, `12` = X__10) %>%
gather(`12`, key = 'age_days', value = 'fileno') %>%
rename(`12` = X__11) %>%
gather(`12`, key = 'age1', value = 'number') %>%
rename(`12` = X__12) %>%
gather(`12`, key = 'age2', value = 'frequency') %>%
rename(`12` = X__13) %>%
gather(`12`, key = 'age3', value = 'duration') %>%
mutate(sex = 'F', condition = 'WT') %>%
select(c('pupid', 'sex', 'condition', 'age_days', 'frequency', 'duration'))
) %>%
gather(c('frequency','duration'), key = 'measure', value = 'value') %>%
mutate(sex = factor(sex, levels = c('M', 'F')),
condition = factor(condition, levels = c('WT', 'KO')),
age_days = factor(age_days, levels = c('8', '10', '12')),
measure = factor(measure, levels = c('frequency', 'duration')))
usv_quartiles <- usv %>%
filter(condition == 'WT') %>%
group_by(sex, measure, age_days) %>%
do(quartiles=unique(quantile(.$value, seq(0, 1, length.out = 5), na.rm = TRUE)))
usv_min_max <- usv %>%
group_by(sex, measure, age_days) %>%
summarise(min_val = min(value, na.rm = TRUE), max_val = max(value, na.rm = TRUE)) %>%
ungroup
usv_quartiles <- usv_quartiles %>%
full_join(usv_min_max) %>%
ungroup %>% rowwise %>%
mutate(quartiles = if_else(length(quartiles)<5, list(rep(NA,5)), list(c(min_val, quartiles[2:4], max_val))))
usv <- usv %>%
group_by(sex, measure, age_days) %>%
full_join(usv_quartiles) %>%
mutate(Q=as.factor(cut(value, quartiles[[1]], include.lowest=TRUE, labels=FALSE)))
usv
Plot frequencies trends
library(ggrepel)
usv.justfirst <- usv %>% filter(measure == 'frequency' & age_days == 8)
usv %>% filter(measure == 'frequency') %>%
ggplot(aes(x = age_days, y = value)) +
geom_point(aes(color=pupid)) +
geom_line(aes(group=pupid, color=pupid)) +
geom_smooth(aes(x=as.numeric(age_days)), method = "lm", formula = y ~ splines::ns(x, df=2), se = TRUE) +
geom_label_repel(data=usv.justfirst, aes(label=pupid, color=pupid), alpha=0.75, nudge_x = -0.2) +
facet_grid(. ~ sex + condition) +
guides(color=FALSE)

Plot durations trends
usv.justfirst <- usv %>% filter(measure == 'duration' & age_days == 8)
usv %>% filter(measure == 'duration') %>%
ggplot(aes(x = age_days, y = value)) +
geom_point(aes(color=pupid)) +
geom_line(aes(group=pupid, color=pupid)) +
geom_smooth(aes(x=as.numeric(age_days)), method = "lm", formula = y ~ splines::ns(x, df=2), se = TRUE) +
geom_label_repel(data=usv.justfirst, aes(label=pupid, color=pupid), alpha=0.75, nudge_x = -0.2) +
facet_grid(. ~ sex + condition) +
guides(color=FALSE)

Rank frequencies
u1 <- usv %>% filter(sex == 'M' & condition == 'WT' & measure == 'frequency')
fm1 <- lm(value ~ splines::ns(as.numeric(age_days), df=2), data = u1)
u1[['resid']] <- fm1[['residuals']]
ssr1 <- u1 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u2 <- usv %>% filter(sex == 'M' & condition == 'KO' & measure == 'frequency')
p2 <- predict(fm1, u2, type='response')
u2[['resid']] <- u2$value - p2
ssr2 <- u2 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u3 <- usv %>% filter(sex == 'F' & condition == 'WT' & measure == 'frequency')
fm3 <- lm(value ~ splines::ns(as.numeric(age_days), df=2), data = u3)
u3[['resid']] <- fm3[['residuals']]
ssr3 <- u3 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u4 <- usv %>% filter(sex == 'F' & condition == 'KO' & measure == 'frequency')
p4 <- predict(fm3, u4, type='response')
u4[['resid']] <- u4$value - p4
ssr4 <- u4 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
ssr.freq <- bind_rows(ssr1, ssr2, ssr3, ssr4) %>%
mutate(fill = factor(if_else(sex == 'M',
if_else( condition == 'WT', 'M:WT', 'M:KO'),
if_else( condition == 'WT', 'F:WT', 'F:KO')),
levels = c('M:KO', 'M:WT', 'F:WT', 'F:KO')))
ssr.freq %>%
ggplot(aes(x=pupid, y=ssr)) +
scale_fill_brewer(palette = "RdBu", direction = -1) +
geom_col(aes(fill=fill)) +
facet_grid(. ~ sex + condition, scales = 'free') +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(fill=FALSE)

Rank durations
u1 <- usv %>% filter(sex == 'M' & condition == 'WT' & measure == 'duration')
fm1 <- lm(value ~ splines::ns(as.numeric(age_days), df=2), data = u1)
u1[['resid']] <- fm1[['residuals']]
ssr1 <- u1 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u2 <- usv %>% filter(sex == 'M' & condition == 'KO' & measure == 'duration')
p2 <- predict(fm1, u2, type='response')
u2[['resid']] <- u2$value - p2
ssr2 <- u2 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u3 <- usv %>% filter(sex == 'F' & condition == 'WT' & measure == 'duration')
fm3 <- lm(value ~ splines::ns(as.numeric(age_days), df=2), data = u3)
u3[['resid']] <- fm3[['residuals']]
ssr3 <- u3 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
u4 <- usv %>% filter(sex == 'F' & condition == 'KO' & measure == 'duration')
p4 <- predict(fm3, u4, type='response')
u4[['resid']] <- u4$value - p4
ssr4 <- u4 %>% group_by(sex, condition, pupid) %>% summarise(ssr=sum(resid^2))
ssr.dur <- bind_rows(ssr1, ssr2, ssr3, ssr4) %>%
mutate(fill = factor(if_else(sex == 'M',
if_else( condition == 'WT', 'M:WT', 'M:KO'),
if_else( condition == 'WT', 'F:WT', 'F:KO')),
levels = c('M:KO', 'M:WT', 'F:WT', 'F:KO')))
ssr.dur %>%
ggplot(aes(x=pupid, y=ssr)) +
scale_fill_brewer(palette = "RdBu", direction = -1) +
geom_col(aes(fill=fill)) +
facet_grid(. ~ sex + condition, scales = 'free') +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(fill=FALSE)

Chamber test data
chamber <- bind_rows(
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:H12', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', type = 'detailed', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:Q12', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(11:17, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', type = 'detailed', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:U12', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(19:21, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', type = 'total', measure = 'duration',
behavior = gsub('Total ', '', gsub(' \\(s\\)$', '', behavior, perl = TRUE))) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:H29', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', type = 'detailed', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:Q29', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(11:17, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', type = 'detailed', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'MALES- Test-M', range = 'A2:U29', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(19:21, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', type = 'total', measure = 'duration',
behavior = gsub('Total ', '', gsub(' \\(s\\)$', '', behavior, perl = TRUE))) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:H11', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', type = 'detailed', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:P11', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', type = 'detailed', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:T11', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(18:20, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', type = 'total', measure = 'duration',
behavior = gsub('Total ', '', gsub(' \\(s\\)$', '', behavior, perl = TRUE))) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:H28', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', type = 'detailed', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:P28', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', type = 'detailed', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value')),
read_excel(path = 'Shank3 3-Chamber Test Results_FINAL.xlsx',
sheet = 'FEMALES- Test-M', range = 'A2:U28', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(18:20, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', type = 'total', measure = 'duration',
behavior = gsub('Total ', '', gsub(' \\(s\\)$', '', behavior, perl = TRUE))) %>%
select(c('pupid', 'sex', 'condition', 'type', 'behavior', 'type', 'measure', 'value'))
)
chamber <- chamber %>%
mutate(sex = factor(sex, levels = c('M', 'F')),
condition = factor(condition, levels = c('WT', 'KO')),
type = factor(type, levels = c('detailed', 'total')),
measure = factor(measure, levels = c('frequency', 'duration')),
behavior = factor(behavior, levels = c('Rear', 'Contact', 'Sniff', 'Grooming', 'Stretch', 'Withdrawal', 'Nose2 nose',
'Middle', 'Non-Social', 'Social')),
social = if_else(behavior %in% c('Rear', 'Contact', 'Sniff', 'Nose2 nose', 'Social'), TRUE, FALSE)) %>%
group_by(sex, type, measure, behavior) %>% # group in quartiles ignoring condition
mutate(Q0 = if_else(social, as.factor(ntile(desc(value), 4)), as.factor(ntile(value, 4))))
# invert the quartiles for the social behaviors : Q0==4 is represents the most non-social behavior
# instead of the above, use just the values in the WT group to set the quartiles for the KO group as well
chamber_quartiles <- chamber %>%
ungroup %>%
filter(condition == 'WT') %>%
group_by(sex, type, measure, behavior) %>%
do(quartiles=unique(quantile(.$value, seq(0, 1, length.out = 5), na.rm = TRUE)))
chamber_min_max <- chamber %>%
summarise(min_val = min(value, na.rm = TRUE), max_val = max(value, na.rm = TRUE)) %>%
ungroup
chamber_quartiles <- chamber_quartiles %>%
full_join(chamber_min_max) %>%
ungroup %>% rowwise %>%
mutate(quartiles = if_else(length(quartiles)<5, list(rep(NA,5)), list(c(min_val, quartiles[2:4], max_val))))
chamber <- chamber %>%
full_join(chamber_quartiles) %>%
mutate(Q=as.numeric(cut(value, quartiles[[1]], include.lowest=TRUE, labels=FALSE)))
chamber <- chamber %>% ungroup %>% mutate(Q=as.factor(if_else(social, 5-Q, Q)))
chamber
Plot quartiles
chamber %>%
ggplot(aes(x=pupid, y=value)) +
facet_grid (type + measure + behavior ~ sex + condition, scales = 'free') +
geom_col(aes(fill=Q)) +
scale_fill_brewer(palette = "RdBu", direction = -1) +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Social proximity data
proximity <- bind_rows(
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'MALES-M', range = 'A2:J12', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(2:10, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'MALES-M', range = 'A2:T12', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(12:20, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'MALES-M', range = 'A2:J28', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(2:10, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'MALES-M', range = 'A2:T28', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(12:20, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:J11', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(2:10, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:T11', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
gather(12:20, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:J27', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(2:10, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')) ,
read_excel(path = 'Shank3 Social Proximity Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:T27', col_names = TRUE) %>%
mutate(`Pup ID` = gsub(' .*$', '', `Pup ID`, perl = TRUE)) %>%
rename(pupid = `Pup ID`) %>%
tail(n=10) %>%
gather(12:20, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value'))
)
proximity <- proximity %>%
mutate(sex = factor(sex, levels = c('M', 'F')),
condition = factor(condition, levels = c('WT', 'KO')),
measure = factor(measure, levels = c('frequency', 'duration')),
behavior = factor(behavior, levels = c('Nose2Nose', 'Anogenital Sniff', 'Crawl Under', 'Crawl Over',
'Allogrooming', 'Upright', 'Self Grooming', 'Nose2Head', 'Other Behavior')),
social = if_else(behavior %in% c('Nose2Nose', 'Anogenital Sniff', 'Crawl Under', 'Crawl Over',
'Allogrooming', 'Upright','Nose2Head'), TRUE, FALSE)) %>%
group_by(sex, measure, behavior) %>% # group in quartiles ignoring condition
mutate(Q0 = if_else(social, as.factor(ntile(desc(value), 4)), as.factor(ntile(value, 4))))
proximity_quartiles <- proximity %>%
ungroup %>%
filter(condition == 'WT') %>%
group_by(sex, measure, behavior) %>%
do(quartiles=unique(quantile(.$value, seq(0, 1, length.out = 5), na.rm = TRUE)))
proximity_min_max <- proximity %>%
summarise(min_val = min(value, na.rm = TRUE), max_val = max(value, na.rm = TRUE)) %>%
ungroup
proximity_quartiles <- proximity_quartiles %>%
full_join(proximity_min_max) %>%
ungroup %>% rowwise %>%
mutate(quartiles = if_else(length(quartiles)<5, list(rep(NA,5)), list(c(min_val, quartiles[2:4], max_val))))
proximity <- proximity %>%
full_join(proximity_quartiles) %>%
mutate(Q=as.numeric(cut(value, quartiles[[1]], include.lowest=TRUE, labels=FALSE)))
proximity <- proximity %>% ungroup %>% mutate(Q=as.factor(if_else(social, 5-Q, Q)))
proximity
Plot quartiles
proximity %>%
ggplot(aes(x=pupid, y=value)) +
facet_grid (measure + behavior ~ sex + condition, scales = 'free') +
geom_col(aes(fill=Q)) +
scale_fill_brewer(palette = "RdBu", direction = -1) +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Grooming data
grooming <- bind_rows(
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'MALES -M', range = 'A2:H12', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'MALES -M', range = 'A2:P12', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'KO', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'MALES -M', range = 'A2:H28', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
tail(n=10) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'MALES -M', range = 'A2:P28', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
tail(n=10) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'M', condition = 'WT', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:H11', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:P11', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'KO', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:H27', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
tail(n=10) %>%
gather(2:8, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', measure = 'frequency') %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value')),
read_excel(path = 'Shank3 Grooming Results_FINAL.xlsx',
sheet = 'FEMALES-M', range = 'A2:P27', col_names = TRUE) %>%
mutate(X__1 = gsub(' .*$', '', X__1, perl = TRUE)) %>%
rename(pupid = X__1) %>%
tail(n=10) %>%
gather(10:16, key='behavior', value='value') %>%
mutate(sex = 'F', condition = 'WT', measure = 'duration',
behavior = gsub('__1$', '', behavior, perl = TRUE)) %>%
select(c('pupid', 'sex', 'condition', 'behavior', 'measure', 'value'))
)
grooming <- grooming %>%
mutate(sex = factor(sex, levels = c('M', 'F')),
condition = factor(condition, levels = c('WT', 'KO')),
measure = factor(measure, levels = c('frequency', 'duration')),
behavior = factor(behavior, levels = c('Other', 'Paw', 'Head', 'Body', 'Leg', 'Tail', 'Genital'))) %>%
group_by(sex, measure, behavior) %>%
mutate(Q0 = as.factor(ntile(value, 4)))
grooming_quartiles <- grooming %>%
ungroup %>%
filter(condition == 'WT') %>%
group_by(sex, measure, behavior) %>%
do(quartiles=unique(quantile(.$value, seq(0, 1, length.out = 5), na.rm = TRUE)))
grooming_min_max <- grooming %>%
summarise(min_val = min(value, na.rm = TRUE), max_val = max(value, na.rm = TRUE)) %>%
ungroup
grooming_quartiles <- grooming_quartiles %>%
full_join(grooming_min_max) %>%
ungroup %>% rowwise %>%
mutate(quartiles = if_else(length(quartiles)<5, list(rep(NA,5)), list(c(min_val, quartiles[2:4], max_val))))
grooming <- grooming %>%
full_join(grooming_quartiles) %>%
mutate(Q=as.factor(cut(value, quartiles[[1]], include.lowest=TRUE, labels=FALSE)))
grooming
Plot quartiles
grooming %>%
ggplot(aes(x=pupid, y=value)) +
facet_grid (measure + behavior ~ sex + condition, scales = 'free') +
geom_col(aes(fill=Q)) +
scale_fill_brewer(palette = "RdBu", direction = -1) +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Tests matrix
Merging all test data
all <- bind_rows(
usv %>% ungroup %>%
mutate(testgroup = 'USV',
test = paste(measure, age_days)) %>%
select(c('pupid', 'sex', 'condition', 'testgroup', 'test', 'value', 'Q')),
chamber %>% ungroup %>%
mutate(testgroup = '3-chamber',
test = paste(type, measure, behavior)) %>%
select(c('pupid', 'sex', 'condition', 'testgroup', 'test', 'value', 'Q')),
proximity %>% ungroup %>%
mutate(testgroup = 'Social proximity',
test = paste(measure, behavior)) %>%
select(c('pupid', 'sex', 'condition', 'testgroup', 'test', 'value', 'Q')),
grooming %>% ungroup %>%
mutate(testgroup = 'Grooming',
test = paste(measure, behavior)) %>%
select(c('pupid', 'sex', 'condition', 'testgroup', 'test', 'value', 'Q'))
) %>%
mutate(testgroup = factor(testgroup, levels = c('USV', '3-chamber', 'Social proximity', 'Grooming')))
all
Plot all tests (except those that are all NAs)
allarenas <- function(x){all(is.na(x))}
tests <- all %>%
ungroup %>%
group_by(test) %>%
summarise(alltestsarenas = allarenas(Q))
all %>%
ungroup %>%
full_join(tests) %>%
filter(!alltestsarenas) %>%
ggplot(aes(x = pupid, y = test, fill = Q)) +
geom_tile(colour = "white", size = 0.25) +
labs(x = "", y = "") +
scale_y_discrete(expand=c(0,0)) +
scale_x_discrete(expand=c(0,0)) +
scale_fill_brewer(palette = 'RdBu', direction = -1) +
facet_grid (testgroup ~ sex + condition, scales = 'free', space = 'free') +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Finding the tests that are significant
P-values for the two-sided, homoscedastic t-tests
all_spread <- all %>% ungroup() %>% select(pupid,sex,condition,test,value) %>% spread(test,value)
pvals <- bind_rows(
all_spread %>%
filter(sex=='M') %>%
summarise_at(vars(unique(all$test)),
funs(t.test(.[condition == "WT"], .[condition == "KO"], var.equal = TRUE)$p.value)) %>%
gather(test,pvalue) %>%
mutate(sex = 'M'),
all_spread %>%
filter(sex=='F') %>%
summarise_at(vars(unique(all$test)),
funs(t.test(.[condition == "WT"], .[condition == "KO"], var.equal = TRUE)$p.value)) %>%
gather(test,pvalue) %>%
mutate(sex = 'F')
) %>%
mutate(signif = if_else(pvalue <= .05, TRUE, FALSE),
pvalue = ifelse(pvalue <= .05,
color_tile("red", "white")(signif(pvalue, 3)),
color_tile("white", "darkgreen")(signif(pvalue, 3))))
pvals %>%
kable("html", escape = F) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), full_width = F)
|
test
|
pvalue
|
sex
|
signif
|
|
frequency 8
|
5.02e-01
|
M
|
FALSE
|
|
frequency 10
|
2.94e-01
|
M
|
FALSE
|
|
frequency 12
|
3.51e-01
|
M
|
FALSE
|
|
duration 8
|
5.27e-01
|
M
|
FALSE
|
|
duration 10
|
9.63e-01
|
M
|
FALSE
|
|
duration 12
|
1.54e-01
|
M
|
FALSE
|
|
detailed frequency Rear
|
4.66e-01
|
M
|
FALSE
|
|
detailed frequency Contact
|
8.02e-02
|
M
|
FALSE
|
|
detailed frequency Sniff
|
3.96e-02
|
M
|
TRUE
|
|
detailed frequency Grooming
|
1.00e+00
|
M
|
FALSE
|
|
detailed frequency Stretch
|
8.72e-02
|
M
|
FALSE
|
|
detailed frequency Withdrawal
|
1.84e-01
|
M
|
FALSE
|
|
detailed frequency Nose2 nose
|
8.00e-05
|
M
|
TRUE
|
|
detailed duration Rear
|
8.59e-01
|
M
|
FALSE
|
|
detailed duration Contact
|
5.14e-02
|
M
|
FALSE
|
|
detailed duration Sniff
|
6.37e-02
|
M
|
FALSE
|
|
detailed duration Grooming
|
7.84e-01
|
M
|
FALSE
|
|
detailed duration Stretch
|
8.72e-02
|
M
|
FALSE
|
|
detailed duration Withdrawal
|
1.51e-01
|
M
|
FALSE
|
|
detailed duration Nose2 nose
|
1.22e-04
|
M
|
TRUE
|
|
total duration Middle
|
8.53e-02
|
M
|
FALSE
|
|
total duration Social
|
4.86e-02
|
M
|
TRUE
|
|
total duration Non-Social
|
2.46e-01
|
M
|
FALSE
|
|
frequency Nose2Nose
|
7.22e-02
|
M
|
FALSE
|
|
frequency Anogenital Sniff
|
4.87e-01
|
M
|
FALSE
|
|
frequency Crawl Under
|
4.93e-01
|
M
|
FALSE
|
|
frequency Crawl Over
|
1.71e-01
|
M
|
FALSE
|
|
frequency Allogrooming
|
2.45e-01
|
M
|
FALSE
|
|
frequency Upright
|
1.57e-02
|
M
|
TRUE
|
|
frequency Self Grooming
|
1.57e-01
|
M
|
FALSE
|
|
frequency Nose2Head
|
5.86e-02
|
M
|
FALSE
|
|
frequency Other Behavior
|
1.74e-02
|
M
|
TRUE
|
|
duration Nose2Nose
|
1.15e-01
|
M
|
FALSE
|
|
duration Anogenital Sniff
|
3.91e-01
|
M
|
FALSE
|
|
duration Crawl Under
|
7.63e-01
|
M
|
FALSE
|
|
duration Crawl Over
|
2.00e-01
|
M
|
FALSE
|
|
duration Allogrooming
|
5.01e-01
|
M
|
FALSE
|
|
duration Upright
|
1.17e-01
|
M
|
FALSE
|
|
duration Self Grooming
|
2.21e-01
|
M
|
FALSE
|
|
duration Nose2Head
|
1.29e-01
|
M
|
FALSE
|
|
duration Other Behavior
|
6.58e-02
|
M
|
FALSE
|
|
frequency Other
|
9.16e-01
|
M
|
FALSE
|
|
frequency Paw
|
7.37e-01
|
M
|
FALSE
|
|
frequency Head
|
1.55e-01
|
M
|
FALSE
|
|
frequency Body
|
1.62e-01
|
M
|
FALSE
|
|
frequency Leg
|
1.10e-03
|
M
|
TRUE
|
|
frequency Tail
|
7.68e-04
|
M
|
TRUE
|
|
frequency Genital
|
1.00e+00
|
M
|
FALSE
|
|
duration Other
|
7.27e-05
|
M
|
TRUE
|
|
duration Paw
|
1.79e-01
|
M
|
FALSE
|
|
duration Head
|
5.78e-04
|
M
|
TRUE
|
|
duration Body
|
1.04e-04
|
M
|
TRUE
|
|
duration Leg
|
4.34e-02
|
M
|
TRUE
|
|
duration Tail
|
2.24e-02
|
M
|
TRUE
|
|
duration Genital
|
7.21e-01
|
M
|
FALSE
|
|
frequency 8
|
8.91e-01
|
F
|
FALSE
|
|
frequency 10
|
5.09e-01
|
F
|
FALSE
|
|
frequency 12
|
6.86e-01
|
F
|
FALSE
|
|
duration 8
|
6.46e-01
|
F
|
FALSE
|
|
duration 10
|
7.87e-01
|
F
|
FALSE
|
|
duration 12
|
5.60e-01
|
F
|
FALSE
|
|
detailed frequency Rear
|
2.21e-02
|
F
|
TRUE
|
|
detailed frequency Contact
|
2.30e-02
|
F
|
TRUE
|
|
detailed frequency Sniff
|
1.69e-02
|
F
|
TRUE
|
|
detailed frequency Grooming
|
1.47e-02
|
F
|
TRUE
|
|
detailed frequency Stretch
|
1.53e-01
|
F
|
FALSE
|
|
detailed frequency Withdrawal
|
4.93e-01
|
F
|
FALSE
|
|
detailed frequency Nose2 nose
|
5.42e-01
|
F
|
FALSE
|
|
detailed duration Rear
|
2.28e-01
|
F
|
FALSE
|
|
detailed duration Contact
|
5.17e-02
|
F
|
FALSE
|
|
detailed duration Sniff
|
9.71e-01
|
F
|
FALSE
|
|
detailed duration Grooming
|
2.40e-02
|
F
|
TRUE
|
|
detailed duration Stretch
|
1.28e-01
|
F
|
FALSE
|
|
detailed duration Withdrawal
|
1.53e-01
|
F
|
FALSE
|
|
detailed duration Nose2 nose
|
2.15e-01
|
F
|
FALSE
|
|
total duration Middle
|
6.34e-01
|
F
|
FALSE
|
|
total duration Social
|
2.70e-01
|
F
|
FALSE
|
|
total duration Non-Social
|
5.09e-01
|
F
|
FALSE
|
|
frequency Nose2Nose
|
4.93e-02
|
F
|
TRUE
|
|
frequency Anogenital Sniff
|
6.26e-01
|
F
|
FALSE
|
|
frequency Crawl Under
|
4.35e-01
|
F
|
FALSE
|
|
frequency Crawl Over
|
3.36e-01
|
F
|
FALSE
|
|
frequency Allogrooming
|
3.76e-01
|
F
|
FALSE
|
|
frequency Upright
|
5.08e-01
|
F
|
FALSE
|
|
frequency Self Grooming
|
4.70e-01
|
F
|
FALSE
|
|
frequency Nose2Head
|
3.44e-01
|
F
|
FALSE
|
|
frequency Other Behavior
|
5.57e-01
|
F
|
FALSE
|
|
duration Nose2Nose
|
3.62e-02
|
F
|
TRUE
|
|
duration Anogenital Sniff
|
8.15e-01
|
F
|
FALSE
|
|
duration Crawl Under
|
3.68e-01
|
F
|
FALSE
|
|
duration Crawl Over
|
3.74e-01
|
F
|
FALSE
|
|
duration Allogrooming
|
6.84e-01
|
F
|
FALSE
|
|
duration Upright
|
3.03e-01
|
F
|
FALSE
|
|
duration Self Grooming
|
6.66e-01
|
F
|
FALSE
|
|
duration Nose2Head
|
2.65e-01
|
F
|
FALSE
|
|
duration Other Behavior
|
9.45e-02
|
F
|
FALSE
|
|
frequency Other
|
2.63e-02
|
F
|
TRUE
|
|
frequency Paw
|
1.93e-01
|
F
|
FALSE
|
|
frequency Head
|
2.46e-02
|
F
|
TRUE
|
|
frequency Body
|
7.25e-02
|
F
|
FALSE
|
|
frequency Leg
|
1.28e-02
|
F
|
TRUE
|
|
frequency Tail
|
5.38e-02
|
F
|
FALSE
|
|
frequency Genital
|
1.47e-02
|
F
|
TRUE
|
|
duration Other
|
2.20e-02
|
F
|
TRUE
|
|
duration Paw
|
9.07e-01
|
F
|
FALSE
|
|
duration Head
|
6.15e-03
|
F
|
TRUE
|
|
duration Body
|
1.52e-02
|
F
|
TRUE
|
|
duration Leg
|
1.68e-02
|
F
|
TRUE
|
|
duration Tail
|
3.08e-02
|
F
|
TRUE
|
|
duration Genital
|
1.90e-01
|
F
|
FALSE
|
Significant tests
Males
test_signif_male <- pvals %>% filter(sex =='M' & signif)
test_signif_male %>%
kable("html", escape = F) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), full_width = F)
|
test
|
pvalue
|
sex
|
signif
|
|
detailed frequency Sniff
|
3.96e-02
|
M
|
TRUE
|
|
detailed frequency Nose2 nose
|
8.00e-05
|
M
|
TRUE
|
|
detailed duration Nose2 nose
|
1.22e-04
|
M
|
TRUE
|
|
total duration Social
|
4.86e-02
|
M
|
TRUE
|
|
frequency Upright
|
1.57e-02
|
M
|
TRUE
|
|
frequency Other Behavior
|
1.74e-02
|
M
|
TRUE
|
|
frequency Leg
|
1.10e-03
|
M
|
TRUE
|
|
frequency Tail
|
7.68e-04
|
M
|
TRUE
|
|
duration Other
|
7.27e-05
|
M
|
TRUE
|
|
duration Head
|
5.78e-04
|
M
|
TRUE
|
|
duration Body
|
1.04e-04
|
M
|
TRUE
|
|
duration Leg
|
4.34e-02
|
M
|
TRUE
|
|
duration Tail
|
2.24e-02
|
M
|
TRUE
|
Females
test_signif_female <- pvals %>% filter(sex =='F' & signif)
test_signif_female %>%
kable("html", escape = F) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), full_width = F)
|
test
|
pvalue
|
sex
|
signif
|
|
detailed frequency Rear
|
2.21e-02
|
F
|
TRUE
|
|
detailed frequency Contact
|
2.30e-02
|
F
|
TRUE
|
|
detailed frequency Sniff
|
1.69e-02
|
F
|
TRUE
|
|
detailed frequency Grooming
|
1.47e-02
|
F
|
TRUE
|
|
detailed duration Grooming
|
2.40e-02
|
F
|
TRUE
|
|
frequency Nose2Nose
|
4.93e-02
|
F
|
TRUE
|
|
duration Nose2Nose
|
3.62e-02
|
F
|
TRUE
|
|
frequency Other
|
2.63e-02
|
F
|
TRUE
|
|
frequency Head
|
2.46e-02
|
F
|
TRUE
|
|
frequency Leg
|
1.28e-02
|
F
|
TRUE
|
|
frequency Genital
|
1.47e-02
|
F
|
TRUE
|
|
duration Other
|
2.20e-02
|
F
|
TRUE
|
|
duration Head
|
6.15e-03
|
F
|
TRUE
|
|
duration Body
|
1.52e-02
|
F
|
TRUE
|
|
duration Leg
|
1.68e-02
|
F
|
TRUE
|
|
duration Tail
|
3.08e-02
|
F
|
TRUE
|
Plot significant tests
Males
tests <- all %>%
ungroup %>%
filter(sex == 'M') %>%
group_by(test) %>%
summarise(alltestsarenas = allarenas(Q))
all %>%
ungroup %>%
filter(sex == 'M') %>%
full_join(tests) %>%
filter(!alltestsarenas) %>%
filter(test %in% test_signif_male[['test']]) %>%
ggplot(aes(x = pupid, y = test, fill = Q)) +
geom_tile(colour = "white", size = 0.25) +
labs(x = "", y = "") +
scale_fill_brewer(palette = 'RdBu', direction = -1) +
scale_y_discrete(expand=c(0,0)) +
scale_x_discrete(expand=c(0,0)) +
facet_grid (testgroup ~ sex + condition, scales = 'free', space = 'free') +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Females
tests <- all %>%
ungroup %>%
filter(sex == 'F') %>%
group_by(test) %>%
summarise(alltestsarenas = allarenas(Q))
all %>%
ungroup %>%
filter(sex == 'F') %>%
full_join(tests) %>%
filter(!alltestsarenas) %>%
filter(test %in% test_signif_female[['test']]) %>%
ggplot(aes(x = pupid, y = test, fill = Q)) +
geom_tile(colour = "white", size = 0.25) +
labs(x = "", y = "") +
scale_fill_brewer(palette = 'RdBu', direction = -1) +
scale_y_discrete(expand=c(0,0)) +
scale_x_discrete(expand=c(0,0)) +
facet_grid (testgroup ~ sex + condition, scales = 'free', space = 'free') +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position='bottom')

Social proximity data
Plot quartiles