setwd("~/Documents/Dropbox/Research/Adrian")
a<-read.csv ("new_AI_algorithm_study.csv", header=T, sep=",")

#creating DV's - average of 10 tasks
a$aitrust<-(a$ai_1+a$ai_2+a$ai_3+a$ai_4+a$ai_5+a$ai_6+a$ai_7+a$ai_8+a$ai_9+a$ai_10)/10

a$algtrust<-(a$alg_1+a$alg_2+a$alg_3+a$alg_4+a$alg_5+a$alg_6+a$alg_7+a$alg_8+a$alg_9+a$alg_10)/10

#no difference overall in trust in AI vs. algorithms
t.test(a$aitrust, a$algtrust)
## 
##  Welch Two Sample t-test
## 
## data:  a$aitrust and a$algtrust
## t = 0.45595, df = 397.92, p-value = 0.6487
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.245568  5.205593
## sample estimates:
## mean of x mean of y 
##  46.86976  45.88974
#well this is bizarre... social conservatism correlates with trust in algorithms, but not with trust in AI!!! 
cor.test(a$poli_1, a$aitrust)
## 
##  Pearson's product-moment correlation
## 
## data:  a$poli_1 and a$aitrust
## t = 1.03, df = 203, p-value = 0.3042
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06557707  0.20709462
## sample estimates:
##        cor 
## 0.07210592
cor.test(a$poli_1, a$algtrust)
## 
##  Pearson's product-moment correlation
## 
## data:  a$poli_1 and a$algtrust
## t = 1.8966, df = 193, p-value = 0.05938
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.005349539  0.270633112
## sample estimates:
##       cor 
## 0.1352645
#testing different potential "mediators" - these all make sense... just the DV makes no sense. 
ai<-subset(a, ai1==1)
alg<-subset(a, alg1==1)
t.test(ai$autonomy_1, alg$autonomy_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$autonomy_1 and alg$autonomy_1
## t = -1.4334, df = 395, p-value = 0.1525
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.402919   1.629682
## sample estimates:
## mean of x mean of y 
##  37.28646  41.67308
t.test(ai$goals_1, alg$goals_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$goals_1 and alg$goals_1
## t = 1.0448, df = 398, p-value = 0.2967
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.687158  8.783312
## sample estimates:
## mean of x mean of y 
##  33.25000  30.20192
t.test(ai$mind_1, alg$mind_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$mind_1 and alg$mind_1
## t = 3.0316, df = 394.52, p-value = 0.002593
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   2.916281 13.677469
## sample estimates:
## mean of x mean of y 
##  33.42188  25.12500
t.test(ai$risk_1, alg$risk_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$risk_1 and alg$risk_1
## t = 5.1468, df = 383.24, p-value = 4.243e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   8.712356 19.483958
## sample estimates:
## mean of x mean of y 
##  46.08854  31.99038
t.test(ai$threat_1, alg$threat_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$threat_1 and alg$threat_1
## t = 3.7154, df = 397.46, p-value = 0.000232
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   4.477501 14.540928
## sample estimates:
## mean of x mean of y 
##  71.93229  62.42308
t.test(ai$threat_2, alg$threat_2)
## 
##  Welch Two Sample t-test
## 
## data:  ai$threat_2 and alg$threat_2
## t = 3.5969, df = 380.61, p-value = 0.0003645
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   4.285293 14.619355
## sample estimates:
## mean of x mean of y 
##  34.56771  25.11538
t.test(ai$confusing_1, alg$confusing_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$confusing_1 and alg$confusing_1
## t = -1.8918, df = 398, p-value = 0.05924
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.832301   0.208102
## sample estimates:
## mean of x mean of y 
##  39.19271  44.50481
t.test(ai$exciting_1, alg$exciting_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$exciting_1 and alg$exciting_1
## t = 4.8115, df = 397.63, p-value = 2.13e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   7.599215 18.099503
## sample estimates:
## mean of x mean of y 
##  70.47917  57.62981
t.test(ai$predictable_1, alg$predictable_1)
## 
##  Welch Two Sample t-test
## 
## data:  ai$predictable_1 and alg$predictable_1
## t = -3.2155, df = 396.67, p-value = 0.001409
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -13.716912  -3.307928
## sample estimates:
## mean of x mean of y 
##  50.46354  58.97596
#looking at interactions between task and condition and conservatism
alglong <- reshape(alg, 
  varying = c("alg_1", "alg_2", "alg_3", "alg_4", "alg_5", "alg_6", "alg_7", "alg_8", "alg_9", "alg_10"), 
  v.names = "trust",
  timevar = "task", 
  times = c(1:10), 
  direction = "long")

ailong <- reshape(ai, 
  varying = c("ai_1", "ai_2", "ai_3", "ai_4", "ai_5", "ai_6", "ai_7", "ai_8", "ai_9", "ai_10"), 
  v.names = "trust",
  timevar = "task", 
  times = c(1:10), 
  direction = "long")

ailong$cond<-"ai"
ailong<-ailong[c(48,49,51,39)]

alglong$cond<-"alg"
alglong<-alglong[c(48,49,51,39)]
  
long<-rbind(ailong, alglong)


summary(lm(trust ~ task * cond * poli_1, data=long))
## 
## Call:
## lm(formula = trust ~ task * cond * poli_1, data = long)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -56.451 -31.943   2.487  28.902  82.631 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          38.403326   4.977723   7.715 1.88e-14 ***
## task                  1.970001   0.802233   2.456  0.01415 *  
## condalg             -35.056923   7.199791  -4.869 1.21e-06 ***
## poli_1                0.006617   0.072068   0.092  0.92685    
## task:condalg          3.075739   1.160351   2.651  0.00809 ** 
## task:poli_1          -0.004683   0.011615  -0.403  0.68683    
## condalg:poli_1        0.488728   0.106188   4.602 4.43e-06 ***
## task:condalg:poli_1  -0.041807   0.017114  -2.443  0.01465 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 33.03 on 2042 degrees of freedom
##   (1950 observations deleted due to missingness)
## Multiple R-squared:  0.05645,    Adjusted R-squared:  0.05322 
## F-statistic: 17.45 on 7 and 2042 DF,  p-value: < 2.2e-16