AI Concern

CodeBook

setwd("C:/Users/mvx13/OneDrive - Texas State University/Papers/2025/00_NewPapers/Survey/PewSurvey/W152")

library(readxl)
library(ggplot2)
library(dplyr)
library(compareGroups)
library(vtree)
library(DT)

codebook= read_excel("ATP W152 Codebook_cleaned.xlsx", sheet="Codebook")
datatable(
  codebook, extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('csv', 'excel')
  )
)
questions= read_excel("ATP W152 Codebook_cleaned.xlsx", sheet="Un")
datatable(
  questions, extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('csv', 'excel')
  )
)

AI Concern

df= read.csv("W152_AIConcern.csv")
df1 =df[, c(2:15, 17)]
head(df1)
##            F_METRO F_CREGION F_USR_SELFID F_AGECAT F_GENDER
## 1 Non-metropolitan   Midwest        Rural      65+    A man
## 2     Metropolitan     South     Suburban      65+    A man
## 3 Non-metropolitan   Midwest        Rural    50-64    A man
## 4     Metropolitan      West     Suburban    50-64  A woman
## 5 Non-metropolitan     South        Rural    50-64  A woman
## 6     Metropolitan   Midwest     Suburban      65+  A woman
##               F_EDUCCAT F_HISP_ORIGIN       F_RACETHNMOD
## 1          Some College   No Response White non-Hispanic
## 2          Some College   No Response White non-Hispanic
## 3 H.S. graduate or less   No Response White non-Hispanic
## 4     College graduate+   No Response White non-Hispanic
## 5     College graduate+   No Response White non-Hispanic
## 6     College graduate+   No Response White non-Hispanic
##                           F_BIRTHPLACE          F_MARITAL      F_PARTYLN_FINAL
## 1 U.S. 50 states, District of Columbia            Married          No Response
## 2 U.S. 50 states, District of Columbia            Married          No Response
## 3 U.S. 50 states, District of Columbia            Married          No Response
## 4 U.S. 50 states, District of Columbia            Married The Republican Party
## 5 U.S. 50 states, District of Columbia Never been married The Republican Party
## 6 U.S. 50 states, District of Columbia            Married          No Response
##                      F_INC_SDT1       F_IDEO           F_INTFREQ
## 1  $80,000 to less than $90,000     Moderate    About once a day
## 2              $100,000 or more Conservative          Less often
## 3                       Refused Conservative Several times a day
## 4 $90,000 to less than $100,000     Moderate Several times a day
## 5              $100,000 or more     Moderate   Almost constantly
## 6              $100,000 or more Conservative Several times a day
##                     CNCEXC_W152
## 1   More concerned than excited
## 2   More concerned than excited
## 3 Equally concerned and excited
## 4   More concerned than excited
## 5   More concerned than excited
## 6   More concerned than excited

Compare Groups

res1 <- compareGroups(CNCEXC_W152 ~ ., df1, ref = 1, max.ylev = 50,
                      max.xlev = 50,  chisq.test.perm=TRUE, chisq.test.B=10000)
res2= createTable(res1, show.ratio = TRUE)
res2
## 
## --------Summary descriptives table by 'CNCEXC_W152'---------
## 
## _____________________________________________________________________________________________________________________________________________________________________ 
##                                          Don't know/Refused/Web blank Equally concerned and excited More concerned than excited More excited than concerned p.overall 
##                                                      N=31                        N=2091                       N=2675                       N=613                      
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
## F_METRO:                                                                                                                                                      0.019   
##     Metropolitan                                  26 (83.9%)                  1846 (88.3%)                 2288 (85.5%)                 576 (94.0%)                   
##     No Response                                   0 (0.00%)                     2 (0.10%)                    1 (0.04%)                   0 (0.00%)                    
##     Non-metropolitan                              5 (16.1%)                    243 (11.6%)                  386 (14.4%)                 37 (6.04%)                    
## F_CREGION:                                                                                                                                                    0.028   
##     Midwest                                       6 (19.4%)                    367 (17.6%)                  592 (22.1%)                 124 (20.2%)                   
##     No Response                                   0 (0.00%)                     2 (0.10%)                    1 (0.04%)                   0 (0.00%)                    
##     Northeast                                     6 (19.4%)                    357 (17.1%)                  479 (17.9%)                 93 (15.2%)                    
##     South                                         10 (32.3%)                   821 (39.3%)                 1008 (37.7%)                 237 (38.7%)                   
##     West                                          9 (29.0%)                    544 (26.0%)                  595 (22.2%)                 159 (25.9%)                   
## F_USR_SELFID:                                                                                                                                                <0.001   
##     Refused                                       2 (6.45%)                    27 (1.29%)                   22 (0.82%)                   6 (0.98%)                    
##     Rural                                         6 (19.4%)                    432 (20.7%)                  713 (26.7%)                 84 (13.7%)                    
##     Suburban                                      15 (48.4%)                  1111 (53.1%)                 1352 (50.5%)                 338 (55.1%)                   
##     Urban                                         8 (25.8%)                    521 (24.9%)                  588 (22.0%)                 185 (30.2%)                   
## F_AGECAT:                                                                                                                                                    <0.001   
##     18-29                                         1 (3.23%)                    313 (15.0%)                  297 (11.1%)                 152 (24.8%)                   
##     30-49                                         5 (16.1%)                    754 (36.1%)                  834 (31.2%)                 290 (47.3%)                   
##     50-64                                         12 (38.7%)                   491 (23.5%)                  729 (27.3%)                 110 (17.9%)                   
##     65+                                           13 (41.9%)                   521 (24.9%)                  801 (29.9%)                 60 (9.79%)                    
##     Refused                                       0 (0.00%)                    12 (0.57%)                   14 (0.52%)                   1 (0.16%)                    
## F_GENDER:                                                                                                                                                    <0.001   
##     A man                                         18 (58.1%)                  1054 (50.4%)                 1212 (45.3%)                 405 (66.1%)                   
##     A woman                                       13 (41.9%)                  1018 (48.7%)                 1434 (53.6%)                 202 (33.0%)                   
##     In some other way                             0 (0.00%)                    11 (0.53%)                   18 (0.67%)                   2 (0.33%)                    
##     Refused                                       0 (0.00%)                     8 (0.38%)                   11 (0.41%)                   4 (0.65%)                    
## F_EDUCCAT:                                                                                                                                                   <0.001   
##     College graduate+                             9 (29.0%)                    951 (45.5%)                  999 (37.3%)                 350 (57.1%)                   
##     H.S. graduate or less                         13 (41.9%)                   534 (25.5%)                  797 (29.8%)                 114 (18.6%)                   
##     Refused                                       0 (0.00%)                     4 (0.19%)                    7 (0.26%)                   2 (0.33%)                    
##     Some College                                  9 (29.0%)                    602 (28.8%)                  872 (32.6%)                 147 (24.0%)                   
## F_HISP_ORIGIN:                                                                                                                                                0.005   
##     Cuban                                         0 (0.00%)                    23 (1.10%)                   19 (0.71%)                  10 (1.63%)                    
##     Dominican                                     1 (3.23%)                    17 (0.81%)                    7 (0.26%)                   4 (0.65%)                    
##     Mexican                                       1 (3.23%)                    161 (7.70%)                  212 (7.93%)                 61 (9.95%)                    
##     No Response                                   29 (93.5%)                  1769 (84.6%)                 2293 (85.7%)                 481 (78.5%)                   
##     Other Central American                        0 (0.00%)                    15 (0.72%)                   21 (0.79%)                   6 (0.98%)                    
##     Other country                                 0 (0.00%)                     9 (0.43%)                   12 (0.45%)                   1 (0.16%)                    
##     Other South American                          0 (0.00%)                    33 (1.58%)                   37 (1.38%)                  20 (3.26%)                    
##     Puerto Rican                                  0 (0.00%)                    32 (1.53%)                   37 (1.38%)                  10 (1.63%)                    
##     Refused                                       0 (0.00%)                     6 (0.29%)                    7 (0.26%)                   4 (0.65%)                    
##     Salvadoran                                    0 (0.00%)                     7 (0.33%)                    7 (0.26%)                  11 (1.79%)                    
##     Spanish                                       0 (0.00%)                    19 (0.91%)                   23 (0.86%)                   5 (0.82%)                    
## F_RACETHNMOD:                                                                                                                                                <0.001   
##     Asian non-Hispanic                            4 (12.9%)                    273 (13.1%)                  148 (5.53%)                 126 (20.6%)                   
##     Black non-Hispanic                            6 (19.4%)                    249 (11.9%)                  308 (11.5%)                 75 (12.2%)                    
##     Hispanic                                      2 (6.45%)                    322 (15.4%)                  382 (14.3%)                 132 (21.5%)                   
##     Other                                         1 (3.23%)                    67 (3.20%)                   116 (4.34%)                 27 (4.40%)                    
##     Refused                                       1 (3.23%)                    15 (0.72%)                   26 (0.97%)                   4 (0.65%)                    
##     White non-Hispanic                            17 (54.8%)                  1165 (55.7%)                 1695 (63.4%)                 249 (40.6%)                   
## F_BIRTHPLACE:                                                                                                                                                <0.001   
##     Another country                               6 (19.4%)                    400 (19.1%)                  298 (11.1%)                 178 (29.0%)                   
##     Refused                                       0 (0.00%)                    16 (0.77%)                   14 (0.52%)                   4 (0.65%)                    
##     U.S. 50 states, District of Columbia          25 (80.6%)                  1638 (78.3%)                 2325 (86.9%)                 418 (68.2%)                   
##     U.S. other territory                          0 (0.00%)                    21 (1.00%)                   15 (0.56%)                   6 (0.98%)                    
##     U.S. Puerto Rico                              0 (0.00%)                    16 (0.77%)                   23 (0.86%)                   7 (1.14%)                    
## F_MARITAL:                                                                                                                                                   <0.001   
##     Divorced                                      3 (9.68%)                    176 (8.42%)                  277 (10.4%)                 38 (6.20%)                    
##     Living with a partner                         2 (6.45%)                    183 (8.75%)                  238 (8.90%)                 75 (12.2%)                    
##     Married                                       13 (41.9%)                  1159 (55.4%)                 1460 (54.6%)                 304 (49.6%)                   
##     Never been married                            7 (22.6%)                    442 (21.1%)                  483 (18.1%)                 178 (29.0%)                   
##     Refused                                       0 (0.00%)                    12 (0.57%)                   13 (0.49%)                   4 (0.65%)                    
##     Separated                                     2 (6.45%)                    38 (1.82%)                   43 (1.61%)                   9 (1.47%)                    
##     Widowed                                       4 (12.9%)                    81 (3.87%)                   161 (6.02%)                  5 (0.82%)                    
## F_PARTYLN_FINAL:                                                                                                                                             <0.001   
##     No Response                                   19 (61.3%)                  1134 (54.2%)                 1589 (59.4%)                 303 (49.4%)                   
##     Refused                                       5 (16.1%)                    71 (3.40%)                   98 (3.66%)                  23 (3.75%)                    
##     The Democratic Party                          3 (9.68%)                    494 (23.6%)                  491 (18.4%)                 160 (26.1%)                   
##     The Republican Party                          4 (12.9%)                    392 (18.7%)                  497 (18.6%)                 127 (20.7%)                   
## F_INC_SDT1:                                                                                                                                                  <0.001   
##     $100,000 or more                              9 (29.0%)                    770 (36.8%)                  713 (26.7%)                 249 (40.6%)                   
##     $30,000 to less than $40,000                  2 (6.45%)                    158 (7.56%)                  223 (8.34%)                 53 (8.65%)                    
##     $40,000 to less than $50,000                  2 (6.45%)                    152 (7.27%)                  230 (8.60%)                 32 (5.22%)                    
##     $50,000 to less than $60,000                  1 (3.23%)                    145 (6.93%)                  196 (7.33%)                 36 (5.87%)                    
##     $60,000 to less than $70,000                  0 (0.00%)                    135 (6.46%)                  197 (7.36%)                 37 (6.04%)                    
##     $70,000 to less than $80,000                  3 (9.68%)                    130 (6.22%)                  198 (7.40%)                 39 (6.36%)                    
##     $80,000 to less than $90,000                  0 (0.00%)                    105 (5.02%)                  170 (6.36%)                 29 (4.73%)                    
##     $90,000 to less than $100,000                 2 (6.45%)                    112 (5.36%)                  177 (6.62%)                 36 (5.87%)                    
##     Less than $30,000                             9 (29.0%)                    289 (13.8%)                  432 (16.1%)                 79 (12.9%)                    
##     Refused                                       3 (9.68%)                    95 (4.54%)                   139 (5.20%)                 23 (3.75%)                    
## F_IDEO:                                                                                                                                                      <0.001   
##     Conservative                                  9 (29.0%)                    454 (21.7%)                  733 (27.4%)                 118 (19.2%)                   
##     Liberal                                       4 (12.9%)                    443 (21.2%)                  414 (15.5%)                 121 (19.7%)                   
##     Moderate                                      11 (35.5%)                   886 (42.4%)                  939 (35.1%)                 291 (47.5%)                   
##     Refused                                       3 (9.68%)                    26 (1.24%)                   70 (2.62%)                   9 (1.47%)                    
##     Very conservative                             2 (6.45%)                    132 (6.31%)                  299 (11.2%)                 31 (5.06%)                    
##     Very liberal                                  2 (6.45%)                    150 (7.17%)                  220 (8.22%)                 43 (7.01%)                    
## F_INTFREQ:                                                                                                                                                   <0.001   
##     About once a day                              2 (6.45%)                    74 (3.54%)                   134 (5.01%)                 17 (2.77%)                    
##     Almost constantly                             11 (35.5%)                  1063 (50.8%)                 1135 (42.4%)                 420 (68.5%)                   
##     Do not use the internet                       3 (9.68%)                    34 (1.63%)                   44 (1.64%)                   3 (0.49%)                    
##     Less often                                    2 (6.45%)                    33 (1.58%)                   53 (1.98%)                   4 (0.65%)                    
##     Refused                                       0 (0.00%)                     9 (0.43%)                   10 (0.37%)                   4 (0.65%)                    
##     Several times a day                           10 (32.3%)                   839 (40.1%)                 1232 (46.1%)                 155 (25.3%)                   
##     Several times a week                          3 (9.68%)                    39 (1.87%)                   67 (2.50%)                  10 (1.63%)                    
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
##export2xls(res2, file='tabledem_ai_reg1.xlsx')

Chi-sq Test

g <- "CNCEXC_W152"   
vars <- c("F_METRO", "F_CREGION", "F_USR_SELFID", "F_AGECAT", "F_GENDER", "F_EDUCCAT", "F_HISP_ORIGIN", "F_RACETHNMOD", 
          "F_BIRTHPLACE", "F_MARITAL", "F_PARTYLN_FINAL", "F_INC_SDT1", "F_IDEO", "F_INTFREQ") 

chisq_info <- lapply(vars, function(v){
  tab <- table(df1[[v]], df1[[g]])
  ct  <- suppressWarnings(chisq.test(tab, correct = FALSE))
  data.frame(
    var   = v,
    chisq = unname(ct$statistic),
    df    = unname(ct$parameter),
    p     = ct$p.value
  )
})
chisq_info <- do.call(rbind, chisq_info)
chisq_info
##                var     chisq df            p
## 1          F_METRO  35.69887  6 3.154103e-06
## 2        F_CREGION  24.91512 12 1.523025e-02
## 3     F_USR_SELFID  72.92651  9 4.051097e-12
## 4         F_AGECAT 218.49764 12 4.862878e-40
## 5         F_GENDER  90.22228  9 1.469158e-15
## 6        F_EDUCCAT  95.79310  9 1.112839e-16
## 7    F_HISP_ORIGIN  67.42629 30 1.064247e-04
## 8     F_RACETHNMOD 213.98910 15 3.009686e-37
## 9     F_BIRTHPLACE 146.59153 12 2.782916e-25
## 10       F_MARITAL  95.00487 18 1.803664e-12
## 11 F_PARTYLN_FINAL  51.79301  9 4.946525e-08
## 12      F_INC_SDT1  95.94595 27 1.180376e-09
## 13          F_IDEO 138.96135 15 3.688748e-22
## 14       F_INTFREQ 177.30994 18 3.268075e-28

vtree

names(df1)
##  [1] "F_METRO"         "F_CREGION"       "F_USR_SELFID"    "F_AGECAT"       
##  [5] "F_GENDER"        "F_EDUCCAT"       "F_HISP_ORIGIN"   "F_RACETHNMOD"   
##  [9] "F_BIRTHPLACE"    "F_MARITAL"       "F_PARTYLN_FINAL" "F_INC_SDT1"     
## [13] "F_IDEO"          "F_INTFREQ"       "CNCEXC_W152"
vtree(df1,"F_GENDER CNCEXC_W152", showlegend=TRUE, shownodelabels=FALSE)

vtree(df1,"F_GENDER CNCEXC_W152", sameline=TRUE, prunesmaller=25)

vtree(df1,"F_GENDER F_EDUCCAT CNCEXC_W152", sameline=TRUE, prunesmaller=100)

vtree(df1,"F_AGECAT F_EDUCCAT CNCEXC_W152", sameline=TRUE, prunesmaller=200)

vtree(df1,"F_GENDER CNCEXC_W152", pattern=TRUE)

vtree(df1,"F_AGECAT F_USR_SELFID F_INTFREQ  CNCEXC_W152", pattern=TRUE , prunesmaller=100)

vtree(df1,"F_USR_SELFID F_MARITAL  CNCEXC_W152", pattern=TRUE , prunesmaller=75)

vtree(df1,"F_USR_SELFID F_INC_SDT1  CNCEXC_W152", pattern=TRUE , prunesmaller=75)