Last updated: 2021-05-27
Checks: 7 0
Knit directory:
fa_sim_cal/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20201104)
was run prior to running the code in the R Markdown file.
Setting a seed ensures that any results that rely on randomness, e.g.
subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version a6fb2e3. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the
analysis have been committed to Git prior to generating the results (you can
use wflow_publish
or wflow_git_commit
). workflowr only
checks the R Markdown file, but you know if there are other scripts or data
files that it depends on. Below is the status of the Git repository when the
results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: .tresorit/
Ignored: _targets/
Ignored: data/VR_20051125.txt.xz
Ignored: data/VR_Snapshot_20081104.txt.xz
Ignored: renv/library/
Ignored: renv/local/
Ignored: renv/staging/
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made
to the R Markdown (analysis/m_01_3_drop_novar.Rmd
) and HTML (docs/m_01_3_drop_novar.html
)
files. If you’ve configured a remote Git repository (see
?wflow_git_remote
), click on the hyperlinks in the table below to
view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
html | ab90fe6 | Ross Gayler | 2021-05-18 | WIP |
Rmd | 24d95c0 | Ross Gayler | 2021-05-15 | WIP |
html | 24d95c0 | Ross Gayler | 2021-05-15 | WIP |
Rmd | d7b5c39 | Ross Gayler | 2021-05-15 | WIP |
Rmd | ec5d588 | Ross Gayler | 2021-03-30 | WIP |
html | ec5d588 | Ross Gayler | 2021-03-30 | WIP |
# NOTE this notebook can be run manually or automatically by {targets}
# So load the packages required by this notebook here
# rather than relying on _targets.R to load them.
# Set up the project environment, because {workflowr} knits each Rmd file
# in a new R session, and doesn't execute the project .Rprofile
library(targets) # access data from the targets cache
library(tictoc) # capture execution time
library(here) # construct file paths relative to project root
here() starts at /home/ross/RG/projects/academic/entity_resolution/fa_sim_cal_TOP/fa_sim_cal
library(fs) # file system operations
library(dplyr) # data wrangling
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(gt) # table formatting
library(stringr) # string matching
library(vroom) # fast reading of delimited text files
library(skimr) # compact summary of each variable
# start the execution time clock
tictoc::tic("Computation time (excl. render)")
# Get the path to the raw entity data file
# This is a target managed by {targets}
f_entity_raw_tsv <- tar_read(c_raw_entity_data_file)
These meta notebooks document the development of functions that will be applied in the core pipeline.
The aim of the m_01 set of meta notebooks is to work out how to read the
raw entity data, drop excluded cases, discard irrelevant variables,
apply any cleaning, and construct standardised names. This does not
include construction of any modelling features. To be clear, the target
(c_raw_entity_data
) corresponding to the objective of this set of
notebooks is the cleaned and standardised raw data, before constructing
any modelling features.
This notebook documents the process of dropping variables with no variation in values, because they are uninformative.
The subsequent notebooks in this set will develop the other functions needed to generate the cleaned and standardised data.
Read the raw entity data file and drop the excluded rows using the
previously defined core pipeline functions, raw_entity_data_read()
,
raw_entity_data_excl_status()
, and raw_entity_data_excl_test
.
# Show the data file name
fs::path_file(f_entity_raw_tsv)
[1] "VR_20051125.txt.xz"
d <- raw_entity_data_read(f_entity_raw_tsv) %>%
raw_entity_data_excl_status() %>%
raw_entity_data_excl_test()
dim(d)
[1] 4099699 32
Take a quick look at the distributions of all the variables.
skimr::skim(d)
Name | d |
Number of rows | 4099699 |
Number of columns | 32 |
_______________________ | |
Column type frequency: | |
character | 32 |
________________________ | |
Group variables | None |
Variable type: character
skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
---|---|---|---|---|---|---|---|
snapshot_dt | 0 | 1.00 | 19 | 19 | 0 | 1 | 0 |
county_id | 0 | 1.00 | 1 | 3 | 0 | 100 | 0 |
county_desc | 0 | 1.00 | 3 | 12 | 0 | 100 | 0 |
voter_reg_num | 0 | 1.00 | 12 | 12 | 0 | 1786064 | 0 |
ncid | 4099699 | 0.00 | NA | NA | 0 | 0 | 0 |
status_cd | 0 | 1.00 | 1 | 1 | 0 | 1 | 0 |
voter_status_desc | 0 | 1.00 | 6 | 6 | 0 | 1 | 0 |
reason_cd | 0 | 1.00 | 2 | 2 | 0 | 1 | 0 |
voter_status_reason_desc | 0 | 1.00 | 8 | 8 | 0 | 1 | 0 |
last_name | 0 | 1.00 | 1 | 21 | 0 | 191996 | 0 |
first_name | 23 | 1.00 | 1 | 19 | 0 | 126589 | 0 |
midl_name | 252695 | 0.94 | 1 | 20 | 0 | 175742 | 0 |
name_sufx_cd | 3869063 | 0.06 | 1 | 3 | 0 | 101 | 0 |
house_num | 0 | 1.00 | 1 | 6 | 0 | 27534 | 0 |
half_code | 4088996 | 0.00 | 1 | 1 | 0 | 41 | 0 |
street_dir | 3812561 | 0.07 | 1 | 2 | 0 | 8 | 0 |
street_name | 7 | 1.00 | 1 | 30 | 0 | 83244 | 0 |
street_type_cd | 154594 | 0.96 | 2 | 4 | 0 | 119 | 0 |
street_sufx_cd | 3941004 | 0.04 | 1 | 3 | 0 | 11 | 0 |
unit_num | 3755239 | 0.08 | 1 | 7 | 0 | 16116 | 0 |
res_city_desc | 19 | 1.00 | 3 | 20 | 0 | 783 | 0 |
state_cd | 18 | 1.00 | 2 | 2 | 0 | 5 | 0 |
zip_code | 21 | 1.00 | 5 | 9 | 0 | 902 | 0 |
area_cd | 2628117 | 0.36 | 1 | 3 | 0 | 507 | 0 |
phone_num | 2540990 | 0.38 | 1 | 7 | 0 | 1072592 | 0 |
sex_code | 0 | 1.00 | 1 | 1 | 0 | 3 | 0 |
sex | 0 | 1.00 | 3 | 6 | 0 | 3 | 0 |
age | 0 | 1.00 | 1 | 3 | 0 | 135 | 0 |
birth_place | 718647 | 0.82 | 2 | 2 | 0 | 56 | 0 |
registr_dt | 0 | 1.00 | 19 | 29 | 0 | 60788 | 0 |
cancellation_dt | 4095558 | 0.00 | 19 | 19 | 0 | 248 | 0 |
load_dt | 0 | 1.00 | 29 | 29 | 0 | 1 | 0 |
The most useful column to look at in the skim tables is n_unique
. This
shows the number of unique values of the variable.
The following variable is entirely missing values:
ncid
- North Carolina identification number (NCID) of voterThe following variables have exactly one unique nonmissing value:
snapshot_dt
- Date of snapshotload_dt
- Data load dateThe following variables have exactly one unique nonmissing value because of selecting ACTIVE & VERIFIED records:
status_cd
Status code for voter registrationvoter_status_desc
Status code descriptionreason_cd
Reason code for voter registration statusvoter_status_reason_desc
Reason code descriptionThose seven variables can not possibly be useful for analyses. Write a function to drop them from the data.
# Function to drop variables with no variation
raw_entity_data_drop_novar <- function(
d # data frame - raw entity data
) {
d %>%
dplyr::select(
-c(ncid, snapshot_dt, load_dt,
status_cd, voter_status_desc, reason_cd, voter_status_reason_desc)
)
}
Apply the filter and track the number of rows before and after the filter.
# number of columns before dropping
d %>% names() %>% length
[1] 32
d %>%
raw_entity_data_drop_novar() %>%
# number of columns after dropping
names() %>% length
[1] 25
Computation time (excl. render): 823.018 sec elapsed
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.10
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] skimr_2.1.3 vroom_1.4.0 stringr_1.4.0 gt_0.3.0 dplyr_1.0.6
[6] fs_1.5.0 here_1.0.1 tictoc_1.0.1 targets_0.4.2
loaded via a namespace (and not attached):
[1] tidyselect_1.1.1 xfun_0.23 bslib_0.2.5 repr_1.1.3
[5] purrr_0.3.4 colorspace_2.0-1 vctrs_0.3.8 generics_0.1.0
[9] htmltools_0.5.1.1 base64enc_0.1-3 yaml_2.2.1 utf8_1.2.1
[13] rlang_0.4.11 jquerylib_0.1.4 later_1.2.0 pillar_1.6.1
[17] glue_1.4.2 withr_2.4.2 bit64_4.0.5 lifecycle_1.0.0
[21] munsell_0.5.0 gtable_0.3.0 workflowr_1.6.2 codetools_0.2-18
[25] evaluate_0.14 knitr_1.33 callr_3.7.0 httpuv_1.6.1
[29] ps_1.6.0 parallel_4.1.0 fansi_0.4.2 highr_0.9
[33] Rcpp_1.0.6 renv_0.13.2 promises_1.2.0.1 scales_1.1.1
[37] jsonlite_1.7.2 bit_4.0.4 ggplot2_3.3.3 digest_0.6.27
[41] stringi_1.6.2 bookdown_0.22 processx_3.5.2 rprojroot_2.0.2
[45] grid_4.1.0 cli_2.5.0 tools_4.1.0 magrittr_2.0.1
[49] sass_0.4.0 tibble_3.1.2 tidyr_1.1.3 crayon_1.4.1
[53] whisker_0.4 pkgconfig_2.0.3 ellipsis_0.3.2 data.table_1.14.0
[57] rmarkdown_2.8 R6_2.5.0 igraph_1.2.6 git2r_0.28.0
[61] compiler_4.1.0