Load required packages

library(broom)
library(dplyr)
library(tidyr)
library(readr)

Load the dataset

pregint <- read.csv("../data/pregint.csv")

Filter variables

Separate variable names that should not be used:

ignoreVars <- c("ResponseID", "StartDate", "EndDate", "Finished",
    "SC0_0", "SC0_1", "SC0_2", "rid", "gc", "term", "LocationLatitude",
    "LocationLongitude", "LocationAccuracy", "states", "region",
    grep("TEXT", names(pregint), fixed = TRUE, value = TRUE))

validVars <- !names(pregint) %in% ignoreVars

Read names from Excel file and filter variables that have been recoded:

codebookCode <- read_csv("../docs/codebookCode.csv")
## Parsed with column specification:
## cols(
##   codebname = col_character(),
##   dataname = col_character(),
##   value = col_integer(),
##   response = col_character(),
##   subset = col_character(),
##   corresponds = col_character(),
##   recodeName = col_character()
## )
changedNames <- codebookCode[["dataname"]] != codebookCode[["recodeName"]]
mkRemoval <- unlist(codebookCode[changedNames, "dataname"], use.names = FALSE)
descVars <- !names(pregint) %in% c(names(pregint)[!validVars], mkRemoval)
pregintDESC <- pregint[, descVars]
pregintDESC <- pregintDESC[, !vapply(pregintDESC, function(x)
    all(is.na(x)), logical(1L))]

Load helper functions for creating summaries

source("../R/table-helpers.R")

Summary

alldatnames <- names(pregintDESC)
idxVec <- seq_along(pregintDESC)
names(idxVec) <- names(pregintDESC)
lapply(idxVec, function(i, dataset) {
    varname <- alldatnames[[i]]
    if (is.integer(dataset[[i]]) || is.numeric(dataset[[i]])) {
        resx <- .meansd(dataset[[i]], varName = varname)
        cbind(resx, valid = sum(!is.na(dataset[[i]])))
    } else if (is.factor(dataset[[i]]))
        .prop(dataset[[i]])
}, dataset = pregintDESC)
## $Q1.1a
##       M (SD)  valid 
## Q1.1a "1 (0)" "2099"
## 
## $Q1.1b
##       M (SD)  valid 
## Q1.1b "1 (0)" "2099"
## 
## $Q112
##      M (SD)         valid 
## Q112 "32.45 (6.88)" "2099"
## 
## $Q1.9
##    n (%)       
## 0  "959 (45.7)"
## 1  "455 (21.7)"
## 10 "1 (0)"     
## 12 "1 (0)"     
## 2  "409 (19.5)"
## 3  "167 (8)"   
## 4  "64 (3)"    
## 5  "21 (1)"    
## 6  "6 (0.3)"   
## 7  "2 (0.1)"   
## 8  "1 (0)"     
## 9  "2 (0.1)"   
## mm "1 (0)"     
## na "1 (0)"     
## No "8 (0.4)"   
## NO "1 (0)"     
## 
## $Q1.9c
##       M (SD)        valid 
## Q1.9c "1.18 (0.38)" "1069"
## 
## $Q1.9d
##       M (SD)       valid 
## Q1.9d "1.57 (1.1)" "1068"
## 
## $Q1.12
##       M (SD)              valid 
## Q1.12 "336.59 (15278.82)" "2099"
## 
## $Q1.13
##       M (SD)        valid 
## Q1.13 "1.06 (1.28)" "2099"
## 
## $Q2.1
##      M (SD)  valid 
## Q2.1 "1 (0)" "2099"
## 
## $Q3.1
##      M (SD)  valid 
## Q3.1 "1 (0)" "2099"
## 
## $Q3.3
##      M (SD)       valid 
## Q3.3 "1.7 (1.65)" "1069"
## 
## $Q3.16
##       M (SD)       valid 
## Q3.16 "1.39 (0.7)" "1069"
## 
## $Q3.20
##       M (SD)        valid
## Q3.20 "4.78 (0.97)" "695"
## 
## $Q3.23_x15
##           M (SD)  valid
## Q3.23_x15 "1 (0)" "309"
## 
## $Q3.26
##       M (SD)        valid 
## Q3.26 "3.86 (1.63)" "1069"
## 
## $Q121
##      M (SD)       valid
## Q121 "1.3 (0.46)" "865"
## 
## $Q3.38
##       M (SD)  valid 
## Q3.38 "1 (0)" "2099"
## 
## $educ
##                          n (%)       
## College degree/Some Grad "632 (30.1)"
## Grad degree              "239 (11.4)"
## HS diploma/GED           "444 (21.2)"
## LT/some HS               "76 (3.6)"  
## Some college             "708 (33.7)"
## 
## $Anxious
##         M (SD)  valid
## Anxious "1 (0)" "720"
## 
## $Excited
##         M (SD)  valid
## Excited "1 (0)" "729"
## 
## $Frustrated
##            M (SD)  valid
## Frustrated "1 (0)" "216"
## 
## $Happy
##       M (SD)  valid
## Happy "1 (0)" "660"
## 
## $Scared
##        M (SD)  valid
## Scared "1 (0)" "640"
## 
## $Ambivalent
##            M (SD)  valid
## Ambivalent "1 (0)" "45" 
## 
## $Surprised
##           M (SD)  valid
## Surprised "1 (0)" "777"
## 
## $Thankful
##          M (SD)  valid
## Thankful "1 (0)" "415"
## 
## $Unhappy
##         M (SD)  valid
## Unhappy "1 (0)" "181"
## 
## $Worried
##         M (SD)  valid
## Worried "1 (0)" "601"
## 
## $Angry
##       M (SD)  valid
## Angry "1 (0)" "132"
## 
## $Other
##       M (SD)  valid
## Other "1 (0)" "35" 
## 
## $gender
##        n (%)        
## female "1069 (50.9)"
## male   "1030 (49.1)"
## 
## $hispanic
##     n (%)      
## no  "1806 (86)"
## yes "293 (14)" 
## 
## $Q1.9a..Q1.9c
##     n (%)        
## no  "304 (14.5)" 
## yes "1794 (85.5)"
## 
## $Q1.9b..Q1.9d
##                    n (%)       
## 4                  "173 (8.2)" 
## don't have partner "223 (10.6)"
## no                 "192 (9.2)" 
## yes                "1510 (72)" 
## 
## $Q2.2_1..Q2.7_1
##                n (%)       
## can be avoided "1382 (100)"
## 
## $Q2.2_2..Q2.7_2
##                                 n (%)      
## sometimes ‘just happens’ anyway "580 (100)"
## 
## $Q2.2_3..Q2.7_3
##                                                            n (%)      
## is something determined by fate or a higher power like God "330 (100)"
## 
## $Q2.2_5..Q2.7_5
##                                                      n (%)      
## is a natural process that happens when it's meant to "455 (100)"
## 
## $Q2.2_4..Q2.7_4
##       n (%)     
## other "17 (100)"
## 
## $Q2.5
##                                                            n (%)      
## can be avoided                                             "88 (47.8)"
## is a natural process that happens when it's meant to       "32 (17.4)"
## is something determined by fate or a higher power like God "38 (20.7)"
## other                                                      "3 (1.6)"  
## sometimes ‘just happens’ anyway                            "23 (12.5)"
## 
## $Q2.10
##                                                            n (%)       
## can be avoided                                             "128 (53.1)"
## is a natural process that happens when it's meant to       "31 (12.9)" 
## is something determined by fate or a higher power like God "41 (17)"   
## other                                                      "1 (0.4)"   
## sometimes ‘just happens’ anyway                            "40 (16.6)" 
## 
## $Q2.12_1..Q2.13_1
##                  n (%)        
## a little control "259 (12.3)" 
## a lot of control "1045 (49.8)"
## complete control "717 (34.2)" 
## no control       "78 (3.7)"   
## 
## $Q2.13_1..Q3.12_1
##                  n (%)       
## a little control "386 (18.4)"
## a lot of control "964 (45.9)"
## complete control "641 (30.5)"
## no control       "108 (5.1)" 
## 
## $Q3.2..Q3.3
##                                n (%)        
## 6                              "67 (3.2)"   
## 7                              "45 (2.1)"   
## don't know                     "52 (2.5)"   
## don't want me/partner pregnant "35 (1.7)"   
## no                             "286 (13.6)" 
## yes                            "1614 (76.9)"
## 
## $Q3.12_1..Q3.13_1
##                  n (%)       
## a little control "513 (24.4)"
## a lot of control "918 (43.7)"
## complete control "522 (24.9)"
## no control       "146 (7)"   
## 
## $Q3.15..Q3.16
##            n (%)        
## don't know "36 (1.7)"   
## no         "878 (41.8)" 
## yes        "1185 (56.5)"
## 
## $Q3.17_1
##                        n (%)      
## was planned in advance "199 (100)"
## 
## $Q3.17_2
##                                                              n (%)     
## was planned to happen after my ideal criteria were fulfilled "86 (100)"
## 
## $Q3.17_3
##                                           n (%)      
## was planned in discussion with my partner "114 (100)"
## 
## $Q3.17_4
##                 n (%)      
## was not planned "158 (100)"
## 
## $Q3.17_5
##                                               n (%)     
## was left to 'fate' or a higher power like God "48 (100)"
## 
## $Q3.17_6
##                 n (%)     
## 'just happened' "75 (100)"
## 
## $Q3.17_8
##                                               n (%)     
## happened naturally because it was meant to be "38 (100)"
## 
## $Q3.17_7
##       n (%)    
## other "1 (100)"
## 
## $Q3.17a_1
##            n (%)       
## 2          "112 (24.1)"
## 3          "207 (44.6)"
## 4          "97 (20.9)" 
## No control "48 (10.3)" 
## 
## $Q3.18_1
##                        n (%)      
## was planned in advance "184 (100)"
## 
## $Q3.18_2
##                                                              n (%)     
## was planned to happen after my ideal criteria were fulfilled "80 (100)"
## 
## $Q3.18_3
##                                           n (%)      
## was planned in discussion with my partner "177 (100)"
## 
## $Q3.18_4
##                 n (%)      
## was not planned "313 (100)"
## 
## $Q3.18_5
##                                               n (%)     
## was left to 'fate' or a higher power like God "64 (100)"
## 
## $Q3.18_6
##                 n (%)      
## 'just happened' "121 (100)"
## 
## $Q3.18_8
##                                               n (%)     
## happened naturally because it was meant to be "74 (100)"
## 
## $Q3.18_7
##       n (%)    
## other "6 (100)"
## 
## $Q3.18a_1
##                  n (%)       
## A little control "196 (28.6)"
## A lot of control "231 (33.7)"
## Complete control "144 (21)"  
## No control       "114 (16.6)"
## 
## $Q3.19..Q3.20
##                            n (%)       
## didn’t have ideal criteria "57 (4.8)"  
## don’t know                 "89 (7.5)"  
## no                         "396 (33.4)"
## yes                        "643 (54.3)"
## 
## $Q3.23_x1
##                    n (%)      
## finish high school "313 (100)"
## 
## $Q3.23_x2
##                n (%)      
## finish college "210 (100)"
## 
## $Q3.23_x3
##                n (%)      
## start a career "183 (100)"
## 
## $Q3.23_x4
##                          n (%)      
## gain financial stability "279 (100)"
## 
## $Q3.23_x5
##                                   n (%)      
## have a place of one’s own to live "262 (100)"
## 
## $Q3.23_x6
##             n (%)      
## buy a house "203 (100)"
## 
## $Q3.23_x7
##                      n (%)      
## be in a relationship "213 (100)"
## 
## $Q3.23_x8
##            n (%)    
## be married "5 (100)"
## 
## $Q3.23_x10
##       n (%)     
## other "67 (100)"
## 
## $Q3.24
##                                                               n (%)       
## I was not able to fulfill all of my ideal criteria because... "296 (28.2)"
## not applicable - I didn't have any ideal criteria             "315 (30.1)"
## not applicable- I fulfilled all of my ideal criteria          "437 (41.7)"
## 
## $Q3.25..Q3.26
##                                                                   n (%)       
## aren't trying, but would feel okay if you/partner became pregnant "494 (23.5)"
## don't want you/partner to become pregnant soon                    "800 (38.1)"
## other                                                             "142 (6.8)" 
## would like you/partner to become pregnant soon                    "319 (15.2)"
## you/partner can't get pregnant                                    "229 (10.9)"
## you/partner is pregnant                                           "115 (5.5)" 
## 
## $Q3.27_4
##                                                                               n (%)     
## tracking ovulation and/or timing of sexual activity to try to become pregnant "60 (100)"
## 
## $Q3.27_5
##                        n (%)     
## just letting it happen "82 (100)"
## 
## $Q3.27_3
##                                                  n (%)     
## leaving it up to fate or a higher power like God "45 (100)"
## 
## $Q3.27_9
##                         n (%)     
## leaving it up to nature "23 (100)"
## 
## $Q3.27_2
##                                                                                         n (%)    
## in the process of using assisted reproductive technology such as in vitro fertilization "3 (100)"
## 
## $Q3.27_8
##       n (%)    
## other "3 (100)"
## 
## $Q3.28_4
##                                                                               n (%)     
## tracking ovulation and/or timing of sexual activity to try to become pregnant "51 (100)"
## 
## $Q3.28_5
##                        n (%)     
## just letting it happen "65 (100)"
## 
## $Q3.28_3
##                                                  n (%)     
## leaving it up to fate or a higher power like God "28 (100)"
## 
## $Q3.28_9
##                         n (%)     
## leaving it up to nature "26 (100)"
## 
## $Q3.28_2
##                                                                                         n (%)    
## in the process of using assisted reproductive technology such as in vitro fertilization "8 (100)"
## 
## $Q3.28_8
##       n (%)     
## other "13 (100)"
## 
## $Q3.29_5
##                        n (%)     
## just letting it happen "45 (100)"
## 
## $Q3.29_3
##                                                  n (%)     
## leaving it up to fate or a higher power like God "49 (100)"
## 
## $Q3.29_9
##                         n (%)     
## leaving it up to nature "43 (100)"
## 
## $Q3.29_2
##                                                                           n (%)      
## using some form of birth control or contraception every time you have sex "102 (100)"
## 
## $Q3.29_4
##                                                                                      n (%)     
## using some form of birth control or contraception some of the time when you have sex "31 (100)"
## 
## $Q3.29_8
##       n (%)    
## other "5 (100)"
## 
## $Q3.30_5
##                        n (%)     
## just letting it happen "41 (100)"
## 
## $Q3.30_3
##                                                  n (%)     
## leaving it up to fate or a higher power like God "52 (100)"
## 
## $Q3.30_9
##                         n (%)     
## leaving it up to nature "32 (100)"
## 
## $Q3.30_2
##                                                                           n (%)      
## using some form of birth control or contraception every time you have sex "144 (100)"
## 
## $Q3.30_4
##                                                                                      n (%)     
## using some form of birth control or contraception some of the time when you have sex "32 (100)"
## 
## $Q3.30_8
##       n (%)    
## other "9 (100)"
## 
## $Q3.32_1..Q3.33_1
##         n (%)      
## Anxious "720 (100)"
## 
## $Q3.32_2..Q3.33_2
##         n (%)      
## Excited "729 (100)"
## 
## $Q3.32_3..Q3.33_3
##            n (%)      
## Frustrated "216 (100)"
## 
## $Q3.32_4..Q3.33_4
##       n (%)      
## Happy "660 (100)"
## 
## $Q3.32_5..Q3.33_5
##        n (%)      
## Scared "640 (100)"
## 
## $Q3.32_11..Q3.33_11
##            n (%)     
## Ambivalent "45 (100)"
## 
## $Q3.32_6..Q3.33_6
##           n (%)      
## Surprised "777 (100)"
## 
## $Q3.32_7..Q3.33_7
##          n (%)      
## Thankful "415 (100)"
## 
## $Q3.32_8..Q3.33_8
##         n (%)      
## Unhappy "181 (100)"
## 
## $Q3.32_9..Q3.33_9
##         n (%)      
## Worried "601 (100)"
## 
## $Q3.32_17..Q3.33_17
##       n (%)      
## Angry "132 (100)"
## 
## $Q3.32_10..Q3.33_10
##       n (%)     
## Other "35 (100)"
## 
## $Q3.34..Q121
##          n (%)        
## Negative "669 (38.1)" 
## Positive "1086 (61.9)"
## 
## $Q114
##                          n (%)        
## bisexual                 "119 (5.7)"  
## heterosexual or straight "1980 (94.3)"
## 
## $Q3.4_1
##                    n (%)       
## finish high school "1077 (100)"
## 
## $Q3.4_2
##                n (%)      
## finish college "846 (100)"
## 
## $Q3.4_3
##                n (%)      
## start a career "858 (100)"
## 
## $Q3.4_4
##                          n (%)       
## gain financial stability "1295 (100)"
## 
## $Q3.4_5
##                                   n (%)       
## have a place of one’s own to live "1044 (100)"
## 
## $Q3.4_10
##             n (%)      
## buy a house "293 (100)"
## 
## $Q3.4_6
##                      n (%)      
## be in a relationship "756 (100)"
## 
## $Q3.4_7
##            n (%)      
## be married "761 (100)"
## 
## $Q3.4_15
##                      n (%)       
## be emotionally ready "1223 (100)"
## 
## $Q3.4_8
##       n (%)     
## other "15 (100)"
## 
## $Q3.4_9
##      n (%)    
## none "9 (100)"
## 
## $relationship
##                       n (%)        
## div/sep/wid           "81 (3.9)"   
## married/living/commit "1379 (65.7)"
## other                 "5 (0.2)"    
## single                "634 (30.2)" 
## 
## $sexpref
##                          n (%)        
## bisexual                 "119 (5.7)"  
## heterosexual or straight "1980 (94.3)"
## 
## $stateOrg
##                      n (%)       
## Alabama              "33 (1.6)"  
## Alaska               "3 (0.1)"   
## Arizona              "64 (3)"    
## Arkansas             "14 (0.7)"  
## California           "265 (12.6)"
## Colorado             "38 (1.8)"  
## Connecticut          "21 (1)"    
## Delaware             "11 (0.5)"  
## District of Columbia "5 (0.2)"   
## Florida              "121 (5.8)" 
## Georgia              "60 (2.9)"  
## Hawaii               "8 (0.4)"   
## Idaho                "9 (0.4)"   
## Illinois             "91 (4.3)"  
## Indiana              "33 (1.6)"  
## Iowa                 "14 (0.7)"  
## Kansas               "18 (0.9)"  
## Kentucky             "28 (1.3)"  
## Louisiana            "23 (1.1)"  
## Maine                "6 (0.3)"   
## Maryland             "46 (2.2)"  
## Massachusetts        "37 (1.8)"  
## Michigan             "35 (1.7)"  
## Minnesota            "27 (1.3)"  
## Mississippi          "18 (0.9)"  
## Missouri             "53 (2.5)"  
## Montana              "7 (0.3)"   
## Nebraska             "10 (0.5)"  
## Nevada               "24 (1.1)"  
## New Hampshire        "6 (0.3)"   
## New Jersey           "46 (2.2)"  
## New Mexico           "11 (0.5)"  
## New York             "141 (6.7)" 
## North Carolina       "86 (4.1)"  
## North Dakota         "2 (0.1)"   
## Ohio                 "97 (4.6)"  
## Oklahoma             "18 (0.9)"  
## Oregon               "33 (1.6)"  
## Pennsylvania         "111 (5.3)" 
## Rhode Island         "5 (0.2)"   
## South Carolina       "37 (1.8)"  
## South Dakota         "6 (0.3)"   
## Tennessee            "47 (2.2)"  
## Texas                "140 (6.7)" 
## Utah                 "24 (1.1)"  
## Vermont              "3 (0.1)"   
## Virginia             "69 (3.3)"  
## Washington           "38 (1.8)"  
## West Virginia        "23 (1.1)"  
## Wisconsin            "32 (1.5)"  
## Wyoming              "2 (0.1)"   
## 
## $age
##     M (SD)         valid 
## age "32.45 (6.88)" "2099"
## 
## $ageGroup
##       n (%)       
## 21-24 "359 (17.1)"
## 25-29 "445 (21.2)"
## 30-34 "425 (20.2)"
## 35-39 "425 (20.2)"
## 40-44 "445 (21.2)"
## 
## $avoidControl
##              n (%)        
## High control "1762 (83.9)"
## Low control  "337 (16.1)" 
## 
## $avoidPreg
##     n (%)        
## No  "845 (40.3)" 
## Yes "1254 (59.7)"
## 
## $becomeControl
##              n (%)        
## High control "1440 (68.6)"
## Low control  "659 (31.4)" 
## 
## $childnum
##          M (SD)       valid 
## childnum "1.06 (1.3)" "2097"
## 
## $currentSit
##                                                                   n (%)       
## aren't trying, but would feel okay if you/partner became pregnant "494 (23.5)"
## don't want you/partner to become pregnant soon                    "800 (38.1)"
## other                                                             "142 (6.8)" 
## would like you/partner to become pregnant soon                    "319 (15.2)"
## you/partner can't get pregnant                                    "229 (10.9)"
## you/partner is pregnant                                           "115 (5.5)" 
## 
## $hispOrg
##                           n (%)       
## Cuban                     "14 (4.8)"  
## Mexican, Mexican American "140 (47.8)"
## other                     "79 (27)"   
## Puerto Rican              "60 (20.5)" 
## 
## $idealCrit
##                                n (%)        
## don't know                     "119 (5.7)"  
## don't want me/partner pregnant "80 (3.8)"   
## no                             "286 (13.6)" 
## yes                            "1614 (76.9)"
## 
## $incCat
##                   n (%)       
## $100,000 or more  "323 (15.4)"
## $20,000-$39,999   "495 (23.6)"
## $40,000-$59,999   "410 (19.5)"
## $60,000-$79,999   "337 (16.1)"
## $80,000-$99,999   "216 (10.3)"
## less than $20,000 "318 (15.2)"
## 
## $pregFeel
##          n (%)        
## Negative "669 (38.1)" 
## Positive "1086 (61.9)"
## 
## $pregPlan
##     n (%)        
## No  "443 (21.5)" 
## Yes "1619 (78.5)"
## 
## $race
##                                           n (%)        
## American Indian or Alaska Native          "27 (1.3)"   
## Asian                                     "135 (6.4)"  
## Black or African American                 "267 (12.7)" 
## Native Hawaiian or Other Pacific Islander "7 (0.3)"    
## other                                     "129 (6.1)"  
## White                                     "1534 (73.1)"
## 
## $regionOrg
##            n (%)       
## MidWest    "418 (19.9)"
## North East "376 (17.9)"
## South      "779 (37.1)"
## West       "526 (25.1)"
## 
## $underPovLevel
##     n (%)        
## No  "1531 (77.2)"
## Yes "451 (22.8)"