forked from AdaLovelaceInstitute/how-do-people-feel-about-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptive analysis_How do people feel about AI.Rmd
1491 lines (1330 loc) · 49.4 KB
/
Descriptive analysis_How do people feel about AI.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Descriptive analysis"
output:
word_document: default
html_document: default
date: "2023-05-10"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
# setwd("..") # Use this line to set the working directory on your machine where the data is located.
```
```{r}
install.packages("tidyverse")
install.packages("haven")
install.packages("scales")
install.packages("psych")
install.packages("survey")
install.packages("jtools")
install.packages("nFactors")
install.packages("sjPlot")
install.packages("purrr")
install.packages("broom")
install.packages("labelled")
install.packages("stringr")
install.packages("descr")
```
```{r}
library(tidyverse)
library(haven)
library(scales)
library(psych)
library(survey)
library(jtools)
library(nFactors)
library(sjPlot)
library(purrr)
library(broom)
library(labelled)
library(stringr)
library(descr)
```
```{r}
# Read dataset
df1 <- read_dta("262400371_Public Attitudes to AI_client version.dta")
```
```{r}
# Prep data
# Remove ppt identifying as 'other' and remove 16 year old
df1 <- df1 %>%
filter(is.na(RS_Sex) | RS_Sex != 3) %>%
filter(CS_Age != "16")
# combine ethnicity groupings
df1 <- df1 %>%
mutate(RS_Ethnicity_Combined =
case_when(
RS_Ethnicity_Reduced == 1 ~ 1,
RS_Ethnicity_Reduced == 2 ~ 2,
RS_Ethnicity_Reduced == 3 ~ 3,
RS_Ethnicity_Reduced == 4 | RS_Ethnicity_Reduced == 5 | RS_Ethnicity_Reduced == 6 ~ 4
))
#"1" = "White",
# "2" = "Asian or Asian British",
# "3" = "Black British, Caribbean or African",
# "4" = "Any other ethnic group"
df1 <- df1 %>%
mutate(Region_combined =
case_when(
CS_Region_N < 10 ~ 1, #eng
CS_Region_N == 10 ~ 2, #ni
CS_Region_N == 11 ~ 3, #scotland
CS_Region_N == 12 ~ 4 # wales
))
```
```{r}
## functions to simplify data tidying
## recoding technology labels
recode_technologies <- function(Technology_specific) {
recode(Technology_specific,
"WEL" = "Welfare eligibility",
"JOB" = "Job eligibility",
"CAN" = "Cancer risk",
"LOAN" = "Loan repayment risk",
"MP" = "Mobile phone unlock",
"BC" = "Border control",
"PS" = "Police surveillance",
"AW" = "Autonomous weapons",
"DC" = "Driverless cars",
"RCA" = "Robotic care assistant",
"RVC" ="Robotic vacuum cleaner",
"SMC"= "Targeted consumer ads",
"SMP" = "Targeted political ads",
"VASS"= "Smart speaker",
"VAH"= "Virtual healthcare assistant",
"CCR"= "Climate change simulation",
"VR"= "Education simulations")
}
## list of demographic variables of interest
demog <- df1 %>%
remove_val_labels() %>%
dplyr::select(
Respondent_ID, PV25_Weight,
RS_Ethnicity_Combined,
CS_Age_Band,
RS_Sex,
RS_EducationLevel,
DR_Socio_Eco
) %>%
mutate(RS_Ethnicity_Combined =
dplyr::recode(RS_Ethnicity_Combined,
"1" = "White",
"2" = "Asian or Asian British",
"3" = "Black British, Caribbean or African",
"4" = "Any other ethnic group"
)) %>%
mutate(CS_Age_Band =
dplyr::recode(CS_Age_Band,
"1" = "18-24 yrs",
"2" = "25-34 yrs",
"3" = "35-44 yrs",
"4" = "45-54 yrs",
"5" = "55-64 yrs",
"6" = "65-74 yrs",
"7" = "75+ yrs"
)) %>%
mutate(RS_Sex =
dplyr::recode(RS_Sex,
"1" = "Male",
"2" = "Female")) %>%
mutate(RS_EducationLevel =
dplyr::recode(RS_EducationLevel,
"1" = "Degree level qualification(s)",
"2" = "Non-degree level qualifications",
"3" = "No academic or vocational qualifications")) %>%
mutate(DR_Socio_Eco =
dplyr::recode(DR_Socio_Eco,
"1" = "SEC1, 2",
"2" = "SEC3",
"3" = "SEC4",
"4" = "SEC5",
"5" = "SEC6, 7",
"6" = "SEC8",
"7" = "Students")) %>%
pivot_longer(names_to = "Q_Demo",
values_to = "A_Demo",
RS_Ethnicity_Combined:DR_Socio_Eco)
# list of levels
demo_list <- c("White",
"Asian or Asian British",
"Black British, Caribbean or African",
"Any other ethnic group",
"18-24 yrs",
"25-34 yrs",
"35-44 yrs",
"45-54 yrs",
"55-64 yrs",
"65-74 yrs",
"75+ yrs",
"Male",
"Female",
"Identify in another way",
"Degree level qualification(s)",
"Non-degree level qualifications",
"No academic or vocational qualifications",
"SEC1, 2",
"SEC3",
"SEC4",
"SEC5",
"SEC6, 7",
"SEC8",
"Students",
"Total" )
```
####### Descriptive analysis #########
Awareness of technology
```{r}
# prep data
df2.1 <- df1 %>%
# remove all labels
remove_val_labels() %>%
## select vars
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("AWARE_", ignore.case = TRUE))) %>%
## pivot longer
pivot_longer( # convert to long format
names_to = "Question_a",
values_to = "Value_a",
AWARE_MP:AWARE_VR
)
## create new labelling var for specific technologies
df2.1$Technology_specific <- sub('.*_', '', df2.1$Question_a) # extract everything after the underscore into a new variable by replacing everything before the underscore with blank space.
df2.1 <- df2.1 %>%
mutate("Value_a" =
dplyr::recode(Value_a,
"1" = "Yes",
"2" = "No",
"3" = "Not sure/prefer not to say",
"4" = "Not sure/prefer not to say"))
## relabel the codes so they read as words
df2.1 <- df2.1 %>%
mutate(Technology_specific =
recode_technologies(Technology_specific))
## Awareness plot
df2.1 %>%
drop_na(Value_a) %>%
group_by(Technology_specific, Value_a) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
mutate(Value_factor =
case_when(Value_a == "Yes" ~ "High",
TRUE ~ "Other")) %>%
group_by(Technology_specific, Value_factor) %>%
mutate(Sum_f = sum(pct)) %>%
#### ggplot #####
ggplot(aes(y=pct, x=reorder(Technology_specific, -Sum_f), fill = Value_a)) +
geom_col(width = 0.7) +
scale_y_continuous(name = "", label = percent) +
theme_minimal() +
theme(panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 12)) +
labs(title="Awareness of technology",
subtitle = "'Before today, had you heard of the use of AI technologies for...'") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("Yes", "Not sure/prefer not to say", "No"),
values = c(
"#00A087FF",
"#D5DFE8",
"#E64B35FF"
),
name = "Response") +
xlab("") +
geom_text(
aes(label = scales::percent(pct, accuracy = 1)), position = position_stack(vjust = .5), size = 3) +
coord_flip()
```
```{r}
## Awareness x demographics of interest
df2.1.1 <- inner_join(df2.1, demog)
# overall awareness
df2.1.t <- df2.1 %>%
drop_na(Value_a) %>%
group_by(Technology_specific, Value_a) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
df2.1.t$A_Demo <- "Total"
df2.1.t$Q_Demo <- "Total"
# awareness by demographics
df2.1.d <- df2.1.1 %>%
drop_na(Value_a) %>%
drop_na(A_Demo) %>%
group_by(Technology_specific, Q_Demo,
A_Demo,
Value_a) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
df2.1.1 <- rbind(df2.1.t, df2.1.d)
df2.1.1$A_Demo <- factor(df2.1.1$A_Demo,levels = demo_list)
```
```{r, fig.width=12, fig.height=20}
df2.1.1 %>%
drop_na(A_Demo) %>%
ggplot(aes(y=pct, x=A_Demo)) +
geom_col(aes(fill = Value_a), width = 0.7) +
scale_y_continuous(name = "Percentage (%)", label = percent) +
theme_light() +
facet_wrap(~Technology_specific) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 14)) +
labs(title="Awareness") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("Yes", "Not sure/prefer not to say", "No"),
values = c(
"#00A087FF",
"#D5DFE8",
"#E64B35FF"
),
name = "Response") +
coord_flip()
# awareness x age specific stats
tab <- df2.1.1 %>%
filter(A_Demo == "75+ yrs") %>%
filter(Value_a == "Yes")
# mobile phones
# border control
# SMC
df1 %>%
drop_na(AWARE_SMC) %>% # change for each use of AI interested in
drop_na(CS_Age_Band) %>%
filter(CS_Age_Band!= 7) %>%
group_by(AWARE_SMC) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
```
#######################################################################################################################################
Experience with technology
```{r}
## Experience with technology
df2.2 <- df1 %>%
# remove all labels
remove_val_labels() %>%
## select vars
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("EXP_", ignore.case = TRUE)),) %>%
## pivot longer
pivot_longer( # convert to long format
names_to = "Question_e",
values_to = "Value_e",
EXP_MP:EXP_VR
)
## create new labelling var for specific technologies
df2.2$Technology_specific <- sub('.*_', '', df2.2$Question_e) # extract everything after the underscore into a new variable by replacing everything before the underscore with blank space.
df2.2 <- df2.2 %>%
mutate("Value_e" =
dplyr::recode(Value_e,
"1" = "A lot",
"2" = "Some",
"3" = "None",
"4" = "Not sure/prefer not to say",
"5" = "Not sure/prefer not to say"))
## relabel the codes so they read as words
df2.2 <- df2.2 %>%
mutate(Technology_specific =
recode_technologies(Technology_specific))
## relevel values
df2.2$Value_e <- factor(df2.2$Value_e,levels = c( "None", "Not sure/prefer not to say", "Some", "A lot"))
## Experience plot
df2.2 %>%
drop_na(Value_e) %>%
group_by(Technology_specific, Value_e) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
mutate(Value_factor =
case_when(Value_e == "None" ~ "High",
TRUE ~ "Other")) %>%
group_by(Technology_specific, Value_factor) %>%
mutate(Sum_f = sum(pct)) %>%
#### ggplot #####
ggplot(aes(y=pct, x=reorder(Technology_specific, +Sum_f), fill = Value_e)) +
geom_col(width = 0.7) +
scale_y_continuous(name = "", label = percent) +
theme_minimal() +
theme(
panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 12)) +
labs(title="Experience with technology",
subtitle = "'How much personal experience have you had, if any with...'") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("A lot", "Some", "Not sure/prefer not to say", "None" ),
values = c(
"#00A087FF",
"#91D1C2FF",
"#D5DFE8",
"#E64B35FF"
),
name = "Response") +
xlab("") +
geom_text(
aes(label = scales::percent(pct, accuracy = 1)), position = position_stack(vjust = .5), size = 3) +
coord_flip()
```
```{r}
## experience x demographics of interest
df2.2.1 <- inner_join(df2.2, demog)
# overall awareness
df2.2.t <- df2.2 %>%
drop_na(Value_e) %>%
group_by(Technology_specific, Value_e) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
df2.2.t$A_Demo <- "Total"
df2.2.t$Q_Demo <- "Total"
# awareness by demographics
df2.2.d <- df2.2.1 %>%
drop_na(Value_e) %>%
drop_na(A_Demo) %>%
group_by(Technology_specific, Q_Demo,
A_Demo,
Value_e) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
df2.2.1 <- rbind(df2.2.t, df2.2.d)
df2.2.1$A_Demo <- factor(df2.2.1$A_Demo,levels = demo_list)
```
```{r, fig.width=12, fig.height=20}
df2.2.1 %>%
drop_na(A_Demo) %>%
ggplot(aes(y=pct, x=A_Demo)) +
geom_col(aes(fill = Value_e), width = 0.7) +
scale_y_continuous(name = "Percentage (%)", label = percent) +
theme_light() +
facet_wrap(~Technology_specific) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 14)) +
labs(title="Experience") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("A lot", "Some", "None", "Not sure/prefer not to say"),
values = c(
"#00A087FF",
"#91D1C2FF",
"#E64B35FF",
"#D5DFE8"),
name = "Response") +
coord_flip()
# experience x age specific stats
#MP
#BC
#SMC
#smp
df1 %>%
drop_na(EXP_MP) %>% # change for each use of AI interested in
drop_na(CS_Age_Band) %>%
filter(CS_Age_Band== 7) %>%
group_by(EXP_MP) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
```
```{r}
## tidy up console by removing data frames we no longer need
rm(df2.1,
df2.1.1,
df2.1.d,
df2.1.t,
df2.2,
df2.2.1,
df2.2.d,
df2.2.t,
tab)
```
#######################################################################################################################################
Overall ratings of benefit and concern
```{r}
### prep data
## overall levels of benefit
df3.1 <- df1 %>%
# remove all labels
remove_val_labels() %>%
## select vars
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("BENA_", ignore.case = TRUE)),) %>%
## pivot longer
pivot_longer( # convert to long format
names_to = "Question_b",
values_to = "Value_b",
BENA_MP:BENA_VR
)
## create new labelling var for specific technologies
df3.1$Technology_specific <- sub('.*_', '', df3.1$Question_b) # extract everything after the underscore into a new variable by replacing everything before the underscore with blank space.
df3.1 <- df3.1 %>%
mutate("Value_b" =
dplyr::recode(Value_b,
"1" = "Very",
"2" = "Somewhat",
"3" = "Not very",
"4" = "Not at all",
"5" = "Don't know/prefer not to say",
"6" = "Don't know/prefer not to say"))
df3.1$Value_b <- factor(df3.1$Value_b,levels = c( "Not at all", "Not very", "Don't know/prefer not to say", "Somewhat", "Very"))
## repeat for concerns
df3.2 <- df1 %>%
# remove all labels
remove_val_labels() %>%
## select vars
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("CONA_", ignore.case = TRUE)),) %>%
## pivot longer
pivot_longer( # convert to long format
names_to = "Question_c",
values_to = "Value_c",
CONA_MP:CONA_VR
)
## create new labelling var for specific technologies
df3.2$Technology_specific <- sub('.*_', '', df3.2$Question_c) # extract everything after the underscore into a new variable by replacing everything before the underscore with blank space.
df3.2 <- df3.2 %>%
mutate("Value_c" =
dplyr::recode(Value_c,
"1" = "Very",
"2" = "Somewhat",
"3" = "Not very",
"4" = "Not at all",
"5" = "Don't know/prefer not to say",
"6" = "Don't know/prefer not to say"))
df3.2$Value_c <- factor(df3.2$Value_c,levels = c( "Not at all", "Not very", "Don't know/prefer not to say", "Somewhat", "Very"))
df3 <- inner_join(df3.1, df3.2)
df3 <- df3 %>%
mutate(Technology_specific =
recode_technologies(Technology_specific))
rm(df3.1, df3.2)
```
```{r}
## bar plot of benefit levels
df3 %>%
drop_na(Value_b) %>%
group_by(Technology_specific, Value_b) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
mutate(Value_factor =
case_when(Value_b == "Very" | Value_b == "Somewhat" ~ "High",
TRUE ~ "Other")) %>%
group_by(Technology_specific, Value_factor) %>%
mutate(Sum_f = sum(pct)) %>%
#### ggplot #####
ggplot(aes(y=pct, x=reorder(Technology_specific, -Sum_f), fill = Value_b)) +
geom_col(width = 0.7) +
scale_y_continuous(name = "", label = percent) +
theme_minimal() +
theme(#panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 12)) +
labs(title="Technology as beneficial",
subtitle = "'To what extent do you think that the use of this technology will be beneficial?'") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("Very", "Somewhat", "Don't know/prefer not to say", "Not very", "Not at all" ),
values = c(
"#00A087FF",
"#91D1C2FF",
"#D5DFE8",
"#F39B7FFF",
"#E64B35FF"
),
name = "Response") +
xlab("") +
geom_text(
aes(label = scales::percent(pct, accuracy = 1)), position = position_stack(vjust = .5), size = 3) +
coord_flip()
```
```{r}
## bar plot of concerns
df3 %>%
drop_na(Value_c) %>%
group_by(Technology_specific, Value_c) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
mutate(Value_factor =
case_when(Value_c == "Very" | Value_c == "Somewhat" ~ "High",
TRUE ~ "Other")) %>%
group_by(Technology_specific, Value_factor) %>%
mutate(Sum_f = sum(pct)) %>%
#### ggplot #####
ggplot(aes(y=pct, x=reorder(Technology_specific, -Sum_f), fill = Value_c)) +
geom_col(width = 0.7) +
scale_y_continuous(name = "", label = percent) +
theme_minimal() +
theme(#panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "top", legend.text = element_text(size=12), legend.title = element_text(size = 12)) +
labs(title="Technology as concerning",
subtitle = "'To what extent are you concerned about the use of...'") +
theme(plot.title = element_text(size = 14)) +
scale_fill_manual(breaks = c("Very", "Somewhat", "Don't know/prefer not to say", "Not very", "Not at all" ),
values = c(
"#E64B35FF",
"#F39B7FFF",
"#D5DFE8",
"#91D1C2FF",
"#00A087FF"
),
name = "Response") +
xlab("") +
geom_text(
aes(label = scales::percent(pct, accuracy = 1)), position = position_stack(vjust = .5), size = 3) +
coord_flip()
```
```{r}
rm(df3)
```
####### Overall - specific benefits and concerns for each technology ###############
```{r}
## loop through all technologies
# overall sample specific benefits and concerns
df5 <- df1 %>%
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("BENB_", ignore.case = TRUE)),) %>%
select(!BENB_MP_3) %>%
select(!BENB_BC_7) %>%
select(!BENB_PS_6) %>%
select(!BENB_WEL_7) %>%
select(!BENB_JOB_7) %>%
select(!BENB_CAN_6) %>%
select(!BENB_LOAN_7) %>%
select(!BENB_SMC_4) %>%
select(!BENB_SMP_5) %>%
select(!BENB_VASS_6) %>%
select(!BENB_VAH_7) %>%
select(!BENB_RVC_4) %>%
select(!BENB_RCA_5) %>%
select(!BENB_DC_7) %>%
select(!BENB_AW_7) %>%
select(!BENB_CCR_5) %>%
select(!BENB_VR_5) %>%
pivot_longer( # convert to long format
names_to = "Question",
values_to = "Value",
BENB_MP01:BENB_VR09)
# broad grouping variable
df5 <- df5 %>%
mutate(Technology_broad =
case_when(
str_detect(Question, "_MP") | str_detect(Question,"_BC") | str_detect(Question,"_PS") ~ "Face recognition",
str_detect(Question, "_WEL") | str_detect(Question,"_JOB") | str_detect(Question,"_CAN") | str_detect(Question,"_LOAN") ~ "AI risk or eligibility",
str_detect(Question, "_SMC") | str_detect(Question,"_SMP") ~ "Social media targeting",
str_detect(Question, "_VASS") | str_detect(Question,"_VAH") ~ "Virtual assistants",
str_detect(Question, "_RVC") | str_detect(Question,"_RCA") | str_detect(Question,"_DC") | str_detect(Question,"_AW") ~ "Robotics",
str_detect(Question, "_CCR") | str_detect(Question,"_VR") ~ "Simulations",
))
## create new labelling var for specific technologies
df5$Technology_specific <- sub('.*_', '', df5$Question) # extract everything after the underscore into a new variable
df5$Technology_specific <- str_sub(df5$Technology_specific, end = -3) # remove last 2 characters from string
df5 <- df5 %>%
mutate(Technology_specific =
recode_technologies(Technology_specific))
```
```{r}
df5.b <- df1 %>%
select(Respondent_ID, PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("CONB_", ignore.case = TRUE)),) %>%
select(!CONB_MP_7) %>%
select(!CONB_BC_11) %>%
select(!CONB_PS_10) %>%
select(!CONB_WEL_11) %>%
select(!CONB_JOB_11) %>%
select(!CONB_CAN_9) %>%
select(!CONB_LOAN_12) %>%
select(!CONB_SMC_5) %>%
select(!CONB_SMP_6) %>%
select(!CONB_VASS_7) %>%
select(!CONB_VAH_11) %>%
select(!CONB_RVC_8) %>%
select(!CONB_RCA_9) %>%
select(!CONB_DC_11) %>%
select(!CONB_AW_10) %>%
select(!CONB_CCR_5) %>%
select(!CONB_VR_6) %>%
pivot_longer( # convert to long format
names_to = "Question",
values_to = "Value",
CONB_MP01:CONB_VR12)
# broad grouping variable
df5.b <- df5.b %>%
mutate(Technology_broad =
case_when(
str_detect(Question, "_MP") | str_detect(Question,"_BC") | str_detect(Question,"_PS") ~ "Face recognition",
str_detect(Question, "_WEL") | str_detect(Question,"_JOB") | str_detect(Question,"_CAN") | str_detect(Question,"_LOAN") ~ "AI risk or eligibility",
str_detect(Question, "_SMC") | str_detect(Question,"_SMP") ~ "Social media targeting",
str_detect(Question, "_VASS") | str_detect(Question,"_VAH") ~ "Virtual assistants",
str_detect(Question, "_RVC") | str_detect(Question,"_RCA") | str_detect(Question,"_DC") | str_detect(Question,"_AW") ~ "Robotics",
str_detect(Question, "_CCR") | str_detect(Question,"_VR") ~ "Simulations",
))
## create new labelling var for specific technologies
df5.b$Technology_specific <- sub('.*_', '', df5.b$Question) # extract everything after the underscore into a new variable
df5.b$Technology_specific <- str_sub(df5.b$Technology_specific, end = -3) # remove last 2 characters from string
df5.b <- df5.b %>%
mutate(Technology_specific =
recode_technologies(Technology_specific))
```
```{r}
## checking specific stats
df1 %>%
filter(CONA_VASS == 1 | CONA_VASS == 2) %>%
group_by(CONB_VASS06) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n))
```
```{r}
## specific benefits - risk and eligibility
df5 %>%
filter(Technology_broad == "AI risk or eligibility") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - risk and eligibility
df5.b %>%
filter(Technology_broad == "AI risk or eligibility") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific benefits - Face recognitio
df5 %>%
filter(Technology_broad == "Face recognition") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - Face recognitio
df5.b %>%
filter(Technology_broad == "Face recognition") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific benefits - Robotics
df5 %>%
filter(Technology_broad == "Robotics") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - Robotics
df5.b %>%
filter(Technology_broad == "Robotics") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific benefits - Virtual assistants
df5 %>%
filter(Technology_broad == "Virtual assistants") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - Virtual assistants
df5.b %>%
filter(Technology_broad == "Virtual assistants") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific benefits - Social media targeting
df5 %>%
filter(Technology_broad == "Social media targeting") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - Social media targeting
df5.b %>%
filter(Technology_broad == "Social media targeting") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific benefits - Simulations
df5 %>%
filter(Technology_broad == "Simulations") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
```{r}
## specific concerns - Simulations
df5.b %>%
filter(Technology_broad == "Simulations") %>%
drop_na(Value) %>%
group_by(Technology_specific, Question, Value) %>%
tally(wt = PV25_Weight) %>%
mutate(pct = n/sum(n)) %>%
filter(Value == 1) %>%
#### select top three benefits of technology type only ####
group_by(Technology_specific) %>%
arrange(desc(pct))
```
####### Chi-square testing of specific benefits and concerns #######
```{r}
## for this analysis, word documents with chi-square test tables will be produced and saved to your working directory.
df2 <- df1 %>%
select(RS_Ethnicity_Combined,
DR_Socio_Eco,
RS_Sex,
CS_Age_Band,
RS_EducationLevel,
AWARE_VR,
PV25_Weight,
tidyselect::vars_select(names(df1), starts_with("BENB_", ignore.case = TRUE)),
tidyselect::vars_select(names(df1), starts_with("CONB_", ignore.case = TRUE))) %>%
mutate(RS_Ethnicity_Combined = as.factor(RS_Ethnicity_Combined)) %>%
mutate(DR_Socio_Eco = as.factor(DR_Socio_Eco)) %>%
mutate(RS_Sex = as.factor(RS_Sex)) %>%
mutate(CS_Age_Band = as.factor(CS_Age_Band)) %>%
mutate(RS_EducationLevel = as.factor(RS_EducationLevel)) %>%
mutate(AWARE_VR = as.factor(AWARE_VR))
df2 <- df2 %>%
select(!BENB_MP_3) %>%
select(!BENB_BC_7) %>%
select(!BENB_PS_6) %>%
select(!BENB_WEL_7) %>%
select(!BENB_JOB_7) %>%
select(!BENB_CAN_6) %>%
select(!BENB_LOAN_7) %>%
select(!BENB_SMC_4) %>%
select(!BENB_SMP_5) %>%
select(!BENB_VASS_6) %>%
select(!BENB_VAH_7) %>%
select(!BENB_RVC_4) %>%
select(!BENB_RCA_5) %>%
select(!BENB_DC_7) %>%
select(!BENB_AW_7) %>%
select(!BENB_CCR_5) %>%
select(!BENB_VR_5)
df2 <- df2 %>%
select(!CONB_MP_7) %>%
select(!CONB_BC_11) %>%
select(!CONB_PS_10) %>%
select(!CONB_WEL_11) %>%
select(!CONB_JOB_11) %>%
select(!CONB_CAN_9) %>%
select(!CONB_LOAN_12) %>%
select(!CONB_SMC_5) %>%
select(!CONB_SMP_6) %>%
select(!CONB_VASS_7) %>%
select(!CONB_VAH_11) %>%
select(!CONB_RVC_8) %>%
select(!CONB_RCA_9) %>%
select(!CONB_DC_11) %>%
select(!CONB_AW_10) %>%
select(!CONB_CCR_5) %>%
select(!CONB_VR_6)
### column numbers to reference in code chunk below!
colnames(df2)
```
```{r}
## SES
for (col in names(df2)[8:18]) { ## change number in this line for columns you are interested in (refer to codebook)
sink(file = paste(col, "SES", sep = "_", ".doc"))