Start matter

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.5     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(modelsummary)
library(emmeans)
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
library(dplyr)
library(ggplot2)
library(forcats)
library(broom)
library(gtsummary)
library(here)
## here() starts at /Users/heli/Library/CloudStorage/OneDrive-NORCE/TRUST AI CENTRE/PUBLICTRUST-AI/Experiment/Analysis
library(haven)
library(sandwich)
library(psych)
## 
## Attaching package: 'psych'
## 
## The following object is masked from 'package:modelsummary':
## 
##     SD
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(patchwork)

Data

data_raw <- read_sav(
  here::here("raw", "Norwegian Citizen Panel - round 36 - v-101-O.sav")
)

# Inspect the dataset
dim(data_raw)
## [1] 13971   464
names(data_raw)
##   [1] "responseid"                     "r36_rekruttert"                
##   [3] "r36_interview_start"            "r36_interview_end"             
##   [5] "r36_browsertype"                "r36_browserversion"            
##   [7] "r36_mobil"                      "r36_opplosning"                
##   [9] "r36_enhetstype"                 "r36_plgtkx_filter"             
##  [11] "r36_tellmx_filter"              "r36_advancedwifeaturesenabled" 
##  [13] "r36_getrenderingmode"           "r36_group"                     
##  [15] "r36_kjerne_ran"                 "r36_pcsak"                     
##  [17] "r36_pceck"                      "r36_pcsld"                     
##  [19] "r36_pcpak"                      "r36_pcpak_13_other"            
##  [21] "r36_pcpak_17_other"             "r36_pcsag"                     
##  [23] "r36_pcecs"                      "r36_pcsad"                     
##  [25] "r36_pcpar_raw"                  "r36_pcpar_14_other"            
##  [27] "r36_pc_order"                   "r36_pcpagx_ran"                
##  [29] "r36_pcpagx"                     "r36_redir"                     
##  [31] "r36_redit"                      "r36_dvrar"                     
##  [33] "r36_dvrago_pipe"                "r36_dvrago"                    
##  [35] "r36_dvrag"                      "r36_ceoos_ran"                 
##  [37] "r36_ceoos"                      "r36_ceows"                     
##  [39] "r36_cedeex_pipe1"               "r36_cedeex_ran1"               
##  [41] "r36_cedeex_pipe2"               "r36_cedeex_ran2"               
##  [43] "r36_cedeex_pipe3"               "r36_cedeex"                    
##  [45] "r36_cefofx2"                    "r36_cefoax2"                   
##  [47] "r36_cefopx2"                    "r36_cefotx2"                   
##  [49] "r36_plhom"                      "r36_plhom_4_other"             
##  [51] "r36_cerrh"                      "r36_cerrn"                     
##  [53] "r36_cehod"                      "r36_cesfe"                     
##  [55] "r36_tecoi_1"                    "r36_tecoi_2"                   
##  [57] "r36_plgtkx_name_ran"            "r36_plgtkx_name_order_ran"     
##  [59] "r36_plgtkx_name1"               "r36_plgtkx_name2"              
##  [61] "r36_plgtkx_name_pipe_1"         "r36_plgtkx_name_pipe_2"        
##  [63] "r36_plgtkx_views"               "r36_plgtkx_tema1"              
##  [65] "r36_plgtkx_tema2"               "r36_plgtkx_tema3"              
##  [67] "r36_plgtkx_vurdering1"          "r36_plgtkx_vurdering2"         
##  [69] "r36_plgtkx_vurdering_pipe_1"    "r36_plgtkx_vurdering_pipe_2"   
##  [71] "r36_plgtkx_qtext_order_ran"     "r36_plgtkx_qtext_pipe"         
##  [73] "r36_plgtkx"                     "r36_lgsia_lgsla_ran"           
##  [75] "r36_lgt_ran1"                   "r36_lgt_ran2"                  
##  [77] "r36_lgtpvx"                     "r36_lgtprx"                    
##  [79] "r36_lgtpbx"                     "r36_lgtptx"                    
##  [81] "r36_lgtpfx"                     "r36_lgtovx"                    
##  [83] "r36_lgtorx"                     "r36_lgtobx"                    
##  [85] "r36_lgtotx"                     "r36_lgtofx"                    
##  [87] "r36_powcr_1"                    "r36_powcr_2"                   
##  [89] "r36_powcr_3"                    "r36_powcr_4"                   
##  [91] "r36_powcr_5"                    "r36_powcr_6"                   
##  [93] "r36_powcr_7"                    "r36_powcr_8"                   
##  [95] "r36_powcr_9"                    "r36_powcr_10"                  
##  [97] "r36_pocpc"                      "r36_pocpr_1"                   
##  [99] "r36_pocpr_2"                    "r36_pocpr_3"                   
## [101] "r36_pocpr_4"                    "r36_pocpr_5"                   
## [103] "r36_pocpr_6"                    "r36_pocpr_7"                   
## [105] "r36_pocpr_8"                    "r36_pocpi_1"                   
## [107] "r36_pocpi_2"                    "r36_pocpi_3"                   
## [109] "r36_pocpi_4"                    "r36_pocpi_5"                   
## [111] "r36_pocpi_6"                    "r36_pocpi_7"                   
## [113] "r36_pocmi_1"                    "r36_pocmi_2"                   
## [115] "r36_pocmi_3"                    "r36_pocmi_4"                   
## [117] "r36_pocmi_5"                    "r36_pocmi_6"                   
## [119] "r36_pocmi_7"                    "r36_palovx_ran"                
## [121] "r36_papovx_ran"                 "r36_patovx_ran"                
## [123] "r36_palovx_papovx_patovx_order" "r36_score_ran"                 
## [125] "r36_cecdix1"                    "r36_cecdix2"                   
## [127] "r36_cecdix3"                    "r36_cecdwx1"                   
## [129] "r36_cecdwx2"                    "r36_cecdwx3"                   
## [131] "r36_cecdtx1"                    "r36_cecdtx2"                   
## [133] "r36_cecdtx3"                    "r36_cecdcx1"                   
## [135] "r36_cecdcx2"                    "r36_cecdcx3"                   
## [137] "r36_cecdfx1"                    "r36_cecdfx2"                   
## [139] "r36_cecdfx3"                    "r36_cecdjx1"                   
## [141] "r36_cecdjx2"                    "r36_cecdjx3"                   
## [143] "r36_ceste"                      "r36_cepos_1"                   
## [145] "r36_cepos_2"                    "r36_cepos_3"                   
## [147] "r36_cepos_4"                    "r36_cepos_5"                   
## [149] "r36_pisuy_ran"                  "r36_pisuy"                     
## [151] "r36_pitryx_ran"                 "r36_pitryx"                    
## [153] "r36_pifayx"                     "r36_piacyx_ran"                
## [155] "r36_piacyx1"                    "r36_pibeyx1"                   
## [157] "r36_pibsyx1"                    "r36_piacyx2"                   
## [159] "r36_pibeyx2"                    "r36_pibsyx2"                   
## [161] "r36_pisue"                      "r36_pitrex_ran"                
## [163] "r36_pitrex"                     "r36_pifaex"                    
## [165] "r36_piacex_ran"                 "r36_piacex1"                   
## [167] "r36_pibeex1"                    "r36_pibsex1"                   
## [169] "r36_piacex2"                    "r36_pibeex2"                   
## [171] "r36_pibsex2"                    "r36_ecshpx_ran"                
## [173] "r36_ecintx_pipe"                "r36_ecpasx"                    
## [175] "r36_ecintx"                     "r36_ecintx_originalvalue"      
## [177] "r36_ecintx_seen"                "r36_ecintx_back"               
## [179] "r36_ecprsx"                     "r36_cedeg_ran"                 
## [181] "r36_cedeg"                      "r36_cedew"                     
## [183] "r36_cedlax_pipe1"               "r36_cedlax_ran"                
## [185] "r36_cedlax_pipe2"               "r36_cedlax"                    
## [187] "r36_cefofx_intro_ran"           "r36_cefofx1"                   
## [189] "r36_cefoax1"                    "r36_ceforx1"                   
## [191] "r36_cefotx1"                    "r36_poimp_1"                   
## [193] "r36_poimp_2"                    "r36_poimp_3"                   
## [195] "r36_ceacrx_ran"                 "r36_ceacrx_1"                  
## [197] "r36_ceacrx_2"                   "r36_ceacrx_3"                  
## [199] "r36_ceacrx_4"                   "r36_ceacrx_5"                  
## [201] "r36_bgciv_raw"                  "r36_bgciv_7_other"             
## [203] "r36_plhpg"                      "r36_plhps"                     
## [205] "r36_plhpi"                      "r36_plhpi_13_other"            
## [207] "r36_plshp"                      "r36_plpag"                     
## [209] "r36_pldor_y"                    "r36_pldor_m"                   
## [211] "r36_plrea1_1"                   "r36_plrea1_2"                  
## [213] "r36_plrea1_3"                   "r36_plplr"                     
## [215] "r36_plpvi"                      "r36_plpvi_13_other"            
## [217] "r36_plpsp"                      "r36_cpmapox_ran"               
## [219] "r36_cpmapox"                    "r36_elnopx_ran"                
## [221] "r36_elnopx"                     "r36_elnoix_ran"                
## [223] "r36_elnoix"                     "r36_ecoor"                     
## [225] "r36_ecoor_7_other"              "r36_echrs"                     
## [227] "r36_echgs"                      "r36_ecges"                     
## [229] "r36_ecres"                      "r36_ecsvs"                     
## [231] "r36_ecder"                      "r36_tellmx_style"              
## [233] "r36_tellmx_sources"             "r36_tellmx_cond"               
## [235] "r36_tellmx_log"                 "r36_tellmx_clock"              
## [237] "r36_tellmx_endby"               "r36_tellmx_session"            
## [239] "r36_tellmx_log_sessiondata_1"   "r36_tellmx_log_sessiondata_2"  
## [241] "r36_tellmx_log_sessiondata_3"   "r36_tellmx_clock_sessiondata_1"
## [243] "r36_tellmx_clock_sessiondata_2" "r36_tellmx_clock_sessiondata_3"
## [245] "r36_tellmx_endby_sessiondata_1" "r36_tellmx_endby_sessiondata_2"
## [247] "r36_tellmx_endby_sessiondata_3" "r36_tellmx_n_q"                
## [249] "r36_tellmx_n_src"               "r36_tellmx_t_src"              
## [251] "r36_tellmx_n_src_exp"           "r36_tellmx_t_first"            
## [253] "r36_tellmx_q_seq"               "r36_tellmx_src_seq"            
## [255] "r36_tellmx_n_src_uniq"          "r36_tellmx_n_src_exp_uniq"     
## [257] "r36_tellmx_src_ms"              "r36_tellmx_summary"            
## [259] "r36_tecsex_1"                   "r36_tecsex_2"                  
## [261] "r36_tecsex_3"                   "r36_tecsex_4"                  
## [263] "r36_pcref"                      "r36_memca1"                    
## [265] "r36_memca2"                     "r36_memca3"                    
## [267] "r36_memca4"                     "r36_mepndx_ran"                
## [269] "r36_mepafx"                     "r36_melopx_1"                  
## [271] "r36_melopx_2"                   "r36_melopx_3"                  
## [273] "r36_melopx_4"                   "r36_cekcc"                     
## [275] "r36_ceexp_order"                "r36_ceexp_scale"               
## [277] "r36_ceacc_seen"                 "r36_ceacco_seen"               
## [279] "r36_ceacc_back"                 "r36_ceacco_back"               
## [281] "r36_ceacc_a_opprinnelig"        "r36_ceacc_b_opprinnelig"       
## [283] "r36_ceacco_opprinnelig"         "r36_ceacc_brotekst"            
## [285] "r36_ceacco_brotekst"            "r36_ceccs_1"                   
## [287] "r36_ceccs_2"                    "r36_ceccs_3"                   
## [289] "r36_ceccs_4"                    "r36_cecppx1_ccs1"              
## [291] "r36_cecppx1_ccs2"               "r36_cecppx1_havvind1"          
## [293] "r36_cecppx1_havvind2"           "r36_cecppx1_fossilenergi1"     
## [295] "r36_cecppx1_fossilenergi2"      "r36_cecppx1_energikostnad1"    
## [297] "r36_cecppx1_energikostnad2"     "r36_cecppx1_kompensasjon1"     
## [299] "r36_cecppx1_kompensasjon2"      "r36_cecppx1_overgordn1"        
## [301] "r36_cecppx1_overgordn2"         "r36_cecppx_roworder"           
## [303] "r36_cecppx_roworder_text"       "r36_cecppx1"                   
## [305] "r36_cecppx2_ccs1"               "r36_cecppx2_ccs2"              
## [307] "r36_cecppx2_havvind1"           "r36_cecppx2_havvind2"          
## [309] "r36_cecppx2_fossilenergi1"      "r36_cecppx2_fossilenergi2"     
## [311] "r36_cecppx2_energikostnad1"     "r36_cecppx2_energikostnad2"    
## [313] "r36_cecppx2_kompensasjon1"      "r36_cecppx2_kompensasjon2"     
## [315] "r36_cecppx2_overgordn1"         "r36_cecppx2_overgordn2"        
## [317] "r36_cecppx2"                    "r36_lgcsix_ran"                
## [319] "r36_lgcsix_intro_pipe"          "r36_lgcsix_1"                  
## [321] "r36_lgcsix_2"                   "r36_lgcsix_3"                  
## [323] "r36_lgcsix_4"                   "r36_lgcbex"                    
## [325] "r36_lgcopx_1"                   "r36_lgcopx_2"                  
## [327] "r36_lgcopx_3"                   "r36_lgcopx_4"                  
## [329] "r36_lgcopx_5"                   "r36_lgcsu_1"                   
## [331] "r36_lgcsu_2"                    "r36_lgcsu_3"                   
## [333] "r36_lgcsu_4"                    "r36_lgcsu_5"                   
## [335] "r36_lgcsu_6"                    "r36_lgccl1"                    
## [337] "r36_lgccl3_1"                   "r36_lgccl3_2"                  
## [339] "r36_lgccl3_3"                   "r36_lgccl3_4"                  
## [341] "r36_lgccl3_4_other"             "r36_lgccl3_5"                  
## [343] "r36_lgclk_1"                    "r36_lgclk_2"                   
## [345] "r36_lgclk_3"                    "r36_lgclk_4"                   
## [347] "r36_lgclk_5"                    "r36_lgclk_6"                   
## [349] "r36_lgclk_7"                    "r36_lgclk_8"                   
## [351] "r36_lgclk_9"                    "r36_lgclk_10"                  
## [353] "r36_wfunbx_ran1"                "r36_wfunbx_pipe1"              
## [355] "r36_wfunbx_pipe2"               "r36_wfunbx_ran2"               
## [357] "r36_wfunbx_ran3"                "r36_wfunbx_ran4"               
## [359] "r36_wfunbx_ran5"                "r36_wfunbx1"                   
## [361] "r36_wfunbx2"                    "r36_wfunbx_order"              
## [363] "r36_pounix_ranorder"            "r36_pounix_ran1"               
## [365] "r36_pounix_ran2"                "r36_pounix_pipe"               
## [367] "r36_poumax"                     "r36_poumwx"                    
## [369] "r36_poumtx"                     "r36_pomwax"                    
## [371] "r36_powhfx"                     "r36_po_order"                  
## [373] "r36_pounixs_seen"               "r36_pounixs_back"              
## [375] "r36_pounixs_originalvalue"      "r36_pounixs"                   
## [377] "r36_pcq_mask_1"                 "r36_pcq_mask_2"                
## [379] "r36_pcq_mask_3"                 "r36_pcq_mask_4"                
## [381] "r36_pcqdu"                      "r36_pcqua"                     
## [383] "r36_pcqes"                      "r36_pcqnr"                     
## [385] "r36_avslutt"                    "r36_lgsia"                     
## [387] "r36_lgsic"                      "r36_lgsla"                     
## [389] "r36_lgslc"                      "r36_palovx"                    
## [391] "r36_papovx"                     "r36_patovx"                    
## [393] "r36_ceacc_a"                    "r36_ceacc_b"                   
## [395] "r36_ceacco"                     "r36_cecrh"                     
## [397] "r36P1"                          "r36P2"                         
## [399] "r36P3"                          "r36P3_2"                       
## [401] "r36P4_1"                        "r36P4_2"                       
## [403] "r36P5_2"                        "r36P5_3"                       
## [405] "r36_Weight4"                    "r36_Weight4_stratapop"         
## [407] "r36_generic_stratapop"          "c34_bgupc"                     
## [409] "c34_bgupc_source"               "c34_bgurb"                     
## [411] "c34_bgurb_source"               "c34_bgedu3"                    
## [413] "c34_bgedu3_source"              "c34_bgedu"                     
## [415] "c34_bgedu_source"               "c36_bgciv"                     
## [417] "c36_bgciv_source"               "c34_bgcit"                     
## [419] "c34_bgcit_source"               "c34_bgimm"                     
## [421] "c34_bgimm_source"               "c26_bginc"                     
## [423] "c26_bginc_source"               "c34_bginc_v2"                  
## [425] "c34_bginc_v2_source"            "c34_bghea"                     
## [427] "c34_bghea_source"               "c34_bgcla"                     
## [429] "c34_bgcla_source"               "c34_bgchi"                     
## [431] "c34_bgchi_source"               "c34_bgrel_recode"              
## [433] "c34_bgrel_recode_source"        "c34_bgrel"                     
## [435] "c34_bgrem2"                     "c34_bgrem2_source"             
## [437] "c34_bgday"                      "c34_bgday_source"              
## [439] "c34_bgjsc"                      "c34_bgjsc_source"              
## [441] "c29_bgscp"                      "c29_bgscp_source"              
## [443] "c36_pcpar"                      "c36_pcpar_source"              
## [445] "c34_bglrs"                      "c34_bglrs_source"              
## [447] "r34_pcvot25"                    "r34_pccos"                     
## [449] "r34_pccoo"                      "r34_pcinc"                     
## [451] "r34_pcwet"                      "r28_pcvot23m"                  
## [453] "r28_pcvot23c"                   "r35_pccon"                     
## [455] "r35_pccop"                      "r35_pccoj"                     
## [457] "r35_pccob"                      "r35_pcref"                     
## [459] "r35_eqdiw"                      "r35_pcent"                     
## [461] "r35_porsm"                      "r35_pcgro"                     
## [463] "r35_pceum"                      "r35_pcsex"
# Inspect experimental variables
data_raw %>%
  select(
    r36_group,
    r36_lgt_ran1,
    r36_lgt_ran2,
    starts_with("r36_lgt")
  ) %>%
  glimpse()
## Rows: 13,971
## Columns: 13
## $ r36_group    <dbl+lbl> 5, 1, 5, 4, 5, 5, 3, 4, 3, 2, 1, 4, 3, 1, 4, 3, 1, 4,…
## $ r36_lgt_ran1 <dbl+lbl> NA, NA, NA, NA, NA, NA,  1, NA,  1, NA, NA, NA,  2, N…
## $ r36_lgt_ran2 <dbl+lbl> NA, NA, NA, NA, NA, NA,  5, NA,  4, NA, NA, NA,  2, N…
## $ r36_lgtpvx   <dbl+lbl> 98, 98, 98, 98, 98, 98,  4, 98,  6, 98, 98, 98, 98, 9…
## $ r36_lgtprx   <dbl+lbl> 98, 98, 98, 98, 98, 98,  6, 98,  4, 98, 98, 98, 98, 9…
## $ r36_lgtpbx   <dbl+lbl> 98, 98, 98, 98, 98, 98,  4, 98,  5, 98, 98, 98, 98, 9…
## $ r36_lgtptx   <dbl+lbl> 98, 98, 98, 98, 98, 98,  4, 98,  5, 98, 98, 98, 98, 9…
## $ r36_lgtpfx   <dbl+lbl> 98, 98, 98, 98, 98, 98,  4, 98,  6, 98, 98, 98, 98, 9…
## $ r36_lgtovx   <dbl+lbl> 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  3, 9…
## $ r36_lgtorx   <dbl+lbl> 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  3, 9…
## $ r36_lgtobx   <dbl+lbl> 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  4, 9…
## $ r36_lgtotx   <dbl+lbl> 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  3, 9…
## $ r36_lgtofx   <dbl+lbl> 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  2, 9…
# ============================================================
# 2. DATA PREPARATION
# ============================================================

data <- data_raw %>%

  # Retain respondents assigned to the experiment
  filter(r36_group == 3) %>%

  # Convert special missing-value codes to NA
  mutate(
    across(
      c(
        r36_lgtpvx, r36_lgtprx, r36_lgtpbx,
        r36_lgtptx, r36_lgtpfx,
        r36_lgtovx, r36_lgtorx, r36_lgtobx,
        r36_lgtotx, r36_lgtofx
      ),
      ~ na_if(as.numeric(.x), 97)
    ),
    across(
      c(
        r36_lgtpvx, r36_lgtprx, r36_lgtpbx,
        r36_lgtptx, r36_lgtpfx,
        r36_lgtovx, r36_lgtorx, r36_lgtobx,
        r36_lgtotx, r36_lgtofx
      ),
      ~ na_if(.x, 98)
    )
  ) %>%

  # Treatment variables
  mutate(
    perspective = factor(
      r36_lgt_ran1,
      levels = c(1, 2),
      labels = c("Participant", "Observer")
    ),

    ai_delegation = factor(
      r36_lgt_ran2,
      levels = 1:5,
      labels = c(
        "Human",
        "Assistant",
        "Advisor",
        "Partner",
        "Agent"
      )
    )
  )

# Check the number of respondents
nrow(data)
## [1] 2817
# Check treatment assignment
table(data$perspective, useNA = "ifany")
## 
## Participant    Observer 
##        1418        1399
table(data$ai_delegation, useNA = "ifany")
## 
##     Human Assistant   Advisor   Partner     Agent 
##       552       549       554       574       588
# Check the factorial distribution
table(
  data$perspective,
  data$ai_delegation,
  useNA = "ifany"
)
##              
##               Human Assistant Advisor Partner Agent
##   Participant   279       285     264     283   307
##   Observer      273       264     290     291   281
# Check whether assignments are complete
sum(is.na(data$perspective))
## [1] 0
sum(is.na(data$ai_delegation))
## [1] 0
# ============================================================
# 3. CONSTRUCT OUTCOME VARIABLES
# ============================================================

data <- data %>%

  mutate(

    # Combine participant and observer versions

    voice = coalesce(
      r36_lgtpvx,
      r36_lgtovx
    ),

    respect = coalesce(
      r36_lgtprx,
      r36_lgtorx
    ),

    bias = coalesce(
      r36_lgtpbx,
      r36_lgtobx
    ),

    trust = coalesce(
      r36_lgtptx,
      r36_lgtotx
    ),

    effectiveness = coalesce(
      r36_lgtpfx,
      r36_lgtofx
    )
  ) %>%

  # Reverse-code outcomes: higher = more positive evaluation
  mutate(
    across(
      c(voice, respect, bias, trust, effectiveness),
      ~ ifelse(.x %in% 1:7, 8 - .x, NA_real_)
    )
  )

# Descriptive statistics
data %>%
  summarise(
    across(
      c(voice, respect, bias, trust, effectiveness),
      list(
        N = ~ sum(!is.na(.x)),
        Mean = ~ mean(.x, na.rm = TRUE),
        SD = ~ sd(.x, na.rm = TRUE),
        Min = ~ min(.x, na.rm = TRUE),
        Max = ~ max(.x, na.rm = TRUE)
      )
    )
  )
## # A tibble: 1 × 25
##   voice_N voice_Mean voice_SD voice_Min voice_Max respect_N respect_Mean
##     <int>      <dbl>    <dbl>     <dbl>     <dbl>     <int>        <dbl>
## 1    2760       3.77     1.69         1         7      2762         3.90
## # ℹ 18 more variables: respect_SD <dbl>, respect_Min <dbl>, respect_Max <dbl>,
## #   bias_N <int>, bias_Mean <dbl>, bias_SD <dbl>, bias_Min <dbl>,
## #   bias_Max <dbl>, trust_N <int>, trust_Mean <dbl>, trust_SD <dbl>,
## #   trust_Min <dbl>, trust_Max <dbl>, effectiveness_N <int>,
## #   effectiveness_Mean <dbl>, effectiveness_SD <dbl>, effectiveness_Min <dbl>,
## #   effectiveness_Max <dbl>
# Check that respondents only answered the relevant perspective version

data %>%
  group_by(perspective) %>%
  summarise(
    n = n(),

    participant_responses = sum(!is.na(r36_lgtpvx)),
    observer_responses = sum(!is.na(r36_lgtovx)),

    .groups = "drop"
  )
## # A tibble: 2 × 4
##   perspective     n participant_responses observer_responses
##   <fct>       <int>                 <int>              <int>
## 1 Participant  1418                  1395                  0
## 2 Observer     1399                     0               1365
# ============================================================
# 4. FACTOR ANALYSIS: PROCEDURAL FAIRNESS
# ============================================================

fairness_items <- data %>%
  select(voice, respect, bias)

# Correlation matrix
cor(
  fairness_items,
  use = "pairwise.complete.obs"
)
##             voice   respect      bias
## voice   1.0000000 0.7495629 0.6615072
## respect 0.7495629 1.0000000 0.7609773
## bias    0.6615072 0.7609773 1.0000000
# Factor analysis (one-factor solution)
fa_results <- psych::fa(
  fairness_items,
  nfactors = 1,
  rotate = "none",
  fm = "minres",
  missing = FALSE
)

# Display results
print(fa_results)
## Factor Analysis using method =  minres
## Call: psych::fa(r = fairness_items, nfactors = 1, rotate = "none", 
##     missing = FALSE, fm = "minres")
## Standardized loadings (pattern matrix) based upon correlation matrix
##          MR1   h2   u2 com
## voice   0.81 0.65 0.35   1
## respect 0.93 0.86 0.14   1
## bias    0.82 0.67 0.33   1
## 
##                 MR1
## SS loadings    2.19
## Proportion Var 0.73
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## df null model =  3  with the objective function =  1.74 with Chi Square =  4886.97
## df of  the model are 0  and the objective function was  0 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  NA 
## 
## The harmonic n.obs is  2756 with the empirical chi square  0  with prob <  NA 
## The total n.obs was  2817  with Likelihood Chi Square =  0  with prob <  NA 
## 
## Tucker Lewis Index of factoring reliability =  -Inf
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    MR1
## Correlation of (regression) scores with factors   0.95
## Multiple R square of scores with factors          0.91
## Minimum correlation of possible factor scores     0.82
print(fa_results$loadings)
## 
## Loadings:
##         MR1  
## voice   0.807
## respect 0.929
## bias    0.819
## 
##                  MR1
## SS loadings    2.185
## Proportion Var 0.728
# Internal consistency
psych::alpha(fairness_items)
## 
## Reliability analysis   
## Call: psych::alpha(x = fairness_items)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##       0.89      0.89    0.85      0.72 7.9 0.0037  3.8 1.5     0.75
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.88  0.89  0.89
## Duhachek  0.88  0.89  0.89
## 
##  Reliability if an item is dropped:
##         raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## voice        0.86      0.86    0.76      0.76 6.4   0.0051    NA  0.76
## respect      0.80      0.80    0.66      0.66 3.9   0.0077    NA  0.66
## bias         0.86      0.86    0.75      0.75 6.0   0.0054    NA  0.75
## 
##  Item statistics 
##            n raw.r std.r r.cor r.drop mean  sd
## voice   2760  0.89  0.89  0.80   0.75  3.8 1.7
## respect 2762  0.93  0.93  0.88   0.83  3.9 1.8
## bias    2761  0.89  0.89  0.81   0.76  3.7 1.7
## 
## Non missing response frequency for each item
##            1    2    3    4    5    6    7 miss
## voice   0.10 0.17 0.16 0.23 0.14 0.16 0.04 0.02
## respect 0.11 0.16 0.14 0.19 0.16 0.19 0.05 0.02
## bias    0.11 0.17 0.17 0.21 0.17 0.14 0.03 0.02
# ============================================================
# CREATE INDEX
# ============================================================

# Inspect the factor analysis and determine whether the
# three items measure a sufficiently common dimension.

# If supported, construct the additive mean index.
data <- data %>%
  mutate(
    procedural_fairness = if_else(
      rowSums(!is.na(
        select(., voice, respect, bias)
      )) == 3,
      rowMeans(
        select(., voice, respect, bias),
        na.rm = TRUE
      ),
      NA_real_
    )
  )

# Descriptive statistics
summary(data$procedural_fairness)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.     NAs 
##   1.000   2.667   4.000   3.794   5.000   7.000      70
sd(data$procedural_fairness, na.rm = TRUE)
## [1] 1.540491

Regression analysis

# ============================================================
# 5. MAIN REGRESSION MODELS
# ============================================================

# Define outcome variables
outcomes <- c(
  "procedural_fairness",
  "voice",
  "respect",
  "bias",
  "trust",
  "effectiveness"
)

# Store models
models_main <- list()
models_interaction <- list()

for (y in outcomes) {

  # Model 1: Treatment effects
  formula_main <- as.formula(
    paste(y, "~ ai_delegation")
  )

  models_main[[y]] <- lm(
    formula_main,
    data = data
  )

  # Model 2: Treatment effects moderated by perspective
  formula_interaction <- as.formula(
    paste(y, "~ ai_delegation * perspective")
  )

  models_interaction[[y]] <- lm(
    formula_interaction,
    data = data
  )
}

# ============================================================
# DISPLAY RESULTS
# ============================================================

# Main models
summary(models_main$procedural_fairness)
## 
## Call:
## lm(formula = formula_main, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.9405 -1.1067  0.1074  1.0595  3.7855 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             4.94052    0.06133   80.55   <2e-16 ***
## ai_delegationAssistant -1.16714    0.08702  -13.41   <2e-16 ***
## ai_delegationAdvisor   -1.38130    0.08642  -15.98   <2e-16 ***
## ai_delegationPartner   -1.40600    0.08588  -16.37   <2e-16 ***
## ai_delegationAgent     -1.72607    0.08544  -20.20   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.423 on 2742 degrees of freedom
##   (70 observations deleted due to missingness)
## Multiple R-squared:  0.1484, Adjusted R-squared:  0.1472 
## F-statistic: 119.5 on 4 and 2742 DF,  p-value: < 2.2e-16
summary(models_main$trust)
## 
## Call:
## lm(formula = formula_main, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2444 -1.5381 -0.1235  1.3716  3.8765 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             5.24444    0.07150   73.34   <2e-16 ***
## ai_delegationAssistant -1.35868    0.10141  -13.40   <2e-16 ***
## ai_delegationAdvisor   -1.61603    0.10071  -16.05   <2e-16 ***
## ai_delegationPartner   -1.70639    0.10000  -17.06   <2e-16 ***
## ai_delegationAgent     -2.12097    0.09957  -21.30   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.662 on 2758 degrees of freedom
##   (54 observations deleted due to missingness)
## Multiple R-squared:  0.1586, Adjusted R-squared:  0.1573 
## F-statistic: 129.9 on 4 and 2758 DF,  p-value: < 2.2e-16
summary(models_main$effectiveness)
## 
## Call:
## lm(formula = formula_main, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.1447 -1.2669  0.0093  1.2578  3.7331 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             5.14471    0.06987   73.63   <2e-16 ***
## ai_delegationAssistant -1.15406    0.09900  -11.66   <2e-16 ***
## ai_delegationAdvisor   -1.40248    0.09846  -14.24   <2e-16 ***
## ai_delegationPartner   -1.61551    0.09767  -16.54   <2e-16 ***
## ai_delegationAgent     -1.87781    0.09718  -19.32   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.622 on 2758 degrees of freedom
##   (54 observations deleted due to missingness)
## Multiple R-squared:  0.1379, Adjusted R-squared:  0.1366 
## F-statistic: 110.3 on 4 and 2758 DF,  p-value: < 2.2e-16
# Interaction models
summary(models_interaction$procedural_fairness)
## 
## Call:
## lm(formula = formula_interaction, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.0237 -1.1030  0.0164  0.9951  3.8970 
## 
## Coefficients:
##                                            Estimate Std. Error t value Pr(>|t|)
## (Intercept)                                 4.85855    0.08636  56.260   <2e-16
## ai_delegationAssistant                     -1.06165    0.12125  -8.756   <2e-16
## ai_delegationAdvisor                       -1.39878    0.12329 -11.345   <2e-16
## ai_delegationPartner                       -1.36096    0.12157 -11.194   <2e-16
## ai_delegationAgent                         -1.75556    0.11905 -14.747   <2e-16
## perspectiveObserver                         0.16517    0.12259   1.347    0.178
## ai_delegationAssistant:perspectiveObserver -0.21471    0.17404  -1.234    0.217
## ai_delegationAdvisor:perspectiveObserver    0.02535    0.17281   0.147    0.883
## ai_delegationPartner:perspectiveObserver   -0.09233    0.17166  -0.538    0.591
## ai_delegationAgent:perspectiveObserver      0.07009    0.17088   0.410    0.682
##                                               
## (Intercept)                                ***
## ai_delegationAssistant                     ***
## ai_delegationAdvisor                       ***
## ai_delegationPartner                       ***
## ai_delegationAgent                         ***
## perspectiveObserver                           
## ai_delegationAssistant:perspectiveObserver    
## ai_delegationAdvisor:perspectiveObserver      
## ai_delegationPartner:perspectiveObserver      
## ai_delegationAgent:perspectiveObserver        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.422 on 2737 degrees of freedom
##   (70 observations deleted due to missingness)
## Multiple R-squared:  0.1511, Adjusted R-squared:  0.1484 
## F-statistic: 54.15 on 9 and 2737 DF,  p-value: < 2.2e-16
summary(models_interaction$trust)
## 
## Call:
## lm(formula = formula_interaction, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.284 -1.507 -0.106  1.421  3.894 
## 
## Coefficients:
##                                            Estimate Std. Error t value Pr(>|t|)
## (Intercept)                                 5.20588    0.10081  51.642   <2e-16
## ai_delegationAssistant                     -1.25588    0.14154  -8.873   <2e-16
## ai_delegationAdvisor                       -1.62734    0.14406 -11.297   <2e-16
## ai_delegationPartner                       -1.63549    0.14192 -11.524   <2e-16
## ai_delegationAgent                         -2.09992    0.13898 -15.110   <2e-16
## perspectiveObserver                         0.07770    0.14309   0.543    0.587
## ai_delegationAssistant:perspectiveObserver -0.21274    0.20305  -1.048    0.295
## ai_delegationAdvisor:perspectiveObserver    0.01737    0.20165   0.086    0.931
## ai_delegationPartner:perspectiveObserver   -0.14115    0.20013  -0.705    0.481
## ai_delegationAgent:perspectiveObserver     -0.04080    0.19938  -0.205    0.838
##                                               
## (Intercept)                                ***
## ai_delegationAssistant                     ***
## ai_delegationAdvisor                       ***
## ai_delegationPartner                       ***
## ai_delegationAgent                         ***
## perspectiveObserver                           
## ai_delegationAssistant:perspectiveObserver    
## ai_delegationAdvisor:perspectiveObserver      
## ai_delegationPartner:perspectiveObserver      
## ai_delegationAgent:perspectiveObserver        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.663 on 2753 degrees of freedom
##   (54 observations deleted due to missingness)
## Multiple R-squared:  0.1591, Adjusted R-squared:  0.1564 
## F-statistic:  57.9 on 9 and 2753 DF,  p-value: < 2.2e-16
summary(models_interaction$effectiveness)
## 
## Call:
## lm(formula = formula_interaction, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.202 -1.202  0.102  1.154  3.822 
## 
## Coefficients:
##                                            Estimate Std. Error t value Pr(>|t|)
## (Intercept)                                 5.08856    0.09851  51.653  < 2e-16
## ai_delegationAssistant                     -1.01356    0.13820  -7.334 2.92e-13
## ai_delegationAdvisor                       -1.46021    0.14065 -10.382  < 2e-16
## ai_delegationPartner                       -1.55619    0.13844 -11.241  < 2e-16
## ai_delegationAgent                         -1.91093    0.13549 -14.104  < 2e-16
## perspectiveObserver                         0.11293    0.13971   0.808    0.419
## ai_delegationAssistant:perspectiveObserver -0.28989    0.19805  -1.464    0.143
## ai_delegationAdvisor:perspectiveObserver    0.10487    0.19695   0.532    0.594
## ai_delegationPartner:perspectiveObserver   -0.11917    0.19530  -0.610    0.542
## ai_delegationAgent:perspectiveObserver      0.07574    0.19443   0.390    0.697
##                                               
## (Intercept)                                ***
## ai_delegationAssistant                     ***
## ai_delegationAdvisor                       ***
## ai_delegationPartner                       ***
## ai_delegationAgent                         ***
## perspectiveObserver                           
## ai_delegationAssistant:perspectiveObserver    
## ai_delegationAdvisor:perspectiveObserver      
## ai_delegationPartner:perspectiveObserver      
## ai_delegationAgent:perspectiveObserver        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.622 on 2753 degrees of freedom
##   (54 observations deleted due to missingness)
## Multiple R-squared:   0.14,  Adjusted R-squared:  0.1372 
## F-statistic: 49.78 on 9 and 2753 DF,  p-value: < 2.2e-16
# Regression tables
modelsummary(
  models_main,
  stars = TRUE,
  statistic = "({std.error})",
  title = "Treatment Effects on Outcomes"
)
Treatment Effects on Outcomes
procedural_fairness voice respect bias trust effectiveness
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
(Intercept) 4.941*** 4.965*** 5.179*** 4.677*** 5.244*** 5.145***
(0.061) (0.067) (0.070) (0.069) (0.072) (0.070)
ai_delegationAssistant -1.167*** -1.178*** -1.318*** -0.998*** -1.359*** -1.154***
(0.087) (0.096) (0.099) (0.097) (0.101) (0.099)
ai_delegationAdvisor -1.381*** -1.466*** -1.558*** -1.123*** -1.616*** -1.402***
(0.086) (0.095) (0.099) (0.097) (0.101) (0.098)
ai_delegationPartner -1.406*** -1.449*** -1.500*** -1.255*** -1.706*** -1.616***
(0.086) (0.094) (0.098) (0.096) (0.100) (0.098)
ai_delegationAgent -1.726*** -1.820*** -1.986*** -1.387*** -2.121*** -1.878***
(0.085) (0.094) (0.098) (0.095) (0.100) (0.097)
Num.Obs. 2747 2760 2762 2761 2763 2763
R2 0.148 0.137 0.145 0.087 0.159 0.138
R2 Adj. 0.147 0.135 0.144 0.086 0.157 0.137
AIC 9739.2 10326.1 10538.8 10408.8 10654.1 10521.5
BIC 9774.7 10361.7 10574.4 10444.3 10689.6 10557.1
Log.Lik. -4863.597 -5157.069 -5263.407 -5198.395 -5321.028 -5254.760
F 119.498 109.020 117.182 65.770 129.937 110.276
RMSE 1.42 1.57 1.63 1.59 1.66 1.62
modelsummary(
  models_interaction,
  stars = TRUE,
  statistic = "({std.error})",
  title = "Treatment Effects by Perspective"
)
Treatment Effects by Perspective
procedural_fairness voice respect bias trust effectiveness
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
(Intercept) 4.859*** 4.916*** 5.081*** 4.579*** 5.206*** 5.089***
(0.086) (0.095) (0.099) (0.097) (0.101) (0.099)
ai_delegationAssistant -1.062*** -1.144*** -1.159*** -0.866*** -1.256*** -1.014***
(0.121) (0.133) (0.138) (0.136) (0.142) (0.138)
ai_delegationAdvisor -1.399*** -1.548*** -1.560*** -1.087*** -1.627*** -1.460***
(0.123) (0.136) (0.141) (0.138) (0.144) (0.141)
ai_delegationPartner -1.361*** -1.416*** -1.529*** -1.117*** -1.635*** -1.556***
(0.122) (0.134) (0.139) (0.136) (0.142) (0.138)
ai_delegationAgent -1.756*** -1.909*** -1.995*** -1.362*** -2.100*** -1.911***
(0.119) (0.131) (0.136) (0.133) (0.139) (0.135)
perspectiveObserver 0.165 0.099 0.198 0.197 0.078 0.113
(0.123) (0.135) (0.140) (0.137) (0.143) (0.140)
ai_delegationAssistant × perspectiveObserver -0.215 -0.067 -0.324 -0.268 -0.213 -0.290
(0.174) (0.191) (0.199) (0.195) (0.203) (0.198)
ai_delegationAdvisor × perspectiveObserver 0.025 0.152 -0.007 -0.079 0.017 0.105
(0.173) (0.190) (0.197) (0.193) (0.202) (0.197)
ai_delegationPartner × perspectiveObserver -0.092 -0.068 0.051 -0.276 -0.141 -0.119
(0.172) (0.189) (0.196) (0.192) (0.200) (0.195)
ai_delegationAgent × perspectiveObserver 0.070 0.193 0.027 -0.045 -0.041 0.076
(0.171) (0.188) (0.195) (0.191) (0.199) (0.194)
Num.Obs. 2747 2760 2762 2761 2763 2763
R2 0.151 0.140 0.149 0.089 0.159 0.140
R2 Adj. 0.148 0.137 0.146 0.086 0.156 0.137
AIC 9740.5 10327.0 10538.1 10414.0 10662.2 10524.9
BIC 9805.6 10392.2 10603.2 10479.2 10727.3 10590.0
Log.Lik. -4859.240 -5152.499 -5258.035 -5196.023 -5320.076 -5251.425
F 54.148 49.540 53.381 29.754 57.896 49.780
RMSE 1.42 1.57 1.62 1.59 1.66 1.62
# ============================================================
# 6. PLANNED CONTRASTS: H1, H2 AND H3
# ============================================================

# Define contrasts
planned_contrasts <- list(

  # H1: Any AI involvement vs. human-only decision-making
  H1_AI_vs_Human = c(
    -1, 1/4, 1/4, 1/4, 1/4
  ),

  # H2: Linear increase in AI delegation
  H2_Linear_Trend = c(
    -2, -1, 0, 1, 2
  ),

  # H3: AI directly participates in determining the fine
  # Partner and Agent vs. Human, Assistant and Advisor
  H3_Direct_AI_vs_Human_Control = c(
    -1/3, -1/3, -1/3, 1/2, 1/2
  )
)

# Function to estimate contrasts for each outcome
run_contrasts <- function(model) {

  emm <- emmeans(
    model,
    ~ ai_delegation
  )

  contrast(
    emm,
    method = planned_contrasts,
    adjust = "none"
  ) %>%
    summary(
      infer = c(TRUE, TRUE)
    )
}

# Run contrasts for all outcomes
contrast_results <- lapply(
  models_main,
  run_contrasts
)

# Display results
contrast_results$procedural_fairness
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.420 0.0684 2742   -1.554   -1.286 -20.762
##  H2_Linear_Trend                 -3.691 0.1910 2742   -4.066   -3.316 -19.287
##  H3_Direct_AI_vs_Human_Control   -0.717 0.0551 2742   -0.825   -0.608 -12.993
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
contrast_results$trust
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.701 0.0797 2758    -1.86   -1.544 -21.330
##  H2_Linear_Trend                 -4.590 0.2230 2758    -5.03   -4.152 -20.584
##  H3_Direct_AI_vs_Human_Control   -0.922 0.0642 2758    -1.05   -0.796 -14.360
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
contrast_results$effectiveness
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.512 0.0779 2758    -1.67   -1.360 -19.418
##  H2_Linear_Trend                 -4.217 0.2180 2758    -4.64   -3.790 -19.380
##  H3_Direct_AI_vs_Human_Control   -0.894 0.0627 2758    -1.02   -0.772 -14.272
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
# Combine results into one table
contrast_table <- bind_rows(
  lapply(names(contrast_results), function(y) {

    as.data.frame(contrast_results[[y]]) %>%
      mutate(outcome = y)

  }),
  .id = NULL
)

contrast_table
##                         contrast   estimate         SE   df   lower.CL
## 1                 H1_AI_vs_Human -1.4201259 0.06839989 2742 -1.5542464
## 2                H2_Linear_Trend -3.6909962 0.19137459 2742 -4.0662491
## 3  H3_Direct_AI_vs_Human_Control -0.7165528 0.05514776 2742 -0.8246882
## 4                 H1_AI_vs_Human -1.4783400 0.07523976 2755 -1.6258720
## 5                H2_Linear_Trend -3.9111205 0.21055755 2755 -4.3239871
## 6  H3_Direct_AI_vs_Human_Control -0.7532158 0.06067556 2755 -0.8721900
## 7                 H1_AI_vs_Human -1.5905450 0.07808016 2757 -1.7436465
## 8                H2_Linear_Trend -4.1541808 0.21852616 2757 -4.5826723
## 9  H3_Direct_AI_vs_Human_Control -0.7843878 0.06295626 2757 -0.9078340
## 10                H1_AI_vs_Human -1.1909737 0.07642691 2756 -1.3408335
## 11               H2_Linear_Trend -3.0316875 0.21362814 2756 -3.4505749
## 12 H3_Direct_AI_vs_Human_Control -0.6140713 0.06152622 2756 -0.7347135
## 13                H1_AI_vs_Human -1.7005158 0.07972320 2758 -1.8568390
## 14               H2_Linear_Trend -4.5896471 0.22296764 2758 -5.0268475
## 15 H3_Direct_AI_vs_Human_Control -0.9221102 0.06421365 2758 -1.0480219
## 16                H1_AI_vs_Human -1.5124660 0.07788887 2758 -1.6651924
## 17               H2_Linear_Trend -4.2170800 0.21759968 2758 -4.6437548
## 18 H3_Direct_AI_vs_Human_Control -0.8944817 0.06267560 2758 -1.0173775
##      upper.CL    t.ratio      p.value             outcome
## 1  -1.2860054 -20.762109 4.765530e-89 procedural_fairness
## 2  -3.3157433 -19.286763 7.902114e-78 procedural_fairness
## 3  -0.6084175 -12.993326 1.670008e-37 procedural_fairness
## 4  -1.3308079 -19.648387 1.517406e-80               voice
## 5  -3.4982539 -18.575066 1.168782e-72               voice
## 6  -0.6342417 -12.413826 1.804583e-34               voice
## 7  -1.4374435 -20.370667 4.823646e-86             respect
## 8  -3.7256893 -19.009994 8.117190e-76             respect
## 9  -0.6609416 -12.459251 1.051824e-34             respect
## 10 -1.0411139 -15.583174 1.548339e-52                bias
## 11 -2.6128001 -14.191424 3.584668e-44                bias
## 12 -0.4934292  -9.980644 4.541493e-23                bias
## 13 -1.5441926 -21.330252 1.440473e-93               trust
## 14 -4.1524467 -20.584364 1.066028e-87               trust
## 15 -0.7961985 -14.360034 3.760357e-45               trust
## 16 -1.3597396 -19.418255 7.855515e-79       effectiveness
## 17 -3.7904052 -19.379992 1.512116e-78       effectiveness
## 18 -0.7715858 -14.271609 1.228666e-44       effectiveness
# ============================================================
# 7. H4: INTERACTION TESTS
# ============================================================

# Compare models with and without interactions
interaction_tests <- lapply(outcomes, function(y) {

  model_without <- models_main[[y]]
  model_with <- models_interaction[[y]]

  test <- anova(
    model_without,
    model_with
  )

  data.frame(
    outcome = y,
    F = test$F[2],
    p_value = test$`Pr(>F)`[2]
  )
})

interaction_table <- bind_rows(interaction_tests)

interaction_table
##               outcome         F    p_value
## 1 procedural_fairness 1.7391911 0.12222231
## 2               voice 1.8246677 0.10463314
## 3             respect 2.1454448 0.05739435
## 4                bias 0.9461324 0.44981759
## 5               trust 0.3795028 0.86308533
## 6       effectiveness 1.3305254 0.24814427
# ============================================================
# TREATMENT EFFECTS SEPARATELY BY PERSPECTIVE
# ============================================================

# Estimate treatment effects within each perspective
perspective_effects <- lapply(outcomes, function(y) {

  emm <- emmeans(
    models_interaction[[y]],
    ~ ai_delegation | perspective
  )

  contrast(
    emm,
    method = planned_contrasts,
    adjust = "none"
  ) %>%
    summary(
      infer = c(TRUE, TRUE)
    )

})

names(perspective_effects) <- outcomes

# Example: procedural fairness
perspective_effects$procedural_fairness
## perspective = Participant:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.394 0.0963 2737    -1.58   -1.205 -14.480
##  H2_Linear_Trend                 -3.810 0.2670 2737    -4.33   -3.287 -14.275
##  H3_Direct_AI_vs_Human_Control   -0.738 0.0775 2737    -0.89   -0.586  -9.527
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## perspective = Observer:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.447 0.0971 2737    -1.64   -1.257 -14.906
##  H2_Linear_Trend                 -3.548 0.2740 2737    -4.09   -3.010 -12.934
##  H3_Direct_AI_vs_Human_Control   -0.686 0.0785 2737    -0.84   -0.532  -8.739
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
# Example: trust
perspective_effects$trust
## perspective = Participant:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.655 0.1120 2753    -1.88   -1.434 -14.720
##  H2_Linear_Trend                 -4.579 0.3120 2753    -5.19   -3.968 -14.696
##  H3_Direct_AI_vs_Human_Control   -0.907 0.0905 2753    -1.08   -0.729 -10.021
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## perspective = Observer:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.749 0.1130 2753    -1.97   -1.527 -15.443
##  H2_Linear_Trend                 -4.589 0.3200 2753    -5.22   -3.963 -14.354
##  H3_Direct_AI_vs_Human_Control   -0.932 0.0914 2753    -1.11   -0.753 -10.203
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
# Example: effectiveness
perspective_effects$effectiveness
## perspective = Participant:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.485 0.1100 2753    -1.70   -1.270 -13.528
##  H2_Linear_Trend                 -4.364 0.3040 2753    -4.96   -3.769 -14.368
##  H3_Direct_AI_vs_Human_Control   -0.909 0.0881 2753    -1.08   -0.736 -10.312
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## perspective = Observer:
##  contrast                      estimate     SE   df lower.CL upper.CL t.ratio
##  H1_AI_vs_Human                  -1.542 0.1100 2753    -1.76   -1.326 -13.959
##  H2_Linear_Trend                 -4.042 0.3120 2753    -4.65   -3.431 -12.961
##  H3_Direct_AI_vs_Human_Control   -0.869 0.0892 2753    -1.04   -0.694  -9.742
##  p.value
##  <0.0001
##  <0.0001
##  <0.0001
## 
## Confidence level used: 0.95
# ============================================================
# FORMAL TESTS OF DIFFERENCES BETWEEN PERSPECTIVES
# ============================================================

perspective_contrast_differences <- lapply(outcomes, function(y) {

  emm <- emmeans(
    models_interaction[[y]],
    ~ ai_delegation | perspective
  )

  # Calculate H1, H2 and H3 separately by perspective
  treatment_contrasts <- contrast(
    emm,
    method = planned_contrasts,
    by = "perspective",
    adjust = "none"
  )

  # Compare each contrast between perspectives
  contrast(
    treatment_contrasts,
    method = "revpairwise",
    by = "contrast",
    adjust = "none"
  ) %>%
    summary(infer = c(TRUE, TRUE))

})

names(perspective_contrast_differences) <- outcomes

# Example
perspective_contrast_differences$procedural_fairness
## contrast = H1_AI_vs_Human:
##  contrast1              estimate    SE   df lower.CL upper.CL t.ratio p.value
##  Observer - Participant  -0.0529 0.137 2737   -0.321    0.215  -0.387  0.6989
## 
## contrast = H2_Linear_Trend:
##  contrast1              estimate    SE   df lower.CL upper.CL t.ratio p.value
##  Observer - Participant   0.2626 0.383 2737   -0.488    1.013   0.686  0.4928
## 
## contrast = H3_Direct_AI_vs_Human_Control:
##  contrast1              estimate    SE   df lower.CL upper.CL t.ratio p.value
##  Observer - Participant   0.0520 0.110 2737   -0.164    0.268   0.471  0.6374
## 
## Confidence level used: 0.95

Sample size and missing data

# ============================================================
# 10. SAMPLE SIZE AND MISSING DATA
# ============================================================

# Number of respondents in experimental group
n_experiment <- nrow(data)

# Number with valid treatment assignments
n_assigned <- sum(
  !is.na(data$perspective) &
  !is.na(data$ai_delegation)
)

# Number of complete observations for each outcome
sample_sizes <- data %>%
  summarise(
    across(
      all_of(outcomes),
      ~ sum(
        !is.na(.) &
        !is.na(perspective) &
        !is.na(ai_delegation)
      )
    )
  ) %>%
  pivot_longer(
    everything(),
    names_to = "outcome",
    values_to = "N"
  )

# Display sample sizes
cat("Experimental sample:", n_experiment, "\n")
## Experimental sample: 2817
cat("Valid treatment assignments:", n_assigned, "\n")
## Valid treatment assignments: 2817
sample_sizes
## # A tibble: 6 × 2
##   outcome                 N
##   <chr>               <int>
## 1 procedural_fairness  2747
## 2 voice                2760
## 3 respect              2762
## 4 bias                 2761
## 5 trust                2763
## 6 effectiveness        2763
# Sample sizes by treatment condition
data %>%
  group_by(perspective, ai_delegation) %>%
  summarise(
    N = n(),
    fairness_N = sum(!is.na(procedural_fairness)),
    trust_N = sum(!is.na(trust)),
    effectiveness_N = sum(!is.na(effectiveness)),
    .groups = "drop"
  )
## # A tibble: 10 × 6
##    perspective ai_delegation     N fairness_N trust_N effectiveness_N
##    <fct>       <fct>         <int>      <int>   <int>           <int>
##  1 Participant Human           279        271     272             271
##  2 Participant Assistant       285        279     280             280
##  3 Participant Advisor         264        261     261             261
##  4 Participant Partner         283        276     277             278
##  5 Participant Agent           307        301     302             304
##  6 Observer    Human           273        267     268             268
##  7 Observer    Assistant       264        252     254             255
##  8 Observer    Advisor         290        285     288             286
##  9 Observer    Partner         291        284     288             287
## 10 Observer    Agent           281        271     273             273

Visualizations

# Outcomes to visualize
outcomes_plot <- c(
  "procedural_fairness",
  "trust",
  "effectiveness",
  "voice",
  "respect",
  "bias"
)

# Extract estimated marginal means
get_emm_data <- function(model, outcome_name) {

  emmeans(model, ~ ai_delegation) %>%
    confint() %>%
    as.data.frame() %>%
    mutate(outcome = outcome_name)

}

# Extract results from main models
emm_main <- map_dfr(
  outcomes_plot,
  function(y) {
    get_emm_data(
      models_main[[y]],
      y
    )
  }
)

# Inspect results
head(emm_main)
##   ai_delegation   emmean         SE   df lower.CL upper.CL             outcome
## 1         Human 4.940520 0.06133254 2742 4.820258 5.060783 procedural_fairness
## 2     Assistant 3.773384 0.06173548 2742 3.652331 3.894436 procedural_fairness
## 3       Advisor 3.559219 0.06088156 2742 3.439840 3.678597 procedural_fairness
## 4       Partner 3.534524 0.06011573 2742 3.416647 3.652401 procedural_fairness
## 5         Agent 3.214452 0.05948180 2742 3.097819 3.331086 procedural_fairness
## 6         Human 5.244444 0.07150399 2758 5.104238 5.384651               trust
# Main plot: Procedural fairness

p_fairness <- ggplot(
  filter(emm_main, outcome == "procedural_fairness"),
  aes(
    x = ai_delegation,
    y = emmean,
    group = 1
  )
) +

  geom_line(
    linewidth = 0.9,
    color = "steelblue4"
  ) +

  geom_point(
    size = 3,
    color = "steelblue4"
  ) +

  geom_errorbar(
    aes(
      ymin = lower.CL,
      ymax = upper.CL
    ),
    width = 0.12,
    linewidth = 0.7
  ) +

  scale_y_continuous(
    limits = c(1, 7),
    breaks = 1:7
  ) +

  labs(
    title = "Perceived procedural fairness",
    subtitle = "Estimated marginal means with 95% confidence intervals",
    x = "Decision-making arrangement",
    y = "Procedural fairness (1–7)"
  ) +

  theme_minimal(base_size = 13) +

  theme(
    plot.title = element_text(face = "bold"),
    axis.text.x = element_text(
      angle = 25,
      hjust = 1
    ),
    panel.grid.minor = element_blank()
  )

p_fairness

# Function for individual outcome plots

plot_outcome <- function(outcome_name, plot_title) {

  ggplot(
    filter(emm_main, outcome == outcome_name),
    aes(
      x = ai_delegation,
      y = emmean,
      group = 1
    )
  ) +

    geom_line(
      linewidth = 0.9,
      color = "steelblue4"
    ) +

    geom_point(
      size = 3,
      color = "steelblue4"
    ) +

    geom_errorbar(
      aes(
        ymin = lower.CL,
        ymax = upper.CL
      ),
      width = 0.12
    ) +

    scale_y_continuous(
      limits = c(1, 7),
      breaks = 1:7
    ) +

    labs(
      title = plot_title,
      x = "Decision-making arrangement",
      y = "Mean evaluation (1–7)"
    ) +

    theme_minimal(base_size = 12) +

    theme(
      plot.title = element_text(face = "bold"),
      axis.text.x = element_text(
        angle = 25,
        hjust = 1
      ),
      panel.grid.minor = element_blank()
    )
}

p_trust <- plot_outcome(
  "trust",
  "Trustworthiness"
)

p_effectiveness <- plot_outcome(
  "effectiveness",
  "Perceived effectiveness"
)

p_trust

p_effectiveness

# Extract marginal means by perspective

get_interaction_emm <- function(model, outcome_name) {

  emmeans(
    model,
    ~ ai_delegation | perspective
  ) %>%
    confint() %>%
    as.data.frame() %>%
    mutate(outcome = outcome_name)

}

emm_interaction <- map_dfr(
  outcomes_plot,
  function(y) {
    get_interaction_emm(
      models_interaction[[y]],
      y
    )
  }
)

# Function for perspective plots

plot_perspective <- function(outcome_name, plot_title) {

  ggplot(
    filter(
      emm_interaction,
      outcome == outcome_name
    ),
    aes(
      x = ai_delegation,
      y = emmean,
      color = perspective,
      group = perspective
    )
  ) +

    geom_line(linewidth = 1) +

    geom_point(size = 3) +

    geom_errorbar(
      aes(
        ymin = lower.CL,
        ymax = upper.CL
      ),
      width = 0.10
    ) +

    scale_y_continuous(
      limits = c(1, 7),
      breaks = 1:7
    ) +

    scale_color_manual(
      values = c(
        "Participant" = "#2166AC",
        "Observer" = "#D6604D"
      )
    ) +

    labs(
      title = plot_title,
      x = "Decision-making arrangement",
      y = "Mean evaluation (1–7)",
      color = "Perspective"
    ) +

    theme_minimal(base_size = 12) +

    theme(
      plot.title = element_text(face = "bold"),
      axis.text.x = element_text(
        angle = 25,
        hjust = 1
      ),
      panel.grid.minor = element_blank()
    )
}

p_fairness_perspective <- plot_perspective(
  "procedural_fairness",
  "Procedural fairness by perspective"
)

p_trust_perspective <- plot_perspective(
  "trust",
  "Trustworthiness by perspective"
)

p_effectiveness_perspective <- plot_perspective(
  "effectiveness",
  "Effectiveness by perspective"
)

p_fairness_perspective

p_trust_perspective

p_effectiveness_perspective

# Combined overview of all outcomes
## Prepare labels
emm_all <- emm_main %>%
  mutate(
    outcome = recode(
      outcome,
      "procedural_fairness" = "Procedural fairness",
      "trust" = "Trustworthiness",
      "effectiveness" = "Effectiveness",
      "voice" = "Voice",
      "respect" = "Dignity and respect",
      "bias" = "Freedom from bias"
    )
  )

# Combined figure
p_all_outcomes <- ggplot(
  emm_all,
  aes(
    x = ai_delegation,
    y = emmean,
    group = 1
  )
) +

  geom_line(
    color = "steelblue4",
    linewidth = 0.8
  ) +

  geom_point(
    color = "steelblue4",
    size = 2.5
  ) +

  geom_errorbar(
    aes(
      ymin = lower.CL,
      ymax = upper.CL
    ),
    width = 0.10
  ) +

  facet_wrap(
    ~ outcome,
    ncol = 2
  ) +

  scale_y_continuous(
    limits = c(1, 7),
    breaks = 1:7
  ) +

  labs(
    title = "Public evaluations of AI involvement in judicial decision-making",
    subtitle = "Estimated marginal means and 95% confidence intervals",
    x = "Decision-making arrangement",
    y = "Mean evaluation (1–7)"
  ) +

  theme_minimal(base_size = 12) +

  theme(
    plot.title = element_text(face = "bold"),
    axis.text.x = element_text(
      angle = 35,
      hjust = 1
    ),
    strip.text = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

p_all_outcomes

# Save figures

# Create output folder
dir.create(
  "figures",
  showWarnings = FALSE
)

# Save individual figures
ggsave(
  "figures/procedural_fairness.png",
  p_fairness,
  width = 8,
  height = 5,
  dpi = 300
)

ggsave(
  "figures/trust.png",
  p_trust,
  width = 8,
  height = 5,
  dpi = 300
)

ggsave(
  "figures/effectiveness.png",
  p_effectiveness,
  width = 8,
  height = 5,
  dpi = 300
)

ggsave(
  "figures/fairness_by_perspective.png",
  p_fairness_perspective,
  width = 8,
  height = 5,
  dpi = 300
)

# Save combined figure
ggsave(
  "figures/all_outcomes.png",
  p_all_outcomes,
  width = 11,
  height = 10,
  dpi = 300
)

# Also save as PDF
ggsave(
  "figures/all_outcomes.pdf",
  p_all_outcomes,
  width = 11,
  height = 10
)
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## for 'Mean evaluation (1–7)' in 'mbcsToSbcs': - substituted for – (U+2013)