This repository contains code associated with "Bayesian Unit-level Modeling of Categorical Survey Data with a Longitudinal Design" by Vedensky, Parker, and Holan.
- From the top-level directory of this repository, run
Rscript data/download_census_files.Rto download the raw HPS data from <census.gov> and extract the data files and replicate weight files. - Optionally run
Rscript data/generate_GAD2_pop.Rto process the HPS files downloaded in step 1 and to producedata/ordinal/HPS_empirical_pop_df_GAD2.RData. However, this file is already included in the repository. - Run
Rscript data/generate_samples.Rto take subsamples of the HPS that are used in the simulation study. - Run
Rscript code/cross_sectional_sim_blur.Rto run the simulation for the cross-sectional models andRscript code/longitudinal_sim_blur.Rfor the longitudinal models. If you want to quickly check that everything will run, set Nsim, n_mcmc, and n_burn to low values in both files. (The manuscript takes n_mcmc=2000, n_burn=500, Nsim=100, which can be time-consuming.) The number of parallel jobs to run the simulations is set tonumCores <- 10by default. Be careful and check this does not exceed the available number of cores on your machine. - Run
Rscript code/process_sim_output.Rto reproduce the figures and tables corresponding to the simulation study that appear in the manuscript. - Run
Rscript code/data_analysis_blur.Rto get the direct estimates and model predictions for the full data analysis. This file also produces all of the figures that appear in the data analysis section of the manuscript. For a quick check that everything will run, you can setnsampandepsilonto a low value, say <100 and .1 respectively. (The manuscript uses nsamp=1000 and epsilon=.001.)
Contains all of the model code in R library format.
Contains code specific to the manuscript.
-
helper_functions.RContains helper functions used by the other files. -
cross_sectional_sim_blur.RRuns the cross-sectional models evaluated in the empirical simulation. -
longitudinal_sim_blur.RRuns the longitudinal models evaluated in the empirical simulation. -
process_sim_output.RGenerates the figures and tables included in Section 5.2 of the manuscript. -
data_analysis_blur.RFits the model to the full HPS data set and produces the figures included in Section 5.3 of the manuscript.
Contains code for processing data, as well as the resulting processed data files.
-
make_basis_functions.RGeneratesscaled_basis_functions.RDataandunscaled_basis_functions.RData. -
generate_GAD2_pop.RGenerates the dataset used in the data analysis and as the "empirical population" that is subsampled in the simulation study. -
generate_samples.RCreates the 100 subsamples of the population data used in the empirical simulation. These are stored asempirical_samples_GAD2.RData. -
process_census_table.RProducescensus_tables.csvfor use incode/data_analysis_blur.R. -
data/ordinal/HPS_empirical_pop_df_GAD2.RDatacontains the processed HPS sample, which is used in the data analysis and as the empirical population that is subsampled in the simulation. -
data/ordinal/empirical_samples_GAD2.RDatacontains the subsamples for the simulation. This file is generated by runninggenerate_samples.R
The processed data are available as data/ordinal/HPS_empirical_pop_df_GAD2.RData.
We have made the subsamples of this file needed for the simulation available on SharePoint.
The file data/census_table.csv was obtained from the Census Population Estimate program: https://www2.census.gov/programs-surveys/popest/datasets/2020-2021/state/asrh/sc-est2021-alldata6.csv.
The raw HPS data are too large to be included directly but can be downloaded from census.gov with the set of bash commands below then processed with generate_GAD2_pop.R.
for i in {1..12}
do if [ $i -lt 10 ]
then wget https://www2.census.gov/programs-surveys/demo/datasets/hhp/2020/wk$i/HPS_Week0$i'_PUF_CSV.zip'
else wget https://www2.census.gov/programs-surveys/demo/datasets/hhp/2020/wk$i/HPS_Week$i'_PUF_CSV.zip'
fi
done
unzip HPS_Week*PUF_CSV.zip