1 Load Libraries

library(tidyverse) # for the map() command
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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(psych) # for the describe() command
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(naniar) # for the gg_miss-upset() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
## 
## To modify variables or add new variables:
##              let(mtcars, new_var = 42, new_var2 = new_var*hp) %>% head()
## 
## 
## Attaching package: 'maditr'
## 
## The following objects are masked from 'package:dplyr':
## 
##     between, coalesce, first, last
## 
## The following object is masked from 'package:purrr':
## 
##     transpose
## 
## The following object is masked from 'package:readr':
## 
##     cols
## 
## 
## Use 'expss_output_rnotebook()' to display tables inside R Notebooks.
##  To return to the console output, use 'expss_output_default()'.
## 
## 
## Attaching package: 'expss'
## 
## The following object is masked from 'package:naniar':
## 
##     is_na
## 
## The following objects are masked from 'package:stringr':
## 
##     fixed, regex
## 
## The following objects are masked from 'package:dplyr':
## 
##     compute, contains, na_if, recode, vars, where
## 
## The following objects are masked from 'package:purrr':
## 
##     keep, modify, modify_if, when
## 
## The following objects are masked from 'package:tidyr':
## 
##     contains, nest
## 
## The following object is masked from 'package:ggplot2':
## 
##     vars

2 Import Data

# use the read.csv() command to import your downloaded CSV file
df <- read.csv(file="data/EAMMi2 Raw Data.csv", header=T)

3 Viewing Data

names(df)
##   [1] "StartDate"             "EndDate"               "Status"               
##   [4] "Progress"              "Duration..in.seconds." "Finished"             
##   [7] "RecordedDate"          "ResponseId"            "RecipientLastName"    
##  [10] "RecipientFirstName"    "RecipientEmail"        "ExternalReference"    
##  [13] "DistributionChannel"   "informedconsent"       "moa1.1_1"             
##  [16] "moa1.1_2"              "moa1.1_3"              "moa1.1_4"             
##  [19] "moa1.1_5"              "moa1.1_6"              "moa1.1_7"             
##  [22] "moa1.1_8"              "moa1.1_9"              "moa1.1_10"            
##  [25] "moa1.2_1"              "moa1.2_2"              "moa1.2_3"             
##  [28] "moa1.2_4"              "moa1.2_5"              "moa1.2_6"             
##  [31] "moa1.2_7"              "moa1.2_8"              "moa1.2_9"             
##  [34] "moa1.2_10"             "moa2.1_1"              "moa2.1_2"             
##  [37] "moa2.1_3"              "moa2.1_4"              "moa2.1_5"             
##  [40] "moa2.1_6"              "moa2.1_7"              "moa2.1_8"             
##  [43] "moa2.1_9"              "moa2.1_10"             "moa2.2_1"             
##  [46] "moa2.2_2"              "moa2.2_3"              "moa2.2_4"             
##  [49] "moa2.2_5"              "moa2.2_6"              "moa2.2_7"             
##  [52] "moa2.2_8"              "moa2.2_9"              "moa2.2_10"            
##  [55] "adult_Q"               "MOA_IMP_biascheck"     "MOA_ach_biascheck"    
##  [58] "MOA_IMP_dummy"         "MOA.ACH_dummy"         "Q65_First.Click"      
##  [61] "Q65_Last.Click"        "Q65_Page.Submit"       "Q65_Click.Count"      
##  [64] "IDEA_1"                "IDEA_2"                "IDEA_3"               
##  [67] "IDEA_4"                "IDEA_5"                "IDEA_6"               
##  [70] "IDEA_7"                "IDEA_8"                "IDEA.biascheck"       
##  [73] "IDEA.bias.dummy"       "Q66_First.Click"       "Q66_Last.Click"       
##  [76] "Q66_Page.Submit"       "Q66_Click.Count"       "politics"             
##  [79] "party"                 "president"             "Q74_First.Click"      
##  [82] "Q74_Last.Click"        "Q74_Page.Submit"       "Q74_Click.Count"      
##  [85] "swb_1"                 "swb_2"                 "swb_3"                
##  [88] "swb_4"                 "swb_5"                 "swb_6"                
##  [91] "Q67_First.Click"       "Q67_Last.Click"        "Q67_Page.Submit"      
##  [94] "Q67_Click.Count"       "mindful_1"             "mindful_2"            
##  [97] "mindful_3"             "mindful_4"             "mindful_5"            
## [100] "mindful_6"             "mindful_7"             "mindful_8"            
## [103] "mindful_9"             "mindful_10"            "mindful_11"           
## [106] "mindful_12"            "mindful_13"            "mindful_14"           
## [109] "mindful_15"            "mindful_biascheck"     "mindful_bias_dummy"   
## [112] "Q68_First.Click"       "Q68_Last.Click"        "Q68_Page.Submit"      
## [115] "Q68_Click.Count"       "belong_1"              "belong_2"             
## [118] "belong_3"              "belong_4"              "belong_5"             
## [121] "belong_6"              "belong_7"              "belong_8"             
## [124] "belong_9"              "belong_10"             "belnow"               
## [127] "belong_biascheck"      "belong_bias_dummy"     "Q72_First.Click"      
## [130] "Q72_Last.Click"        "Q72_Page.Submit"       "Q72_Click.Count"      
## [133] "efficacy_1"            "efficacy_2"            "efficacy_3"           
## [136] "efficacy_4"            "efficacy_5"            "efficacy_6"           
## [139] "efficacy_7"            "efficacy_8"            "efficacy_9"           
## [142] "efficacy_10"           "efficacy_biascheck"    "efficacy_bias_dummy"  
## [145] "Q77_First.Click"       "Q77_Last.Click"        "Q77_Page.Submit"      
## [148] "Q77_Click.Count"       "support_1"             "support_2"            
## [151] "support_3"             "support_4"             "support_5"            
## [154] "support_6"             "support_7"             "support_8"            
## [157] "support_9"             "support_10"            "support_11"           
## [160] "support_12"            "support_biascheck"     "support_bias_dummy"   
## [163] "Q96_First.Click"       "Q96_Last.Click"        "Q96_Page.Submit"      
## [166] "Q96_Click.Count"       "SocMedia_1"            "SocMedia_2"           
## [169] "SocMedia_3"            "SocMedia_4"            "SocMedia_5"           
## [172] "SocMedia_6"            "SocMedia_7"            "SocMedia_8"           
## [175] "SocMedia_9"            "SocMedia_10"           "SocMedia_11"          
## [178] "SocMedia_biascheck"    "SocMedia_bias_dummy"   "Q80_First.Click"      
## [181] "Q80_Last.Click"        "Q80_Page.Submit"       "Q80_Click.Count"      
## [184] "usdream_1"             "usdream_2"             "usdream_3"            
## [187] "Q73_First.Click"       "Q73_Last.Click"        "Q73_Page.Submit"      
## [190] "Q73_Click.Count"       "freq"                  "transgres"            
## [193] "relation"              "relation_10_TEXT"      "fault"                
## [196] "feel"                  "common"                "attenion2"            
## [199] "Q78_First.Click"       "Q78_Last.Click"        "Q78_Page.Submit"      
## [202] "Q78_Click.Count"       "transgres_1"           "transgres_2"          
## [205] "transgres_3"           "transgres_4"           "Q79_First.Click"      
## [208] "Q79_Last.Click"        "Q79_Page.Submit"       "Q79_Click.Count"      
## [211] "NPI1"                  "NPI2"                  "NPI3"                 
## [214] "NPI4"                  "NPI5"                  "NPI6"                 
## [217] "NPI7"                  "NPI8"                  "NPI9"                 
## [220] "NPI10"                 "NPI11"                 "NPI12"                
## [223] "NPI13"                 "exploit_1"             "exploit_2"            
## [226] "exploit_3"             "NPI_biascheck"         "NPI_bias_dummy"       
## [229] "Q76_First.Click"       "Q76_Last.Click"        "Q76_Page.Submit"      
## [232] "Q76_Click.Count"       "Q11"                   "Q14_1"                
## [235] "Q14_2"                 "Q14_3"                 "Q14_4"                
## [238] "Q14_5"                 "Q14_6"                 "Q14_6_TEXT"           
## [241] "Q10_1"                 "Q10_2"                 "Q10_3"                
## [244] "Q10_4"                 "Q10_5"                 "Q10_6"                
## [247] "Q10_7"                 "Q10_8"                 "Q10_9"                
## [250] "Q10_10"                "Q10_11"                "Q10_12"               
## [253] "Q10_13"                "Q10_14"                "Q10_15"               
## [256] "Q71_First.Click"       "Q71_Last.Click"        "Q71_Page.Submit"      
## [259] "Q71_Click.Count"       "physSx_1"              "physSx_2"             
## [262] "physSx_3"              "physSx_4"              "physSx_5"             
## [265] "physSx_6"              "physSx_7"              "physSx_8"             
## [268] "physSx_9"              "physSx_10"             "physSx_11"            
## [271] "physSx_12"             "physSx_13"             "phys_sx_biaschec"     
## [274] "phys_sym_bias_dummy."  "Q70_First.Click"       "Q70_Last.Click"       
## [277] "Q70_Page.Submit"       "Q70_Click.Count"       "stress_1"             
## [280] "stress_2"              "stress_3"              "stress_4"             
## [283] "stress_5"              "stress_6"              "stress_7"             
## [286] "stress_8"              "stress_9"              "stress_10"            
## [289] "stress_biascheck"      "stress_bias_dummy"     "Q69_First.Click"      
## [292] "Q69_Last.Click"        "Q69_Page.Submit"       "Q69_Click.Count"      
## [295] "marriage1_1"           "marriage1_2"           "marriage1_3"          
## [298] "marriage1_4"           "marriage2"             "marriage3"            
## [301] "marriage4"             "marriage5"             "Q75_First.Click"      
## [304] "Q75_Last.Click"        "Q75_Page.Submit"       "Q75_Click.Count"      
## [307] "school"                "sex"                   "age"                  
## [310] "edu"                   "sibling"               "race"                 
## [313] "race_6_TEXT"           "Q82"                   "Q83"                  
## [316] "income"                "place2"                "Q80"                  
## [319] "place"                 "Q81"                   "Q81_First.Click"      
## [322] "Q81_Last.Click"        "Q81_Page.Submit"       "Q81_Click.Count"      
## [325] "comments"              "affiliation"           "response_bias_SUM"    
## [328] "school_coded"
head(df)
##   StartDate  EndDate Status Progress Duration..in.seconds. Finished
## 1  12/02/16 12/02/16      0      100                  1839        1
## 2  11/16/16 11/16/16      0      100                  1467        1
## 3  11/09/16 11/09/16      0       99                  2185        0
## 4  11/07/16 11/07/16      0      100                  2904        1
## 5  11/18/16 11/18/16      0      100                  1229        1
## 6  11/07/16 11/07/16      0      100                  2068        1
##       RecordedDate        ResponseId RecipientLastName RecipientFirstName
## 1   12/2/2016 5:38 R_BJN3bQqi1zUMid3                NA                 NA
## 2 11/16/2016 11:53 R_2TGbiBXmAtxywsD                NA                 NA
## 3  11/16/2016 1:22 R_12G7bIqN2wB2N65                NA                 NA
## 4   11/7/2016 4:54 R_39pldNoon8CePfP                NA                 NA
## 5  11/18/2016 0:30 R_1QiKb2LdJo1Bhvv                NA                 NA
## 6  11/7/2016 14:42 R_pmwDTZyCyCycXwB                NA                 NA
##   RecipientEmail ExternalReference DistributionChannel informedconsent moa1.1_1
## 1             NA                NA           anonymous               1        4
## 2             NA                NA           anonymous               1        4
## 3             NA                NA           anonymous               1        4
## 4             NA                NA           anonymous               1        4
## 5             NA                NA           anonymous               1        4
## 6             NA                NA           anonymous               1        4
##   moa1.1_2 moa1.1_3 moa1.1_4 moa1.1_5 moa1.1_6 moa1.1_7 moa1.1_8 moa1.1_9
## 1        4        3        2        2        3        2        1        4
## 2        4        4        2        3        3        4        3        3
## 3        4        4        1        1        4        2        3        4
## 4        3        3        1        1        2        1        1        1
## 5        4        4        1        1        3        1        1        4
## 6        3        4        2        3        4        2        1        3
##   moa1.1_10 moa1.2_1 moa1.2_2 moa1.2_3 moa1.2_4 moa1.2_5 moa1.2_6 moa1.2_7
## 1         3        2        1        2        1        1        1        2
## 2         3        1        1        2        2        1        1        1
## 3         3        2        1        1        1        1        1        2
## 4         1        1        1        1        1        1        1        2
## 5         3        2        1        2        1        3        3        1
## 6         4        1        1        1        1        1        1        1
##   moa1.2_8 moa1.2_9 moa1.2_10 moa2.1_1 moa2.1_2 moa2.1_3 moa2.1_4 moa2.1_5
## 1        3        3         2        4        4        4        4        3
## 2        1        2         3        3        4        2        4        4
## 3        3        3         3        4        2        2        4        3
## 4        3        2         3        4        2        2        4        3
## 5        1        3         2        4        4        3        4        4
## 6        1        1         3        4        4        4        4        2
##   moa2.1_6 moa2.1_7 moa2.1_8 moa2.1_9 moa2.1_10 moa2.2_1 moa2.2_2 moa2.2_3
## 1        4        4        4        3         2        2        1        1
## 2        3        2        4        2         1        3        1        2
## 3        3        4        4        3         2        2        1        1
## 4        2        4        2        3         2        2        1        1
## 5        3        4        4        3         3        3        3        3
## 6        4        3        4        4         4        2        1        1
##   moa2.2_4 moa2.2_5 moa2.2_6 moa2.2_7 moa2.2_8 moa2.2_9 moa2.2_10 adult_Q
## 1        3        2        3        3        2        2         1       1
## 2        2        1        2        2        2        2         1       1
## 3        2        1        2        3        1        1         1       1
## 4        2        1        2        2        2        2         1       1
## 5        3        3        2        3        3        2         3       1
## 6        2        1        2        2        1        2         1       1
##   MOA_IMP_biascheck MOA_ach_biascheck MOA_IMP_dummy MOA.ACH_dummy
## 1                64                38             0             0
## 2                62                33             0             0
## 3                61                33             0             0
## 4                46                32             0             0
## 5                62                47             0             0
## 6                67                27             0             0
##   Q65_First.Click Q65_Last.Click Q65_Page.Submit Q65_Click.Count IDEA_1 IDEA_2
## 1          37.139        307.731         308.890              45      3      4
## 2         120.026        336.428         338.177              58      4      4
## 3          27.705        154.447         155.544              47      4      4
## 4          19.656        297.285         298.509              43      4      4
## 5          12.867        121.932         122.254              46      4      4
## 6          15.652        223.372         225.431              50      3      4
##   IDEA_3 IDEA_4 IDEA_5 IDEA_6 IDEA_7 IDEA_8 IDEA.biascheck IDEA.bias.dummy
## 1      4      3      4      4      4      4             30               0
## 2      4      4      3      4      4      4             31               0
## 3      4      4      4      4      3      3             30               0
## 4      3      3      4      4      4      4             30               0
## 5      3      4      3      3      3      4             28               0
## 6      3      3      4      4      3      2             26               0
##   Q66_First.Click Q66_Last.Click Q66_Page.Submit Q66_Click.Count politics party
## 1          44.705         86.585          87.514              11        2     3
## 2          19.927         65.200          67.162              13        1     4
## 3          23.170         51.401          52.408              11        2     8
## 4          27.467        172.797         174.119               9        8     8
## 5          23.952         52.176          53.355               9        1     8
## 6           9.475         72.935          73.937              13        8     8
##                                                                            president
## 1                                                                                   
## 2 None, but I was a US Citizen and had a gun next to my head, I would vote for Trump
## 3                                                                    Hillary Clinton
## 4                                                                    Hillary Clinton
## 5                                                                            Sanders
## 6                                                                            No one.
##   Q74_First.Click Q74_Last.Click Q74_Page.Submit Q74_Click.Count swb_1 swb_2
## 1          13.052         40.445          46.399               2     4     6
## 2           4.899         28.125          55.107               6     3     4
## 3          34.868         48.402          56.371               4     1     2
## 4          66.886        119.219         135.295               4     5     6
## 5          23.614         32.221          35.338               4     2     5
## 6          12.314         41.232          54.436               6     4     4
##   swb_3 swb_4 swb_5 swb_6 Q67_First.Click Q67_Last.Click Q67_Page.Submit
## 1     5     5     3     3           9.627         40.388          41.198
## 2     5     5     4     4           8.607         29.115          29.955
## 3     2     2     2     2          37.656         53.240          54.603
## 4     6     5     6     3          13.587         55.197          56.150
## 5     5     3     2     5           6.798         22.246          23.138
## 6     6     5     1     4           7.927         44.108          48.227
##   Q67_Click.Count mindful_1 mindful_2 mindful_3 mindful_4 mindful_5 mindful_6
## 1               7         4         2         2         2         4         1
## 2               7         2         2         2         1         3         1
## 3               9         2         3         1         2         3         1
## 4               7         2         2         1         2         2         1
## 5               7         4         5         3         2         4         1
## 6               7         1         4         3         3         5         1
##   mindful_7 mindful_8 mindful_9 mindful_10 mindful_11 mindful_12 mindful_13
## 1         2         2         2          2          2          4          1
## 2         1         1         2          2          1          2          1
## 3         2         2         5          3          2          1          1
## 4         2         2         3          2          2          3          3
## 5         4         2         1          2          2          6          5
## 6         5         6         3          5          1          3          2
##   mindful_14 mindful_15 mindful_biascheck mindful_bias_dummy Q68_First.Click
## 1          2          4                36                  0          32.692
## 2          1          5                27                  0          13.184
## 3          1          4                33                  0          48.022
## 4          2          4                33                  0         110.432
## 5          2          5                48                  0          81.124
## 6          4          5                51                  0          33.458
##   Q68_Last.Click Q68_Page.Submit Q68_Click.Count belong_1 belong_2 belong_3
## 1        154.123         157.391              15        4        2        4
## 2         76.856          77.629              22        2        3        1
## 3        142.665         143.398              20        4        4        2
## 4        255.734         257.134              17        3        4        1
## 5        134.499         135.848              16        4        3        3
## 6        212.770         213.511              25        2        3        2
##   belong_4 belong_5 belong_6 belong_7 belong_8 belong_9 belong_10 belnow
## 1        4        4        2        5        2        4         3      4
## 2        5        4        4        2        4        5         4      4
## 3        5        4        4        2        3        4         4      2
## 4        5        4        5        2        4        4         4      4
## 5        4        4        5        1        3        2         3      4
## 6        5        4        5        1        4        4         4      3
##   belong_biascheck belong_bias_dummy Q72_First.Click Q72_Last.Click
## 1               38                 0           8.221         80.460
## 2               38                 0           6.774         65.987
## 3               38                 0           5.697         71.192
## 4               40                 0           6.096         86.373
## 5               36                 0          58.613        121.436
## 6               37                 0           6.124         70.638
##   Q72_Page.Submit Q72_Click.Count efficacy_1 efficacy_2 efficacy_3 efficacy_4
## 1          82.781              13          4          3          4          3
## 2          67.158              18          3          3          3          4
## 3          72.176              13          3          3          1          2
## 4          87.231              14          4          1          2          3
## 5         122.620              11          3          3          2          3
## 6          72.503              15          3          2          3          2
##   efficacy_5 efficacy_6 efficacy_7 efficacy_8 efficacy_9 efficacy_10
## 1          3          4          3          3          4           3
## 2          4          4          3          3          3           4
## 3          2          3          1          3          2           2
## 4          2          4          2          3          4           3
## 5          3          3          3          3          4           3
## 6          1          3          2          3          3           2
##   efficacy_biascheck efficacy_bias_dummy Q77_First.Click Q77_Last.Click
## 1                 34                   0          15.372        104.315
## 2                 34                   0          11.711         74.768
## 3                 22                   0          38.964        179.667
## 4                 28                   0          16.050        168.886
## 5                 30                   0          32.150         59.030
## 6                 24                   0           6.259         69.817
##   Q77_Page.Submit Q77_Click.Count support_1 support_2 support_3 support_4
## 1         105.195              11         7         4         6         5
## 2          75.558              21         7         7         7         6
## 3         182.727              13         6         6         5         2
## 4         170.530              10         6         6         7         3
## 5          60.273              11         6         6         5         5
## 6          70.970              13         7         7         6         6
##   support_5 support_6 support_7 support_8 support_9 support_10 support_11
## 1         6         6         7         7         7          4          6
## 2         7         6         6         7         7          7          7
## 3         7         5         5         3         6          6          5
## 4         7         6         5         4         6          6          6
## 5         6         6         7         6         6          6          7
## 6         7         2         2         1         1          7          6
##   support_12 support_biascheck support_bias_dummy Q96_First.Click
## 1          7                72                  0          12.241
## 2          7                81                  0           7.482
## 3          6                62                  0          18.845
## 4          5                67                  0          30.307
## 5          6                72                  0          13.096
## 6          2                54                  0          24.841
##   Q96_Last.Click Q96_Page.Submit Q96_Click.Count SocMedia_1 SocMedia_2
## 1         91.497          92.381              17          4          2
## 2         34.247          35.467              19          3          2
## 3         74.388          76.037              14          3          3
## 4        150.285         151.869              18          4          2
## 5         43.727          45.041              12          3          3
## 6        110.942         111.636              18          1          1
##   SocMedia_3 SocMedia_4 SocMedia_5 SocMedia_6 SocMedia_7 SocMedia_8 SocMedia_9
## 1          5          3          5          5          5          4          5
## 2          4          2          1          1          1          1          2
## 3          4          2          3          4          4          2          3
## 4          5          2          2          4          4          1          3
## 5          5          2          2          4          4          2          4
## 6          2          1          1          1          2          1          1
##   SocMedia_10 SocMedia_11 SocMedia_biascheck SocMedia_bias_dummy
## 1           5           4                 47                   0
## 2           4           2                 23                   0
## 3           3           3                 34                   0
## 4           4           4                 35                   0
## 5           4           4                 37                   0
## 6           1           1                 13                   0
##   Q80_First.Click Q80_Last.Click Q80_Page.Submit Q80_Click.Count usdream_1
## 1          17.470         59.573          60.431              11         4
## 2          10.768         45.340          47.007              15         4
## 3          30.059         66.498          68.018              12         2
## 4         112.432        161.455         163.036              11         1
## 5          22.246         53.406          55.275              12         3
## 6           5.361         89.568          90.785              15         1
##   usdream_2 usdream_3 Q73_First.Click Q73_Last.Click Q73_Page.Submit
## 1         4         1          14.144         24.073          27.558
## 2         4         1           5.240         27.206          36.973
## 3         2         1           5.671         16.751          19.891
## 4         3         1          71.153         82.926          98.687
## 5         4         1          21.293         32.533          35.448
## 6         1         2           6.771         37.203          45.268
##   Q73_Click.Count freq
## 1               3    3
## 2               5    4
## 3               3    6
## 4               3    3
## 5               3    4
## 6               4    2
##                                                                      transgres
## 1 told my friend that something he did was wrong and hurtful to somebody else.
## 2                                                             got very passive
## 3                                                     you don't want to see me
## 4                                I tried to excuse myself and said I was sorry
## 5                                                                  Got angry. 
## 6                                                     why didn't you tell him?
##   relation relation_10_TEXT fault        feel common attenion2 Q78_First.Click
## 1        4                      6           3      3         7          22.366
## 2        7                      2 1,4,5,6,7,8      4         7           6.174
## 3        5                      3           6      5         7           9.705
## 4        4                      3      10,4,6      2         7          58.517
## 5        7                      2         5,6      3        NA           5.647
## 6        6                      3           1      4         7          15.862
##   Q78_Last.Click Q78_Page.Submit Q78_Click.Count transgres_1 transgres_2
## 1        148.934         153.134              12           3           1
## 2         72.626          74.609              22           4           3
## 3        109.167         111.847              10           3           1
## 4        195.290         199.227              14           4           2
## 5         61.894          65.304              13           4           2
## 6        174.894         177.914              21           1           3
##   transgres_3 transgres_4 Q79_First.Click Q79_Last.Click Q79_Page.Submit
## 1           1           1          16.239         27.208          28.488
## 2           2           1          20.400         31.697          32.941
## 3           4           1          57.079         77.311          82.171
## 4           1           1          23.005         49.246          50.303
## 5           2           1          11.727         23.987          25.130
## 6           1           1          14.701         35.077          40.711
##   Q79_Click.Count NPI1 NPI2 NPI3 NPI4 NPI5 NPI6 NPI7 NPI8 NPI9 NPI10 NPI11
## 1               4    1    1    1    2    1    2    2    1    2     2     1
## 2               4    2    2    1    2    1    2    1    1    1     1     2
## 3               5    2    1    1    2    1    2    1    1    1     2     2
## 4               5    2    2    1    2    1    2    2    1    1     2     1
## 5               8    1    2    1    2    1    2    2    2    1     2     1
## 6               6    2    2    2    1    2    2    2    2    1     2     1
##   NPI12 NPI13 exploit_1 exploit_2 exploit_3 NPI_biascheck NPI_bias_dummy
## 1     2     1         2         2         2            19              0
## 2     1     1         4         4         3            18              0
## 3     2     1         5         5         3            19              0
## 4     2     1         2         1         2            20              0
## 5     2     2         5         4         3            21              0
## 6     2     2         1         1         2            23              0
##   Q76_First.Click Q76_Last.Click Q76_Page.Submit Q76_Click.Count Q11 Q14_1
## 1          25.575        141.688         142.668              16   2     2
## 2          10.473        103.989         105.050              35   2     2
## 3          29.957        129.786         132.515              22   2     2
## 4          49.912        222.748         223.703              18   2     2
## 5           5.315        108.076         109.093              25   2     2
## 6           5.353         94.716          98.083              25   2     2
##   Q14_2 Q14_3 Q14_4 Q14_5 Q14_6 Q14_6_TEXT Q10_1 Q10_2 Q10_3 Q10_4 Q10_5 Q10_6
## 1     2     2     2     2     2               NA    NA    NA    NA    NA    NA
## 2     2     2     2     2    NA               NA    NA    NA    NA    NA    NA
## 3     2     2     1     2     2                4     3     4     2     4     5
## 4     2     2     2     2     2               NA    NA    NA    NA    NA    NA
## 5     2     2     2     2    NA               NA    NA    NA    NA    NA    NA
## 6     2     2     2     2     2               NA    NA    NA    NA    NA    NA
##   Q10_7 Q10_8 Q10_9 Q10_10 Q10_11 Q10_12 Q10_13 Q10_14 Q10_15 Q71_First.Click
## 1    NA    NA    NA     NA     NA     NA     NA     NA     NA           5.199
## 2    NA    NA    NA     NA     NA     NA     NA     NA     NA           6.497
## 3     3     1     4      1      3      1      4      2      2           4.533
## 4    NA    NA    NA     NA     NA     NA     NA     NA     NA           7.430
## 5    NA    NA    NA     NA     NA     NA     NA     NA     NA           5.020
## 6    NA    NA    NA     NA     NA     NA     NA     NA     NA          15.872
##   Q71_Last.Click Q71_Page.Submit Q71_Click.Count physSx_1 physSx_2 physSx_3
## 1         28.239          28.669               7        3        1        1
## 2         23.457          24.600               8        2        2        1
## 3        115.299         116.410              21        3        1        1
## 4        122.984         128.490              12        2        3        2
## 5          7.996          17.581               6        1        1        1
## 6         32.719          33.562               7        1        2        2
##   physSx_4 physSx_5 physSx_6 physSx_7 physSx_8 physSx_9 physSx_10 physSx_11
## 1        2        1        2        1        2        2         2         2
## 2        1        3        1        1        3        2         1         1
## 3        3        2        2        1        3        2         1         2
## 4        3        1        2        1        2        1         1         2
## 5        2        1        1        1        1        2         1         1
## 6        1        2        2        1        3        1         2         2
##   physSx_12 physSx_13 phys_sx_biaschec phys_sym_bias_dummy. Q70_First.Click
## 1         3         2               24                    0          13.703
## 2         3         3               24                    0           5.209
## 3         3         3               27                    0          36.694
## 4         3         2               25                    0          47.764
## 5         2         1               16                    0           4.561
## 6         3         2               24                    0          10.062
##   Q70_Last.Click Q70_Page.Submit Q70_Click.Count stress_1 stress_2 stress_3
## 1         54.318          60.887              16        2        4        5
## 2         27.841          28.982              17        4        5        5
## 3         79.053          80.519              18        4        4        5
## 4         77.308          79.068              13        2        4        4
## 5         18.707          20.343              14        4        3        3
## 6         80.372          82.827              18        3        3        5
##   stress_4 stress_5 stress_6 stress_7 stress_8 stress_9 stress_10
## 1        3        3        3        4        3        3         3
## 2        4        3        3        2        2        4         4
## 3        2        1        5        2        2        4         4
## 4        3        4        5        4        2        2         2
## 5        4        3        4        3        3        4         4
## 6        2        3        5        2        1        3         2
##   stress_biascheck stress_bias_dummy Q69_First.Click Q69_Last.Click
## 1               33                 0          10.383        100.428
## 2               36                 0           9.729         43.281
## 3               33                 0          42.213         89.329
## 4               32                 0          43.206        180.767
## 5               35                 0          63.797         76.765
## 6               29                 0          16.412         94.543
##   Q69_Page.Submit Q69_Click.Count marriage1_1 marriage1_2 marriage1_3
## 1         101.287              14          10          25          30
## 2          44.423              13          10          25          35
## 3          91.194              12           1           1          59
## 4         182.932              12           0           0          60
## 5          77.998              13          25          25          25
## 6          95.709              15          13          33          21
##   marriage1_4 marriage2 marriage3 marriage4 marriage5 Q75_First.Click
## 1          35         2        20         1         2          20.229
## 2          30         3        19         1         1          11.100
## 3          39         2        19         1         1          40.807
## 4          40         1        16         1         1          74.778
## 5          25         2        14         3         1          21.347
## 6          33         3        17         1         1          19.366
##   Q75_Last.Click Q75_Page.Submit Q75_Click.Count                     school sex
## 1        164.560         165.870              32                        ACG   2
## 2         60.223          61.354              17                  ACG,Deree   1
## 3        160.366         165.459              23 American College of Greece   1
## 4        155.971         156.974              13 American College of Greece   2
## 5         48.802          49.742              11 American College of Greece   1
## 6        181.747         183.288              25 American College of Greece   2
##   age edu sibling race race_6_TEXT Q82 Q83 income place2 Q80 place    Q81
## 1  20   2       2    1               3  NA      3      2  NA    NA Greece
## 2  23   5       2    1               3  NA      3      2  NA    NA Greece
## 3  23   2       5    1               3  NA      1      2  NA    NA Greece
## 4  22   2   3,5,7    6       Greek   3  NA      1      2  NA    NA Greece
## 5  18   2   3,5,7    1               3  NA      6      2  NA    NA Greece
## 6  23   2     2,4    1               3  NA      1      2  NA    NA Greece
##   Q81_First.Click Q81_Last.Click Q81_Page.Submit Q81_Click.Count
## 1           0.000          0.000           5.781               0
## 2           2.424          2.424           6.621               1
## 3           0.000          0.000           9.294               0
## 4           2.679          2.679           5.803               1
## 5           1.632          1.632           5.500               1
## 6           2.766          2.766           6.995               1
##                                                                                                                              comments
## 1                                                                                                        I have completed this survey
## 2                                                                                                        i have completed this survey
## 3 Didn't know my household income.\nI have completed the last question about disability wrong. I read "not" the moment I pressed ">>"
## 4                                                                                                        I have completed this survey
## 5                                                                                                        i have completed this survey
## 6                                                                                             The question saying "Select" was funny.
##   affiliation response_bias_SUM school_coded
## 1    acgreece                 0     acgreece
## 2    acgreece                 0     acgreece
## 3    acgreece                 0     acgreece
## 4    acgreece                 0     acgreece
## 5    acgreece                 0     acgreece
## 6    acgreece                 0     acgreece
str(df)
## 'data.frame':    3182 obs. of  328 variables:
##  $ StartDate            : chr  "12/02/16" "11/16/16" "11/09/16" "11/07/16" ...
##  $ EndDate              : chr  "12/02/16" "11/16/16" "11/09/16" "11/07/16" ...
##  $ Status               : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Progress             : int  100 100 99 100 100 100 99 99 100 100 ...
##  $ Duration..in.seconds.: int  1839 1467 2185 2904 1229 2068 1656 1839 1160 2134 ...
##  $ Finished             : int  1 1 0 1 1 1 0 0 1 1 ...
##  $ RecordedDate         : chr  "12/2/2016 5:38" "11/16/2016 11:53" "11/16/2016 1:22" "11/7/2016 4:54" ...
##  $ ResponseId           : chr  "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
##  $ RecipientLastName    : logi  NA NA NA NA NA NA ...
##  $ RecipientFirstName   : logi  NA NA NA NA NA NA ...
##  $ RecipientEmail       : logi  NA NA NA NA NA NA ...
##  $ ExternalReference    : logi  NA NA NA NA NA NA ...
##  $ DistributionChannel  : chr  "anonymous" "anonymous" "anonymous" "anonymous" ...
##  $ informedconsent      : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ moa1.1_1             : int  4 4 4 4 4 4 4 4 4 3 ...
##  $ moa1.1_2             : int  4 4 4 3 4 3 4 4 4 2 ...
##  $ moa1.1_3             : int  3 4 4 3 4 4 4 4 4 3 ...
##  $ moa1.1_4             : int  2 2 1 1 1 2 3 3 4 1 ...
##  $ moa1.1_5             : int  2 3 1 1 1 3 3 3 4 1 ...
##  $ moa1.1_6             : int  3 3 4 2 3 4 4 4 4 2 ...
##  $ moa1.1_7             : int  2 4 2 1 1 2 4 3 1 3 ...
##  $ moa1.1_8             : int  1 3 3 1 1 1 4 3 2 3 ...
##  $ moa1.1_9             : int  4 3 4 1 4 3 4 4 4 4 ...
##  $ moa1.1_10            : int  3 3 3 1 3 4 3 3 4 3 ...
##  $ moa1.2_1             : int  2 1 2 1 2 1 1 2 2 2 ...
##  $ moa1.2_2             : int  1 1 1 1 1 1 1 2 2 2 ...
##  $ moa1.2_3             : int  2 2 1 1 2 1 2 2 2 2 ...
##  $ moa1.2_4             : int  1 2 1 1 1 1 1 1 1 1 ...
##  $ moa1.2_5             : int  1 1 1 1 3 1 1 1 1 1 ...
##  $ moa1.2_6             : int  1 1 1 1 3 1 1 1 2 2 ...
##  $ moa1.2_7             : int  2 1 2 2 1 1 3 3 1 3 ...
##  $ moa1.2_8             : int  3 1 3 3 1 1 3 3 3 3 ...
##  $ moa1.2_9             : int  3 2 3 2 3 1 3 3 3 3 ...
##  $ moa1.2_10            : int  2 3 3 3 2 3 3 3 1 3 ...
##  $ moa2.1_1             : int  4 3 4 4 4 4 4 4 4 3 ...
##  $ moa2.1_2             : int  4 4 2 2 4 4 4 4 4 3 ...
##  $ moa2.1_3             : int  4 2 2 2 3 4 3 4 4 3 ...
##  $ moa2.1_4             : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ moa2.1_5             : int  3 4 3 3 4 2 4 4 4 3 ...
##  $ moa2.1_6             : int  4 3 3 2 3 4 4 3 4 4 ...
##  $ moa2.1_7             : int  4 2 4 4 4 3 4 4 2 4 ...
##  $ moa2.1_8             : int  4 4 4 2 4 4 3 4 4 4 ...
##  $ moa2.1_9             : int  3 2 3 3 3 4 4 4 4 4 ...
##  $ moa2.1_10            : int  2 1 2 2 3 4 2 4 2 2 ...
##  $ moa2.2_1             : int  2 3 2 2 3 2 2 2 3 3 ...
##  $ moa2.2_2             : int  1 1 1 1 3 1 1 1 1 2 ...
##  $ moa2.2_3             : int  1 2 1 1 3 1 1 1 3 3 ...
##  $ moa2.2_4             : int  3 2 2 2 3 2 2 3 3 3 ...
##  $ moa2.2_5             : int  2 1 1 1 3 1 1 1 2 2 ...
##  $ moa2.2_6             : int  3 2 2 2 2 2 2 2 3 3 ...
##  $ moa2.2_7             : int  3 2 3 2 3 2 1 2 1 3 ...
##  $ moa2.2_8             : int  2 2 1 2 3 1 2 3 2 2 ...
##  $ moa2.2_9             : int  2 2 1 2 2 2 2 2 3 3 ...
##  $ moa2.2_10            : int  1 1 1 1 3 1 1 1 1 2 ...
##  $ adult_Q              : int  1 1 1 1 1 1 1 1 1 2 ...
##  $ MOA_IMP_biascheck    : int  64 62 61 46 62 67 73 74 71 59 ...
##  $ MOA_ach_biascheck    : int  38 33 33 32 47 27 34 39 40 48 ...
##  $ MOA_IMP_dummy        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ MOA.ACH_dummy        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Q65_First.Click      : num  37.1 120 27.7 19.7 12.9 ...
##  $ Q65_Last.Click       : num  308 336 154 297 122 ...
##  $ Q65_Page.Submit      : num  309 338 156 299 122 ...
##  $ Q65_Click.Count      : int  45 58 47 43 46 50 45 42 47 47 ...
##  $ IDEA_1               : int  3 4 4 4 4 3 4 4 4 4 ...
##  $ IDEA_2               : int  4 4 4 4 4 4 3 3 4 4 ...
##  $ IDEA_3               : int  4 4 4 3 3 3 4 3 3 2 ...
##  $ IDEA_4               : int  3 4 4 3 4 3 4 4 2 2 ...
##  $ IDEA_5               : int  4 3 4 4 3 4 3 3 4 4 ...
##  $ IDEA_6               : int  4 4 4 4 3 4 4 2 4 4 ...
##  $ IDEA_7               : int  4 4 3 4 3 3 3 2 3 3 ...
##  $ IDEA_8               : int  4 4 3 4 4 2 3 3 3 4 ...
##  $ IDEA.biascheck       : int  30 31 30 30 28 26 28 24 27 27 ...
##  $ IDEA.bias.dummy      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Q66_First.Click      : num  44.7 19.9 23.2 27.5 24 ...
##  $ Q66_Last.Click       : num  86.6 65.2 51.4 172.8 52.2 ...
##  $ Q66_Page.Submit      : num  87.5 67.2 52.4 174.1 53.4 ...
##  $ Q66_Click.Count      : int  11 13 11 9 9 13 9 8 8 9 ...
##  $ politics             : int  2 1 2 8 1 8 4 2 8 4 ...
##  $ party                : int  3 4 8 8 8 8 4 1 3 8 ...
##  $ president            : chr  "" "None, but I was a US Citizen and had a gun next to my head, I would vote for Trump" "Hillary Clinton" "Hillary Clinton" ...
##  $ Q74_First.Click      : num  13.1 4.9 34.9 66.9 23.6 ...
##  $ Q74_Last.Click       : num  40.4 28.1 48.4 119.2 32.2 ...
##  $ Q74_Page.Submit      : num  46.4 55.1 56.4 135.3 35.3 ...
##  $ Q74_Click.Count      : int  2 6 4 4 4 6 3 3 3 3 ...
##  $ swb_1                : int  4 3 1 5 2 4 4 5 5 5 ...
##  $ swb_2                : int  6 4 2 6 5 4 4 5 5 4 ...
##  $ swb_3                : int  5 5 2 6 5 6 5 6 5 6 ...
##  $ swb_4                : int  5 5 2 5 3 5 4 5 5 4 ...
##  $ swb_5                : int  3 4 2 6 2 1 1 6 5 6 ...
##  $ swb_6                : int  3 4 2 3 5 4 4 6 5 4 ...
##  $ Q67_First.Click      : num  9.63 8.61 37.66 13.59 6.8 ...
##  $ Q67_Last.Click       : num  40.4 29.1 53.2 55.2 22.2 ...
##  $ Q67_Page.Submit      : num  41.2 30 54.6 56.1 23.1 ...
##  $ Q67_Click.Count      : int  7 7 9 7 7 7 7 7 6 13 ...
##  $ mindful_1            : int  4 2 2 2 4 1 5 3 3 5 ...
##  $ mindful_2            : int  2 2 3 2 5 4 6 2 3 6 ...
##  $ mindful_3            : int  2 2 1 1 3 3 5 4 4 4 ...
##  $ mindful_4            : int  2 1 2 2 2 3 4 2 3 5 ...
##  $ mindful_5            : int  4 3 3 2 4 5 6 2 3 6 ...
##   [list output truncated]

4 Subsetting Data

# use the subset() command to select which columns to keep in your dataframe

# this is the code you'll need for the lab. for the homework assignment, you'll need to customize the code so that the variables are the ones you've chosen.
d <- subset(df, select=c(race,
                        sex,
                        support_1,support_2,support_3,support_4,support_5,support_6,support_7,support_8,support_9, support_10,support_11,support_12,
                        SocMedia_1,SocMedia_2, SocMedia_3, SocMedia_4, SocMedia_5, SocMedia_6, SocMedia_7, SocMedia_8, SocMedia_9, SocMedia_10, SocMedia_11,
                        swb_1, swb_2, swb_3, swb_4, swb_5, swb_6,
                        belong_1,belong_2,belong_3,belong_4,belong_5,belong_6,belong_7,belong_8,belong_9,belong_10))

5 Basic Data Checking

5.1 Checking Values

# use the map() command to view tables for all of your columns/variables at once
d %>%
    map(table, useNA = "always")
## $race
## 
##                   1       1,2     1,2,3 1,2,3,4,5   1,2,3,5     1,2,4   1,2,4,5 
##         9      2026        26         2         1         3         4         3 
##     1,2,5     1,2,6       1,3     1,3,4     1,3,5       1,4     1,4,5       1,5 
##         4         2        98         6         8        39         2        35 
##       1,6         2       2,3     2,3,4   2,3,4,5     2,3,5     2,3,6       2,4 
##        15       249         5         1         1         1         1         6 
##       2,5     2,5,6       2,6         3       3,4     3,4,5       3,5         4 
##         5         1         6       286         9         1         5       210 
##       4,6         5         6      <NA> 
##         3        12        97         0 
## 
## $sex
## 
##    1    2    3 <NA> 
##  792 2332   54    4 
## 
## $support_1
## 
##    1    2    3    4    5    6    7 <NA> 
##  128  148  192  307  449  696 1258    4 
## 
## $support_2
## 
##    1    2    3    4    5    6    7 <NA> 
##  151  131  156  283  410  693 1354    4 
## 
## $support_3
## 
##    1    2    3    4    5    6    7 <NA> 
##   87   92  132  211  427  906 1325    2 
## 
## $support_4
## 
##    1    2    3    4    5    6    7 <NA> 
##  164  155  235  296  568  748 1014    2 
## 
## $support_5
## 
##    1    2    3    4    5    6    7 <NA> 
##  141  132  153  287  393  657 1416    3 
## 
## $support_6
## 
##    1    2    3    4    5    6    7 <NA> 
##   50  103  151  360  673  997  845    3 
## 
## $support_7
## 
##    1    2    3    4    5    6    7 <NA> 
##   71  110  166  333  679  978  842    3 
## 
## $support_8
## 
##    1    2    3    4    5    6    7 <NA> 
##  199  187  298  317  632  695  851    3 
## 
## $support_9
## 
##    1    2    3    4    5    6    7 <NA> 
##   68   65  133  213  534  994 1172    3 
## 
## $support_10
## 
##    1    2    3    4    5    6    7 <NA> 
##  124  115  137  282  359  691 1471    3 
## 
## $support_11
## 
##    1    2    3    4    5    6    7 <NA> 
##   89   81  126  234  542  921 1186    3 
## 
## $support_12
## 
##    1    2    3    4    5    6    7 <NA> 
##   84   94  157  255  646  980  964    2 
## 
## $SocMedia_1
## 
##    1    2    3    4    5 <NA> 
##  302  599 1136  833  308    4 
## 
## $SocMedia_2
## 
##    1    2    3    4    5 <NA> 
##  581  832  820  662  284    3 
## 
## $SocMedia_3
## 
##    1    2    3    4    5 <NA> 
##  148  298  808 1164  761    3 
## 
## $SocMedia_4
## 
##    1    2    3    4    5 <NA> 
##  348  638  830  880  483    3 
## 
## $SocMedia_5
## 
##    1    2    3    4    5 <NA> 
##  386  910 1032  602  249    3 
## 
## $SocMedia_6
## 
##    1    2    3    4    5 <NA> 
##  267  371  820 1042  679    3 
## 
## $SocMedia_7
## 
##    1    2    3    4    5 <NA> 
##  318  433  816  956  654    5 
## 
## $SocMedia_8
## 
##    1    2    3    4    5 <NA> 
##  892  978  684  414  210    4 
## 
## $SocMedia_9
## 
##    1    2    3    4    5 <NA> 
##  414  669 1009  776  310    4 
## 
## $SocMedia_10
## 
##    1    2    3    4    5 <NA> 
##  188  323  879 1116  673    3 
## 
## $SocMedia_11
## 
##    1    2    3    4    5 <NA> 
##  313  572  914  871  509    3 
## 
## $swb_1
## 
##    1    2    3    4    5    6    7 <NA> 
##  234  408  449  467  788  617  215    4 
## 
## $swb_2
## 
##    1    2    3    4    5    6    7 <NA> 
##  108  243  382  458  782  812  394    3 
## 
## $swb_3
## 
##    1    2    3    4    5    6    7 <NA> 
##  125  200  332  375  767  993  386    4 
## 
## $swb_4
## 
##    1    2    3    4    5    6    7 <NA> 
##  137  285  351  416  847  805  337    4 
## 
## $swb_5
## 
##    1    2    3    4    5    6    7 <NA> 
##  374  489  597  318  506  567  327    4 
## 
## $swb_6
## 
##    1    2    3    4    5    6    7 <NA> 
##  255  394  407  416  730  678  298    4 
## 
## $belong_1
## 
##    1    2    3    4    5 <NA> 
##  225  841  626  981  505    4 
## 
## $belong_2
## 
##    1    2    3    4    5 <NA> 
##  276  562  727 1080  533    4 
## 
## $belong_3
## 
##    1    2    3    4    5 <NA> 
##  413  939  672  848  306    4 
## 
## $belong_4
## 
##    1    2    3    4    5 <NA> 
##   91  188  321 1217 1362    3 
## 
## $belong_5
## 
##    1    2    3    4    5 <NA> 
##  132  200  636 1390  821    3 
## 
## $belong_6
## 
##    1    2    3    4    5 <NA> 
##  381  720  800  738  540    3 
## 
## $belong_7
## 
##    1    2    3    4    5 <NA> 
##  428  942  580  809  418    5 
## 
## $belong_8
## 
##    1    2    3    4    5 <NA> 
##  266  558  743 1081  530    4 
## 
## $belong_9
## 
##    1    2    3    4    5 <NA> 
##  279  572  730 1164  433    4 
## 
## $belong_10
## 
##    1    2    3    4    5 <NA> 
##  410  760  637  939  431    5

6 Recoding Variables

table(d$race, useNA = "always")
## 
##                   1       1,2     1,2,3 1,2,3,4,5   1,2,3,5     1,2,4   1,2,4,5 
##         9      2026        26         2         1         3         4         3 
##     1,2,5     1,2,6       1,3     1,3,4     1,3,5       1,4     1,4,5       1,5 
##         4         2        98         6         8        39         2        35 
##       1,6         2       2,3     2,3,4   2,3,4,5     2,3,5     2,3,6       2,4 
##        15       249         5         1         1         1         1         6 
##       2,5     2,5,6       2,6         3       3,4     3,4,5       3,5         4 
##         5         1         6       286         9         1         5       210 
##       4,6         5         6      <NA> 
##         3        12        97         0
d$race_rc <- NA
d$race_rc[df$race == 1] <- "white"
d$race_rc[df$race == 2] <- "black"
d$race_rc[df$race == 3] <- "hispanic"
d$race_rc[df$race == 4] <- "asian"
d$race_rc[df$race == 5] <- "nativeamer"
d$race_rc[df$race == 6] <- "other"
d$race_rc[grep(",", d$race)] <- "multiracial"
 
table(d$race_rc, useNA = "always")
## 
##       asian       black    hispanic multiracial  nativeamer       other 
##         210         249         286         293          12          97 
##       white        <NA> 
##        2026           9
table(d$sex, useNA = "always")
## 
##    1    2    3 <NA> 
##  792 2332   54    4
d$gender[d$sex == "1"] <- "m"
d$gender[d$sex == "2"] <- "f"
d$gender[d$sex == "3"] <- "nb"

table(d$gender, useNA = "always")
## 
##    f    m   nb <NA> 
## 2332  792   54    4

7 Factor Scores/Composite Variables

# use the str() command to check that your recoded variable is numeric so you can use mathematical operators on it
str(d)
## 'data.frame':    3182 obs. of  43 variables:
##  $ race       : chr  "1" "1" "1" "6" ...
##  $ sex        : int  2 1 1 2 1 2 2 2 2 2 ...
##  $ support_1  : int  7 7 6 6 6 7 7 6 7 6 ...
##  $ support_2  : int  4 7 6 6 6 7 7 7 5 6 ...
##  $ support_3  : int  6 7 5 7 5 6 4 6 6 2 ...
##  $ support_4  : int  5 6 2 3 5 6 3 5 6 1 ...
##  $ support_5  : int  6 7 7 7 6 7 7 7 5 4 ...
##  $ support_6  : int  6 6 5 6 6 2 4 7 6 6 ...
##  $ support_7  : int  7 6 5 5 7 2 4 7 7 7 ...
##  $ support_8  : int  7 7 3 4 6 1 3 3 6 2 ...
##  $ support_9  : int  7 7 6 6 6 1 5 7 7 7 ...
##  $ support_10 : int  4 7 6 6 6 7 7 6 6 6 ...
##  $ support_11 : int  6 7 5 6 7 6 4 5 5 2 ...
##  $ support_12 : int  7 7 6 5 6 2 5 7 6 4 ...
##  $ SocMedia_1 : int  4 3 3 4 3 1 3 5 3 5 ...
##  $ SocMedia_2 : int  2 2 3 2 3 1 3 5 2 2 ...
##  $ SocMedia_3 : int  5 4 4 5 5 2 3 5 4 5 ...
##  $ SocMedia_4 : int  3 2 2 2 2 1 3 4 5 3 ...
##  $ SocMedia_5 : int  5 1 3 2 2 1 2 3 4 2 ...
##  $ SocMedia_6 : int  5 1 4 4 4 1 4 4 4 1 ...
##  $ SocMedia_7 : int  5 1 4 4 4 2 4 4 2 1 ...
##  $ SocMedia_8 : int  4 1 2 1 2 1 1 2 3 1 ...
##  $ SocMedia_9 : int  5 2 3 3 4 1 4 3 4 3 ...
##  $ SocMedia_10: int  5 4 3 4 4 1 5 5 3 3 ...
##  $ SocMedia_11: int  4 2 3 4 4 1 5 3 3 3 ...
##  $ swb_1      : int  4 3 1 5 2 4 4 5 5 5 ...
##  $ swb_2      : int  6 4 2 6 5 4 4 5 5 4 ...
##  $ swb_3      : int  5 5 2 6 5 6 5 6 5 6 ...
##  $ swb_4      : int  5 5 2 5 3 5 4 5 5 4 ...
##  $ swb_5      : int  3 4 2 6 2 1 1 6 5 6 ...
##  $ swb_6      : int  3 4 2 3 5 4 4 6 5 4 ...
##  $ belong_1   : int  4 2 4 3 4 2 2 3 4 4 ...
##  $ belong_2   : int  2 3 4 4 3 3 5 4 3 3 ...
##  $ belong_3   : int  4 1 2 1 3 2 1 2 3 3 ...
##  $ belong_4   : int  4 5 5 5 4 5 4 5 3 4 ...
##  $ belong_5   : int  4 4 4 4 4 4 5 4 4 3 ...
##  $ belong_6   : int  2 4 4 5 5 5 4 4 2 1 ...
##  $ belong_7   : int  5 2 2 2 1 1 2 1 5 3 ...
##  $ belong_8   : int  2 4 3 4 3 4 4 3 3 2 ...
##  $ belong_9   : int  4 5 4 4 2 4 4 4 4 1 ...
##  $ belong_10  : int  3 4 4 4 3 4 4 2 4 3 ...
##  $ race_rc    : chr  "white" "white" "white" "other" ...
##  $ gender     : chr  "f" "m" "m" "f" ...
d$support <- (d$support_1 + d$support_2 + d$support_3 + d$support_4 + d$support_5 + d$support_6 + d$support_7 + d$support_8 + d$support_9 + d$support_10 + d$support_11 + d$support_12 )/12

d$SocMedia <- (d$SocMedia_1 + d$SocMedia_2 + d$SocMedia_3 + d$SocMedia_4 + d$SocMedia_5 + d$SocMedia_6 + d$SocMedia_7 + d$SocMedia_8 + d$SocMedia_9 + d$SocMedia_10 + d$SocMedia_11)/11

d$swb <- (d$swb_1 + d$swb_2 + d$swb_3 + d$swb_4 + d$swb_5 + d$swb_6)/6

d$belong <- (d$belong_1 + d$belong_2 + d$belong_3 + d$belong_4 + d$belong_5 + d$belong_6 + d$belong_7 + d$belong_8 + d$belong_9 + d$belong_10)/10

d$race <- (d$race_rc)

8 Exporting Data

# use the subset() command to finalize your current dataframe
# in the version of the subset() command below, a dash is added to the 'c' argument so that instead of keeping the columns listed in the parentheses, R will drop them instead
d2 <- subset(d, select=-c(race_rc, sex, support_1,support_2,support_3,support_4,support_5,support_6,support_7,support_8,support_9, support_10,support_11,support_12,
                        SocMedia_1,SocMedia_2, SocMedia_3, SocMedia_4, SocMedia_5, SocMedia_6, SocMedia_7, SocMedia_8, SocMedia_9, SocMedia_10, SocMedia_11,
                        swb_1, swb_2, swb_3, swb_4, swb_5, swb_6,
                        belong_1,belong_2,belong_3,belong_4,belong_5,belong_6,belong_7,belong_8,belong_9,belong_10))

# use the write.csv() command to export your finalized dataframe
write.csv(d2, file="data/cleaned.csv", row.names = F)

9 Check Data

9.1 Formatting

str(d2)
## 'data.frame':    3182 obs. of  6 variables:
##  $ race    : chr  "white" "white" "white" "other" ...
##  $ gender  : chr  "f" "m" "m" "f" ...
##  $ support : num  6 6.75 5.17 5.58 6 ...
##  $ SocMedia: num  4.27 2.09 3.09 3.18 3.36 ...
##  $ swb     : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ belong  : num  3.4 3.4 3.6 3.6 3.2 3.4 3.5 3.2 3.5 2.7 ...
d2$race <- as.factor(d$race)
d2$gender <- as.factor(d$gender)

9.2 Univariate Normality

describe(d2)
##          vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## race*       1 3173 5.53 2.13   7.00    5.88 0.00   1   7     6 -0.98    -0.68
## gender*     2 3178 1.28 0.49   1.00    1.21 0.00   1   3     2  1.40     0.88
## support     3 3176 5.53 1.13   5.75    5.65 0.99   1   7     6 -1.10     1.39
## SocMedia    4 3175 3.13 0.78   3.18    3.16 0.67   1   5     4 -0.31     0.26
## swb         5 3178 4.47 1.32   4.67    4.53 1.48   1   7     6 -0.36    -0.46
## belong      6 3175 3.31 0.49   3.30    3.33 0.44   1   5     4 -0.33     0.64
##            se
## race*    0.04
## gender*  0.01
## support  0.02
## SocMedia 0.01
## swb      0.02
## belong   0.01

9.3 Histograms

# use the hist() command to create a histogram for your continuous variables
hist(d2$support)

hist(d2$SocMedia)

hist(d2$swb)

hist(d2$belong)

# use the table() command to create a table for your categorical variables (other than your ID variable)
table(d2$race, useNA = "always")
## 
##       asian       black    hispanic multiracial  nativeamer       other 
##         210         249         286         293          12          97 
##       white        <NA> 
##        2026           9
table(d2$gender, useNA = "always")
## 
##    f    m   nb <NA> 
## 2332  792   54    4

10 Missing Data

# use the gg_miss_upset() command to visualize your missing data
gg_miss_upset(d2, nsets = 6)

# create a new dataframe with only your complete cases/observations
d3 <- na.omit(d2)

11 Crosstabs & Scatterplots

11.1 Crosstabs

# use the cross_cases() command to create a crosstab of your categorical variables
cross_cases(d3, gender, race)
 race 
 asian   black   hispanic   multiracial   nativeamer   other   white 
 gender 
   f  151 182 207 221 11 72 1474
   m  57 63 76 61 1 24 505
   nb  1 2 2 10 1 38
   #Total cases  209 247 285 292 12 97 2017

11.2 Scatterplots

# use the plot() command to create scatterplots of your continuous variables
plot(d3$SocMedia, d3$support,
     main="Scatterplot of Social Media Use and Perceived Social Support",
     xlab = "Social Media Use Score",
     ylab = "Perceived Social Support Score")

plot(d3$belong, d3$swb,
      main="Scatterplot of Need to Belong and Subjective Well Being",
     xlab = "Need to Belong Score",
      ylab = "Subjective Well Being Score")

11.3 Boxplots

# use the boxplot() command to create boxplots of your continuous and categorical variables
boxplot(data=d3, support~race,
        main="Boxplot of Perceived Social Support by Race",
        xlab = "Race",
        ylab = "Perceived Social Support Score")

boxplot(data=d3, swb~gender,
        main="Boxplot of Perceived Social Support by Race",
        xlab = "sex",
        ylab = "Subjective Well Being Score")

11.4 Homework Writeup

My continous variables do meet the criteria for skew and kurtosis.

support skew = -1.10 kurtosis = 1.39 SocMedia skew = -0.31 kurtosis = 0.36
swb skew = -0.36 kurtosis = -0.46
belong skew = -0.33 kurtosis = 0.64

I do have missing data, but very little. After omitting to make d3, I went from 3,182 participants to 3,159– meaning that I lost 23 participants. These participants failed to respond to one or more variables in the survey. It seems like the race variable had the least participant response compared to the other omitted cases. The removal of non-response participants are under 4%, meaning that the data can still be relevant.