This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.

library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.5
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
d <- read.csv("/Users/caoanjie/Desktop/senzaki.csv")
d
d %>%  mutate(S1_imada_coding = S1_ChildOnly_Back - S1_ChildOnly_Focal,
             S1_koster_coding = S1_ChildOnly_Focal / (S1_ChildOnly_Back + S1_ChildOnly_Focal)) %>% 
  filter(!is.na(S1_imada_coding) & !is.na(S1_koster_coding)) -> d_new_score 

d_new_score %>% 
  select(Pp., Culture, AgeGroup, S1_imada_coding, S1_koster_coding) %>% 
  gather(scoring_scheme, score, S1_imada_coding:S1_koster_coding) %>% 
  group_by(Culture, scoring_scheme) %>% 
  summarize(mean = mean(score),
            sd = sd(score),
            n = n()) %>%
    mutate(ci_range_95 =  1.96 * (sd/sqrt(n)),
         ci_lower = mean - ci_range_95,
         ci_upper = mean + ci_range_95) -> d_summary
 
d_summary
d_summary %>% filter(scoring_scheme == "S1_imada_coding") %>% 
  ggplot(aes(x = (as.factor(Culture)), y = mean)) + 
  facet_wrap(~scoring_scheme, ncol = 2) +
  geom_point() + 
  geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper)) +
  ylim(-2, 5) -> p1

d_summary %>% filter(scoring_scheme == "S1_koster_coding") %>% 
  ggplot(aes(x = (as.factor(Culture)), y = mean)) + 
  facet_wrap(~scoring_scheme, ncol = 2) +
  geom_point()+ 
  geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper)) -> p2

d_summary %>% filter(scoring_scheme == "S1_koster_coding") %>% 
  ggplot(aes(x = (as.factor(Culture)), y = mean)) + 
  facet_wrap(~scoring_scheme, ncol = 2) +
  geom_point()+ 
  ylim(-2,5) + 
  labs(title = "same scale as s1") +
  geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper)) -> p3

grid.arrange(p1, p2, p3, nrow = 1)

d_new_score %>% ggplot(aes(x = S1_ChildOnly_Focal, y = S1_imada_coding)) + geom_point()

d_new_score %>% ggplot(aes(x = S1_ChildOnly_Focal, y = S1_koster_coding)) + geom_point()

d_new_score %>% ggplot(aes(x = S1_imada_coding, y = S1_koster_coding)) + geom_point()