Skip to content

About

Code for Bayesian Unit-level Modeling of Categorical Survey Data with a Longitudinal Design

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Code for Bayesian Unit-level Modeling of Categorical Survey Data with a Longitudinal Design

This repository contains code associated with "Bayesian Unit-level Modeling of Categorical Survey Data with a Longitudinal Design" by Vedensky, Parker, and Holan.

Reproducing analysis from the manuscript

  1. From the top-level directory of this repository, run Rscript data/download_census_files.R to download the raw HPS data from <census.gov> and extract the data files and replicate weight files.
  2. Optionally run Rscript data/generate_GAD2_pop.R to process the HPS files downloaded in step 1 and to produce data/ordinal/HPS_empirical_pop_df_GAD2.RData. However, this file is already included in the repository.
  3. Run Rscript data/generate_samples.R to take subsamples of the HPS that are used in the simulation study.
  4. Run Rscript code/cross_sectional_sim_blur.R to run the simulation for the cross-sectional models and Rscript code/longitudinal_sim_blur.R for 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 to numCores <- 10 by default. Be careful and check this does not exceed the available number of cores on your machine.
  5. Run Rscript code/process_sim_output.R to reproduce the figures and tables corresponding to the simulation study that appear in the manuscript.
  6. Run Rscript code/data_analysis_blur.R to 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 set nsamp and epsilon to a low value, say <100 and .1 respectively. (The manuscript uses nsamp=1000 and epsilon=.001.)

Repository Structure

blur/

Contains all of the model code in R library format.

code/

Contains code specific to the manuscript.

  • helper_functions.R Contains helper functions used by the other files.

  • cross_sectional_sim_blur.R Runs the cross-sectional models evaluated in the empirical simulation.

  • longitudinal_sim_blur.R Runs the longitudinal models evaluated in the empirical simulation.

  • process_sim_output.R Generates the figures and tables included in Section 5.2 of the manuscript.

  • data_analysis_blur.R Fits the model to the full HPS data set and produces the figures included in Section 5.3 of the manuscript.

data/

Contains code for processing data, as well as the resulting processed data files.

  • make_basis_functions.R Generates scaled_basis_functions.RData and unscaled_basis_functions.RData.

  • generate_GAD2_pop.R Generates the dataset used in the data analysis and as the "empirical population" that is subsampled in the simulation study.

  • generate_samples.R Creates the 100 subsamples of the population data used in the empirical simulation. These are stored as empirical_samples_GAD2.RData.

  • process_census_table.R Produces census_tables.csv for use in code/data_analysis_blur.R.

  • data/ordinal/HPS_empirical_pop_df_GAD2.RData contains 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.RData contains the subsamples for the simulation. This file is generated by running generate_samples.R

Note on dataset

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

About

Code for Bayesian Unit-level Modeling of Categorical Survey Data with a Longitudinal Design

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages