Title: | Dynamic Comparative Public Opinion |
---|---|
Description: | Estimates latent variables of public opinion cross-nationally and over time from sparse and incomparable survey data. 'DCPO' uses a population-level graded response model with country-specific item bias terms. Sampling is conducted with 'Stan'. References: Solt (2020) <doi:10.31235/osf.io/d5n9p>. |
Authors: | Frederick Solt [aut, cre], Yue Hu [ctb], Trustees of Columbia University [cph] |
Maintainer: | Frederick Solt <[email protected]> |
License: | GPL (>=3) |
Version: | 0.5.4 |
Built: | 2025-01-24 06:14:37 UTC |
Source: | https://github.com/fsolt/dcpo |
DCPO estimates dynamic comparative public opinion as a latent variable from survey data
Stan Development Team (2018). RStan: the R interface to Stan. R package version 2.18.2. http://mc-stan.org
dcpo
uses diverse survey data to estimate public opinion across countries and over time.
dcpo(dcpo_input, chime = TRUE, ...)
dcpo(dcpo_input, chime = TRUE, ...)
dcpo_input |
a data frame of survey items and marginals generated by |
chime |
play chime when complete? |
... |
arguments to be passed to |
dcpo
, when passed a data frame dcpo_input
of survey marginals created
by dcpo_setup
, estimates a latent variable of public opinion. See rstan::stan
for
additional options; stan
defaults reset by dcpo
are seed = 324, thin = 2,
cores = min(stan_args$chains, parallel::detectCores()/2),
and control <- list(adapt_delta = 0.99, stepsize = 0.005, max_treedepth = 14)
a stanfit object
out1 <- dcpo(demsup_data, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults
out1 <- dcpo(demsup_data, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults
dcpo_xvt
performs a single cross-validation test for DCPO
dcpo_xvt( dcpo_input, fold_number = 1, number_of_folds = 10, fold_seed = 324, chime = TRUE, ... )
dcpo_xvt( dcpo_input, fold_number = 1, number_of_folds = 10, fold_seed = 324, chime = TRUE, ... )
dcpo_input |
a data frame of survey items and marginals generated by |
fold_number |
an integer indicating the number of the fold to treated as test data in the current analysis |
number_of_folds |
an integer indicating the total number of folds |
fold_seed |
a seed for reproducibly randomly assigning observations to folds; when a complete set of k-fold cross-validations is to be performed, the same seed should be used for all |
chime |
play chime when complete? |
... |
arguments to be passed to |
dcpo_xvt
performs a single cross-validation test of a DCPO estimation. To perform
a complete k-fold cross-validation, call it repeatedly, changing only the fold_number argument.
a stanfit object
# Single cross-validation test with 25% test set demsup_xvtest_25pct <- dcpo_xvt(demsup_data, number_of_folds = 4, iter = 300, chains = 1) # 1 chain/300 iterations for example only; use defaults
# Single cross-validation test with 25% test set demsup_xvtest_25pct <- dcpo_xvt(demsup_data, number_of_folds = 4, iter = 300, chains = 1) # 1 chain/300 iterations for example only; use defaults
A dataset containing the prices and other attributes of almost 54,000 diamonds.
demsup_data
demsup_data
A list of 15 elements
an integer, the total number of countries in the data
an integer, the total number of years in the data
an integer, the total number of distinct survey questions in the data
an integer, the maximum number of response cutpoints in any survey question in the data
an integer, the number of KTQR observations
a numeric vector of length N, the country of each observation
a numeric vector of length N, the year of each observation
a numeric vector of length N, the question of each observation
a numeric vector of length N, the response cutpoint of each observation
a numeric vector of length N, the number of respondents who provided a response above the relevant cutpoint for each observation
a numeric vector of length N, the total number of respondents for each observation
a QxR matrix, a truth table indicating the question-cutpoint to be fixed at difficulty .5
a QxK tibble, a truth table indicating whether item difficulty should be estimated to vary by question-country to account for potential item-response bias
an Nx14 tibble, the aggregate survey response dataset in its original format
a list of length 3, indicating the arguments passed to DCPOtools::format_dcpo to generate demsup_data from demsup_data$data
Data on aggregate support for democracy reported in 51 survey datasets in 998 country-years, formatted for use with the functions of the DCPO package
demsup_data replicates the data employed in Claassen, Christopher. 2019. "Estimating Smooth Country-Year Panels of Public Opinion." Political Analysis 27(1):1-20. See https://github.com/fsolt/DCPOtools.
extract_dcpo_results
is a convenience function that extracts the main parameters of a DCPO stanfit object along with the relevant identifying information (country, year, question, and cutpoint).
extract_dcpo_results( dcpo_input, dcpo_output, pars = c("theta", "sigma", "alpha", "beta", "delta"), probs = c(0.1, 0.9) )
extract_dcpo_results( dcpo_input, dcpo_output, pars = c("theta", "sigma", "alpha", "beta", "delta"), probs = c(0.1, 0.9) )
dcpo_input |
the data frame of survey items and marginals generated by |
dcpo_output |
a stanfit object output by |
pars |
a character vector of parameter names to be summarized from the |
probs |
a numeric vector of quantiles of interest; the default is c(.1, .9) |
a tibble
out1 <- dcpo(demsup_data, chime = FALSE, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults theta_results <- summarize_dcpo_results(dcpo_input = demsup_data, dcpo_output = out1, pars = "theta")
out1 <- dcpo(demsup_data, chime = FALSE, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults theta_results <- summarize_dcpo_results(dcpo_input = demsup_data, dcpo_output = out1, pars = "theta")
get_xvt_results
performs a single cross-validation test for dcpo's estimates of cross-national public opinion
get_xvt_results(dcpo_xvt_output, ci = 80)
get_xvt_results(dcpo_xvt_output, ci = 80)
dcpo_xvt_output |
output from a single call to |
ci |
an integer indicating the desired width of credible interval for coverage testing; 80 is the default. |
a stanfit object
# Single cross-validation test with 25% test set demsup_xvtest_25pct <- dcpo_xvt(demsup_data, chime = FALSE, number_of_folds = 4, iter = 300, chains = 1) # 1 chain/300 iterations for example only; use defaults get_xvt_results(demsup_xvtest_25pct)
# Single cross-validation test with 25% test set demsup_xvtest_25pct <- dcpo_xvt(demsup_data, chime = FALSE, number_of_folds = 4, iter = 300, chains = 1) # 1 chain/300 iterations for example only; use defaults get_xvt_results(demsup_xvtest_25pct)
summarize_dcpo_results
is a convenience function that produces summary statistics of the main parameters of a DCPO stanfit object along with the relevant identifying information (country, year, question, and cutpoint).
summarize_dcpo_results( dcpo_input, dcpo_output, pars = c("theta", "sigma", "alpha", "beta", "delta"), probs = c(0.1, 0.9) )
summarize_dcpo_results( dcpo_input, dcpo_output, pars = c("theta", "sigma", "alpha", "beta", "delta"), probs = c(0.1, 0.9) )
dcpo_input |
the data frame of survey items and marginals generated by |
dcpo_output |
a stanfit object output by |
pars |
a character vector of parameter names to be summarized from the |
probs |
a numeric vector of quantiles of interest; the default is c(.1, .9) |
a tibble
out1 <- dcpo(demsup_data, chime = FALSE, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults theta_results <- summarize_dcpo_results(dcpo_input = demsup_data, dcpo_output = out1, pars = "theta")
out1 <- dcpo(demsup_data, chime = FALSE, chains = 1, iter = 300) # 1 chain/300 iterations for example purposes only; use defaults theta_results <- summarize_dcpo_results(dcpo_input = demsup_data, dcpo_output = out1, pars = "theta")