loading, setting up

library(googlesheets4) # install.packages("googlesheets4")
library(tidyverse)
library(janitor)
library(jmRtools)
d <- read_sheet("https://docs.google.com/spreadsheets/d/1uq6VCaAxCog3eKHt5rnCLF7bWwOUyLn12UEXSsFDFNQ/edit#gid=1041895723",
                sheet = 3, skip = 1, # and 5
                col_types = "c")

# d %>% write_csv("hadi-coded-data-all.csv")
# 
# d <- read_csv("hadi-coded-data-all.csv")

d <- d %>% clean_names()

# d <- d %>% 
 # filter(number_of_student_first_names_in_post != "DNE",
  #       number_of_student_first_names_in_post != "n/a")
create_table_output <- function(m1) {
  
  x0a <- coef(m1) %>% round(3)
    
  x0b <- confint(m1) %>% 
    round(3) %>% 
    paste0(collapse = " , ") %>% 
    str_c("[", ., "]")
  
  x1 <- convert_log_odds(coef(m1))
  
  x2 <- confint(m1) %>% 
    convert_log_odds() %>% 
    round(3) %>% 
    paste0(collapse = ", ") %>% 
    str_c("[", ., "]")
  
  x3 <- coef(m1) %>% 
    convert_log_odds() %>% 
    convert_odds() %>% 
    round(3)
  
  x4 <- confint(m1) %>% 
    convert_log_odds() %>% 
    convert_odds() %>% 
    round(3) %>% 
    paste0(collapse = ", ") %>% 
    str_c("[", ., "]")
  
  x5 <- coef(m1) %>% 
    convert_log_odds() %>% 
    convert_odds() %>% 
    round(3)
  
  x5 <- x5 * 20622917
  
  x6 <- confint(m1) %>%
    convert_log_odds() %>%
    convert_odds() %>%
    round(3)
  
  x6 <- x6 * 20622917
  
  x6 <- x6 %>% 
    paste0(collapse = ", ") %>%
    str_c("[", ., "]")

  tibble(log_odds_coef = x0a, log_odds_ci = x0b, 
         odds_coef = x1, odds_ci = x2,
         prob_coef = x3, prob_ci = x4,
         extrap_coef = x5,
         extrap_ci = x6) %>% 
    gather(key, val)
  
}
d <- d %>% 
  mutate(vid_or_not = 
           if_else(is_there_a_video_1_yes_0_no_only_count_embedded_videos_do_not_count_links_that_include_video == "1", "video",
                   if_else(is_there_a_video_1_yes_0_no_only_count_embedded_videos_do_not_count_links_that_include_video == "0", "not-video", NA))) %>% 
  
  mutate(there_is_a_face_in_this_post_video = if_else(vid_or_not == "video" & there_is_a_face_in_this_post == "1", 1, 0)) %>% 
  mutate(there_is_a_face_in_this_post_image = if_else(vid_or_not == "not-video" & there_is_a_face_in_this_post == "1", 1, 0)) %>% 
  
  mutate(is_there_an_identifiable_face_in_this_post_video = if_else(vid_or_not == "video" & is_there_an_identifiable_face_in_this_post == "1", 1, 0)) %>% 
  mutate(is_there_an_identifiable_face_in_this_post_image = if_else(vid_or_not == "not-video" & is_there_an_identifiable_face_in_this_post == "1", 1, 0)) %>% 
  
  mutate(ethnic_group_face_video = if_else(vid_or_not == "video" & ethnic_group_face == "1", 1, 0)) %>% 
  mutate(ethnic_group_face_image = if_else(vid_or_not == "not-video" & ethnic_group_face == "1", 1, 0)) %>% 
  
  mutate(gender_face_video = if_else(vid_or_not == "video" & gender_face == "1", 1, 0)) %>% 
  mutate(gender_face_image = if_else(vid_or_not == "not-video" & gender_face == "1", 1, 0))

videos

faces

d %>% janitor::tabyl(there_is_a_face_in_this_post_video)
##  there_is_a_face_in_this_post_video    n percent
##                                   0 1473   0.982
##                                   1   27   0.018
m1 <- glm(as.integer(there_is_a_face_in_this_post_video) ~ 1, data = d,
          family = "binomial")

create_table_output(m1)
## # A tibble: 8 × 2
##   key           val                     
##   <chr>         <chr>                   
## 1 log_odds_coef -3.999                  
## 2 log_odds_ci   [-4.405 , -3.64]        
## 3 odds_coef     0.018                   
## 4 odds_ci       [0.012, 0.026]          
## 5 prob_coef     0.018                   
## 6 prob_ci       [0.012, 0.025]          
## 7 extrap_coef   371212.506              
## 8 extrap_ci     [247475.004, 515572.925]

faces + first and/or last name

d %>% 
  janitor::tabyl(is_there_an_identifiable_face_in_this_post_video)
##  is_there_an_identifiable_face_in_this_post_video    n     percent
##                                                 0 1490 0.993333333
##                                                 1   10 0.006666667
m2 <- glm(as.integer(is_there_an_identifiable_face_in_this_post_video) ~ 1, data = d,
          family = "binomial")

create_table_output(m2)
## # A tibble: 8 × 2
##   key           val                    
##   <chr>         <chr>                  
## 1 log_odds_coef -5.004                 
## 2 log_odds_ci   [-5.697 , -4.44]       
## 3 odds_coef     0.007                  
## 4 odds_ci       [0.003, 0.012]         
## 5 prob_coef     0.007                  
## 6 prob_ci       [0.003, 0.012]         
## 7 extrap_coef   144360.419             
## 8 extrap_ci     [61868.751, 247475.004]

faces + ethnic group

d %>% 
  janitor::tabyl(ethnic_group_face_video)
##  ethnic_group_face_video    n percent
##                        0 1500       1
m3 <- glm(as.integer(ethnic_group_face_video) ~ 1, data = d,
          family = "binomial")

create_table_output(m3)
## # A tibble: 8 × 2
##   key           val                    
##   <chr>         <chr>                  
## 1 log_odds_coef -26.566                
## 2 log_odds_ci   [-9243.342 , -7890.816]
## 3 odds_coef     0                      
## 4 odds_ci       [0, 0]                 
## 5 prob_coef     0                      
## 6 prob_ci       [0, 0]                 
## 7 extrap_coef   0                      
## 8 extrap_ci     [0, 0]

faces + gender

d %>% janitor::tabyl(gender_face_video)
##  gender_face_video    n percent
##                  0 1497   0.998
##                  1    3   0.002
m4 <- glm(as.integer(gender_face_video) ~ 1, data = d,
          family = "binomial")

create_table_output(m4)
## # A tibble: 8 × 2
##   key           val              
##   <chr>         <chr>            
## 1 log_odds_coef -6.213           
## 2 log_odds_ci   [-7.605 , -5.259]
## 3 odds_coef     0.002            
## 4 odds_ci       [0, 0.005]       
## 5 prob_coef     0.002            
## 6 prob_ci       [0, 0.005]       
## 7 extrap_coef   41245.834        
## 8 extrap_ci     [0, 103114.585]

images

faces

d %>% janitor::tabyl(there_is_a_face_in_this_post_image)
##  there_is_a_face_in_this_post_image    n percent
##                                   0 1221   0.814
##                                   1  279   0.186
m1 <- glm(as.integer(there_is_a_face_in_this_post_image) ~ 1, data = d,
          family = "binomial")

create_table_output(m1)
## # A tibble: 8 × 2
##   key           val                       
##   <chr>         <chr>                     
## 1 log_odds_coef -1.476                    
## 2 log_odds_ci   [-1.608 , -1.348]         
## 3 odds_coef     0.186                     
## 4 odds_ci       [0.167, 0.206]            
## 5 prob_coef     0.157                     
## 6 prob_ci       [0.143, 0.171]            
## 7 extrap_coef   3237797.969               
## 8 extrap_ci     [2949077.131, 3526518.807]

faces + first and/or last name

d %>% 
  janitor::tabyl(is_there_an_identifiable_face_in_this_post_image)
##  is_there_an_identifiable_face_in_this_post_image    n      percent
##                                                 0 1449 0.9660000000
##                                                 1   50 0.0333333333
##                                                NA    1 0.0006666667
##  valid_percent
##     0.96664443
##     0.03335557
##             NA
m2 <- glm(as.integer(is_there_an_identifiable_face_in_this_post_image) ~ 1, data = d,
          family = "binomial")

create_table_output(m2)
## # A tibble: 8 × 2
##   key           val                     
##   <chr>         <chr>                   
## 1 log_odds_coef -3.367                  
## 2 log_odds_ci   [-3.662 , -3.096]       
## 3 odds_coef     0.033                   
## 4 odds_ci       [0.025, 0.043]          
## 5 prob_coef     0.032                   
## 6 prob_ci       [0.024, 0.041]          
## 7 extrap_coef   659933.344              
## 8 extrap_ci     [494950.008, 845539.597]

faces + ethnic group

d %>% 
  janitor::tabyl(ethnic_group_face_image)
##  ethnic_group_face_image    n     percent
##                        0 1498 0.998666667
##                        1    2 0.001333333
m3 <- glm(as.integer(ethnic_group_face_image) ~ 1, data = d,
          family = "binomial")

create_table_output(m3)
## # A tibble: 8 × 2
##   key           val             
##   <chr>         <chr>           
## 1 log_odds_coef -6.619          
## 2 log_odds_ci   [-8.414 , -5.49]
## 3 odds_coef     0.001           
## 4 odds_ci       [0, 0.004]      
## 5 prob_coef     0.001           
## 6 prob_ci       [0, 0.004]      
## 7 extrap_coef   20622.917       
## 8 extrap_ci     [0, 82491.668]

faces + gender

d %>% janitor::tabyl(gender_face_image)
##  gender_face_image    n    percent
##                  0 1469 0.97933333
##                  1   31 0.02066667
m4 <- glm(as.integer(gender_face_image) ~ 1, data = d,
          family = "binomial")

create_table_output(m4)
## # A tibble: 8 × 2
##   key           val                     
##   <chr>         <chr>                   
## 1 log_odds_coef -3.858                  
## 2 log_odds_ci   [-4.236 , -3.522]       
## 3 odds_coef     0.021                   
## 4 odds_ci       [0.014, 0.029]          
## 5 prob_coef     0.021                   
## 6 prob_ci       [0.014, 0.028]          
## 7 extrap_coef   433081.257              
## 8 extrap_ci     [288720.838, 577441.676]