| Title: | Crosswise Models for Sensitive Survey Questions |
|---|---|
| Description: | Implements a bias-corrected crosswise estimator and its extensions for sensitive survey questions. The methods are described in Atsusaka and Stevenson (2023). "A bias-corrected estimator for the crosswise model with inattentive respondents" <doi:10.1017/pan.2021.43>. |
| Authors: | Yuki Atsusaka [aut, cre], Kolbe Dumas [aut] |
| Maintainer: | Yuki Atsusaka <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-09-29 10:41:00 UTC |
| Source: | https://github.com/yukiatsusaka/cwise |
bc_est is used to apply a bias-corrected crosswise estimator to survey data.
bc_est(Y, A, p, p.prime, weight, data, seed = NULL) bc.est(...)bc_est(Y, A, p, p.prime, weight, data, seed = NULL) bc.est(...)
Y |
a vector of binary responses in the crosswise question (Y=1 if TRUE-TRUE or FALSE-FALSE, Y=0 otherwise). |
A |
a vector of binary responses in the anchor question (A=1 if TRUE-TRUE or FALSE-FALSE, A=0 otherwise). |
p |
an auxiliary probability for the crosswise question. |
p.prime |
an auxiliary probability for the anchor question. |
weight |
an optional vector specifying sample weights in data. |
data |
a data frame containing information from the crosswise model (Y, A, weight). |
seed |
Optional integer used to reproduce the bootstrap uncertainty estimate. When supplied, the caller's random-number state is restored after the function returns. |
... |
Arguments passed to |
A list with:
A two-row matrix of naive and bias-corrected prevalence estimates, standard errors, and 95 percent confidence intervals.
A matrix containing the estimated attentive-response rate and the number of complete observations.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[cmBound()] for a sensitivity analysis of naive crosswise estimates.
bc_est(Y=Y, A=A, p=0.15, p.prime=0.15, data=cmdata) bc_est(Y=Y, A=A, weight=weight, p=0.15, p.prime=0.15, data=cmdata)bc_est(Y=Y, A=A, p=0.15, p.prime=0.15, data=cmdata) bc_est(Y=Y, A=A, weight=weight, p=0.15, p.prime=0.15, data=cmdata)
cmBound is used to apply a sensitivity analysis and
visualize the sensitivity bounds for naive crosswise estimates. The
sensitivity analysis assumes that inattentive respondents choose either
response option with equal probability.
cmBound(lambda.hat, p, N, dq = NULL, N.dq = NULL)cmBound(lambda.hat, p, N, dq = NULL, N.dq = NULL)
lambda.hat |
a value for the observed crosswise proportion: Prop(TRUE-TRUE or FALSE-FALSE). |
p |
an auxiliary probability for the crosswise question. It must be a single finite value strictly between 0 and 1, excluding 0.5. |
N |
a value for the number of survey respondents in the crosswise (and anchor) question. |
dq |
a value for a point estimate from direct questioning (if available). |
N.dq |
a value for the number of survey respondents in direct questioning (if available). |
A ggplot object visualizing the result of sensitivity analysis.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[bc_est()] for bias-corrected prevalence estimation.
p <- cmBound(lambda.hat=0.6385, p=0.25, N=310, dq=0.073, N.dq=310) p p <- p + ggplot2::ggtitle("Sensitivity Analysis") + ggplot2::theme(plot.title = ggplot2::element_text(size=20, face="bold"))p <- cmBound(lambda.hat=0.6385, p=0.25, N=310, dq=0.073, N.dq=310) p p <- p + ggplot2::ggtitle("Sensitivity Analysis") + ggplot2::theme(plot.title = ggplot2::element_text(size=20, face="bold"))
Typical, artificially generated toy data set that comes with the binary response in the crosswise question (Y=1 if TRUE-TRUE or FALSE-FALSE, Y=0 otherwise), the binary response in the anchor question, sample weights, and auxiliary probabilities in the crosswise and anchor questions, respectively (these columns are only included here for an illustrative purpose).
data(cmdata)data(cmdata)
an object of class "data.frame"
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the crosswise question
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the anchor question
an auxiliary probability in the crosswise question
an auxiliary probability in the anchor question
This data set was artificially created for the cWise package.
data(cmdata) head(cmdata)data(cmdata) head(cmdata)
Typical, artificially generated toy data set that comes with the binary response in the crosswise question (Y=1 if TRUE-TRUE or FALSE-FALSE, Y=0 otherwise), the binary response in the anchor question, two covariates, and auxiliary probabilities in the crosswise and anchor questions, respectively (these columns are only included here for an illustrative purpose).
data(cmdata2)data(cmdata2)
an object of class "data.frame"
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the crosswise question
A binary covariate representing being a female
A discrete covariate representing age
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the anchor question
an auxiliary probability in the crosswise question
an auxiliary probability in the anchor question
This data set was artificially created for the cWise package.
data(cmdata2) head(cmdata2)data(cmdata2) head(cmdata2)
Typical, artificially generated toy data set that comes with the binary response in the crosswise question (Y=1 if TRUE-TRUE or FALSE-FALSE, Y=0 otherwise), the binary response in the anchor question, the outcome variable, two covariates, and auxiliary probabilities in the crosswise and anchor questions, respectively (these columns are only included here for an illustrative purpose).
data(cmdata3)data(cmdata3)
an object of class "data.frame"
an outcome variable
A binary covariate representing being a female
A discrete covariate representing age
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the crosswise question
a binary indicator for the crosswise item (TRUE-TRUE or FALSE-FALSE) in the anchor question
an auxiliary probability in the crosswise question
an auxiliary probability in the anchor question
This data set was artificially created for the cWise package.
data(cmdata3) head(cmdata3)data(cmdata3) head(cmdata3)
Perform a post-estimation prediction with uncertainty quantification via parametric bootstrap
cmpredict( out, newdata = NULL, zval = NULL, typical = NULL, nsim = 1000L, seed = NULL, draws = FALSE )cmpredict( out, newdata = NULL, zval = NULL, typical = NULL, nsim = 1000L, seed = NULL, draws = FALSE )
out |
An output of |
newdata |
A named data frame, list, or vector supplying values for every covariate in the fitted formula. A data frame returns one prediction row per row of 'newdata'. |
zval |
Optional named vector for one covariate to vary. Its name must match a formula variable; all remaining covariates are supplied through 'newdata' or 'typical'. |
typical |
Optional named vector or list of fixed covariate values. This is a convenience alternative to 'newdata' when used with 'zval'. |
nsim |
Number of parametric-bootstrap draws. |
seed |
Optional integer seed for reproducible bootstrap draws. When set, the caller's RNG state is restored before returning. |
draws |
If 'TRUE', attach the raw bootstrap draw matrix as a '"draws"' attribute on the returned data frame. |
A data frame with 'estimate', 'conf.low', and 'conf.high' columns, with one row for each prediction scenario. When 'draws = TRUE', its '"draws"' attribute contains the raw parametric-bootstrap matrix.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[cmreg()] to fit the required outcome-model object and [cmpredict_p()] for predictions from a predictor model.
m <- cmreg(Y ~ female + age, anchor = A, p = 0.1, p.prime = 0.15, data = cmdata2) predictions <- cmpredict(m, typical = c(age = 30), zval = c(female = 0, female = 1)) predictionsm <- cmreg(Y ~ female + age, anchor = A, p = 0.1, p.prime = 0.15, data = cmdata2) predictions <- cmpredict(m, typical = c(age = 30), zval = c(female = 0, female = 1)) predictions
Perform a post-estimation prediction with uncertainty quantification via parametric bootstrap
cmpredict_p( out, newdata = NULL, zval = NULL, typical = NULL, type = c("response", "link"), nsim = 1000L, seed = NULL, draws = FALSE ) cmpredict.p(...)cmpredict_p( out, newdata = NULL, zval = NULL, typical = NULL, type = c("response", "link"), nsim = 1000L, seed = NULL, draws = FALSE ) cmpredict.p(...)
out |
An output of |
newdata |
A named data frame, list, or vector supplying values for every covariate in the fitted formula. A data frame returns absent/present latent- trait scenarios for every row. |
zval |
Optional named vector for one covariate to vary. Its name must match a formula variable; all remaining covariates are supplied through 'newdata' or 'typical'. |
typical |
Optional named vector or list of fixed covariate values. This is a convenience alternative to 'newdata' when used with 'zval'. |
type |
Prediction scale: '"response"' (default) or '"link"'. The Gaussian outcome model has an identity link, so these are currently equal. |
nsim |
Number of parametric-bootstrap draws. |
seed |
Optional integer seed for reproducible bootstrap draws. When set, the caller's RNG state is restored before returning. |
draws |
If 'TRUE', attach the raw bootstrap draw matrix as a '"draws"' attribute on the returned data frame. |
... |
Arguments passed to |
A data frame with 'estimate', 'conf.low', and 'conf.high' columns. Each input scenario contributes an absent-trait row followed by a present- trait row. When 'draws = TRUE', its '"draws"' attribute contains the raw parametric-bootstrap matrix.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[cmreg_p()] to fit the required predictor-model object and [cmpredict()] for predictions from an outcome model.
# Keep the fitted example small: this likelihood is deliberately # computationally intensive and package examples run during CRAN checks. example_data <- cmdata3[seq_len(30L), ] m2 <- cmreg_p(V ~ age + female, crosswise = Y, anchor = A, p = 0.1, p.prime = 0.15, data = example_data, n.start = 1L) predictions <- cmpredict_p( m2, newdata = data.frame(age = 30, female = 1), nsim = 20L, seed = 1L ) predictions# Keep the fitted example small: this likelihood is deliberately # computationally intensive and package examples run during CRAN checks. example_data <- cmdata3[seq_len(30L), ] m2 <- cmreg_p(V ~ age + female, crosswise = Y, anchor = A, p = 0.1, p.prime = 0.15, data = example_data, n.start = 1L) predictions <- cmpredict_p( m2, newdata = data.frame(age = 30, female = 1), nsim = 20L, seed = 1L ) predictions
cmreg is used to run a regression with the latent sensitive trait as an outcome.
cmreg( formula, anchor, p, p.prime, data, start = NULL, n.start = 3L, control = list() )cmreg( formula, anchor, p, p.prime, data, start = NULL, n.start = 3L, control = list() )
formula |
an object of class "formula": a symbolic description of the model to be fitted. Ex. Crosswise response ~ Covariates. The anchor response is supplied separately through 'anchor'. |
anchor |
Unquoted column name (or a single character column name) for the anchor response. |
p |
an auxiliary probability for the crosswise question. |
p.prime |
an auxiliary probability for the anchor question. |
data |
a data frame containing information from the crosswise model and covariates. |
start |
Optional numeric vector of starting values for the beta and theta parameters. By default, starts are derived from binomial GLMs for the observed crosswise and anchor responses. |
n.start |
Number of optimization starts, including the data-informed start. |
control |
A list of control settings passed to [stats::optim()]. 'fnscale' is fixed internally because the log-likelihood is maximized. |
An object of class 'cmreg', a list with:
The matched model call.
A coefficient table for the latent-trait outcome model.
A coefficient table for the anchor-response model.
The estimated variance-covariance matrix of all parameters.
Named full-precision parameter estimates and standard errors.
The optimized log-likelihood, number of complete observations, and optimizer convergence code.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[cmpredict()] for predicted latent-trait probabilities and [cmreg_p()] for a model with the latent trait as a predictor.
m <- cmreg(Y ~ female + age, anchor = A, p = 0.1, p.prime = 0.15, data = cmdata2) mm <- cmreg(Y ~ female + age, anchor = A, p = 0.1, p.prime = 0.15, data = cmdata2) m
cmreg is used to run a regression with the latent sensitive trait as a predictor.
cmreg_p( formula, crosswise, anchor, p, p.prime, data, start = NULL, n.start = 3L, control = list() ) cmreg.p(...)cmreg_p( formula, crosswise, anchor, p, p.prime, data, start = NULL, n.start = 3L, control = list() ) cmreg.p(...)
formula |
an object of class "formula": a symbolic description of the model to be fitted. Ex. Outcome ~ Covariates. The crosswise and anchor responses are supplied separately through 'crosswise' and 'anchor'. |
crosswise |
Unquoted column name (or a single character column name) for the crosswise response. |
anchor |
Unquoted column name (or a single character column name) for the anchor response. |
p |
an auxiliary probability for the crosswise question. |
p.prime |
an auxiliary probability for the anchor question. |
data |
a data frame containing information from the crosswise model, the outcome variable, and covariates. |
start |
Optional numeric vector of starting values on the reporting scale: beta, theta, gamma, crosswise effect, and a positive sigma. By default, starts are derived from GLM and least-squares fits to observed responses. |
n.start |
Number of optimization starts, including the data-informed start. |
control |
A list of control settings passed to [stats::optim()]. 'fnscale' is fixed internally because the log-likelihood is maximized. |
... |
Arguments passed to |
An object of class 'cmreg_p' (and 'cmreg'), a list with:
The matched model call.
A coefficient table for the Gaussian outcome model, including the latent-trait effect.
Coefficient tables for the crosswise and anchor-response models, with the residual standard deviation.
The estimated variance-covariance matrix of all parameters.
Named full-precision parameter estimates and standard errors.
The optimized log-likelihood, number of complete observations, and optimizer convergence code.
Atsusaka, Y. and Stevenson, R. T. (2023). The crosswise model for sensitive survey questions. doi:10.1017/pan.2021.43.
[cmpredict_p()] for predictions conditional on latent-trait status and [cmreg()] for a model with the latent trait as the outcome.
# Keep the fitted example small: this likelihood is deliberately # computationally intensive and package examples run during CRAN checks. example_data <- cmdata3[seq_len(30L), ] m2 <- cmreg_p(V ~ age + female, crosswise = Y, anchor = A, p = 0.1, p.prime = 0.15, data = example_data, n.start = 1L) m2# Keep the fitted example small: this likelihood is deliberately # computationally intensive and package examples run during CRAN checks. example_data <- cmdata3[seq_len(30L), ] m2 <- cmreg_p(V ~ age + female, crosswise = Y, anchor = A, p = 0.1, p.prime = 0.15, data = example_data, n.start = 1L) m2
Print and summarise crosswise regression fits
## S3 method for class 'cmreg' print(x, digits = max(3L, getOption("digits") - 3L), ...) ## S3 method for class 'cmreg' summary(object, ...) ## S3 method for class 'summary.cmreg' print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'cmreg' print(x, digits = max(3L, getOption("digits") - 3L), ...) ## S3 method for class 'cmreg' summary(object, ...) ## S3 method for class 'summary.cmreg' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
A 'cmreg' or 'cmreg_p' fit object. |
digits |
Number of significant digits to display. |
... |
Additional arguments, currently ignored. |
object |
A 'cmreg' or 'cmreg_p' fit object. |
'summary.cmreg()' returns a list containing the fit call, coefficient tables, log-likelihood, sample size, convergence code, and model type.
Core simulation function that generates crosswise model data with inattentive respondents and computes bias-corrected prevalence estimates with bootstrap confidence intervals. This implements the methodology described in Appendix C5 for power analysis of the crosswise model.
sim_cwdata( N.sim = 500, sample, prevalence, p, p.prime, gamma, direct, verbose = TRUE ) sim.cwdata(...)sim_cwdata( N.sim = 500, sample, prevalence, p, p.prime, gamma, direct, verbose = TRUE ) sim.cwdata(...)
N.sim |
Integer. Number of Monte Carlo simulations to run. Default is 500. |
sample |
Integer. Sample size per simulation (number of respondents). |
prevalence |
Numeric. True prevalence rate of the sensitive attribute (between 0 and 1). |
p |
Numeric. Probability for the randomization item in sensitive question (between 0 and 1). |
p.prime |
Numeric. Probability for the anchor question (non-sensitive, between 0 and 1). |
gamma |
Numeric. Proportion of attentive respondents (between 0 and 1). |
direct |
Numeric. Direct questioning estimate for comparison purposes (between 0 and 1). |
verbose |
Logical. If 'TRUE' (the default), display a progress bar while simulations run. |
... |
Arguments passed to |
The function implements the crosswise model with bias correction for inattentive respondents. For each simulation:
Generates attentive/inattentive status based on gamma
Simulates responses to sensitive question (crosswise format)
Simulates responses to anchor question (for estimating attention rate)
Computes naive crosswise estimate
Applies bias correction based on estimated inattention
Uses bootstrap (500 iterations) to compute 95% confidence intervals
The bias correction formula is:
where the bias is estimated using the anchor question responses.
A list containing:
Named vector with summary statistics including average bias, RMSE, and coverage rates for both naive and bias-corrected estimators
Numeric vector of bias-corrected point estimates (sorted)
Numeric vector of lower bounds of 95% bootstrap CIs (sorted)
Numeric vector of upper bounds of 95% bootstrap CIs (sorted)
Numeric vector of estimated bias values for each simulation
Numeric vector of relative CI lengths (bias-corrected vs naive)
Atsusaka and Stevenson (2023). Appendix C5: Sample Size Determination and Parameter Selection. doi:10.1017/pan.2021.43.
# Basic usage result <- sim_cwdata( N.sim = 100, sample = 500, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.05 ) print(result$Results)# Basic usage result <- sim_cwdata( N.sim = 100, sample = 500, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.05 ) print(result$Results)
Runs Monte Carlo simulations using the bias-corrected crosswise model and creates a caterpillar plot showing sorted point estimates with bootstrap confidence intervals, replicating Panel C of Figure C7 in Atsusaka and Stevenson (2023).
sim_estimates( N.sim = 100, sample, prevalence, p, p.prime, gamma, direct, txcol = "dimgray", sim.results = NULL, verbose = TRUE ) sim.estimates(...)sim_estimates( N.sim = 100, sample, prevalence, p, p.prime, gamma, direct, txcol = "dimgray", sim.results = NULL, verbose = TRUE ) sim.estimates(...)
N.sim |
Integer. Number of Monte Carlo simulations. Default is 100. |
sample |
Integer. Sample size per simulation. |
prevalence |
Numeric. True prevalence rate of the sensitive attribute. |
p |
Numeric. Randomization probability for the sensitive question. |
p.prime |
Numeric. Randomization probability for the anchor question. |
gamma |
Numeric. Proportion of attentive respondents (between 0 and 1). |
direct |
Numeric. Direct questioning estimate for comparison. |
txcol |
Character. Color for annotation text. Default: |
sim.results |
Optional list. Pre-computed output from |
verbose |
Logical. Passed to |
... |
Arguments passed to |
The plot displays:
Sorted bias-corrected point estimates as filled circles
Bootstrap 95% confidence intervals as vertical line segments
A horizontal reference line at 0
A horizontal reference line at the true prevalence prevalence (red)
Estimates are sorted in ascending order, creating a characteristic "fan" shape that reveals the distribution of estimates across simulations.
Text annotation positions are calibrated to N.sim = 100 and scale
proportionally for other values.
If sim.results is supplied, all simulation parameters (N.sim,
sample, p, p.prime, gamma, direct) are
still used for the annotations, but no new simulation is run.
Invisibly returns the simulation results list from sim_cwdata,
containing BiasCorrectEst, BiasCorrectLow,
BiasCorrectHigh, and summary Results.
Atsusaka and Stevenson (2023). Figure C7, Panel C. doi:10.1017/pan.2021.43.
sim_cwdata for the underlying simulation function
# Replicate Panel C of Figure C7 sim_estimates( N.sim = 100, sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1 ) # Re-use pre-computed simulation results res <- sim_cwdata(N.sim = 100, sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1) sim_estimates(sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1, sim.results = res)# Replicate Panel C of Figure C7 sim_estimates( N.sim = 100, sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1 ) # Re-use pre-computed simulation results res <- sim_cwdata(N.sim = 100, sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1) sim_estimates(sample = 1000, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.1, sim.results = res)
Computes statistical power for a one-sided hypothesis test of H0: pi <= pi0 versus H1: pi > pi0 at a given fixed sample size. This is useful when researchers already know their sample size and want to assess the power they can expect from their study.
sim_power( N.sim, sample, pi.null, pi.alt, p, p.prime, gamma, direct, verbose = TRUE ) sim.power(...)sim_power( N.sim, sample, pi.null, pi.alt, p, p.prime, gamma, direct, verbose = TRUE ) sim.power(...)
N.sim |
Integer. Number of Monte Carlo simulations. Larger values provide more stable power estimates but increase computation time. |
sample |
Integer. The fixed sample size (number of respondents) to evaluate. |
pi.null |
Numeric. Prevalence rate under the null hypothesis (pi0). Can be 0 or a value from direct questioning. |
pi.alt |
Numeric. True prevalence rate under the alternative hypothesis (pi1). Must be greater than pi.null. |
p |
Numeric. Probability for the randomization item in the sensitive question. Values between 0.1 and 0.3 are typical. |
p.prime |
Numeric. Probability for the anchor question (non-sensitive). |
gamma |
Numeric. Proportion of attentive respondents (between 0 and 1). For example, 0.8 means 80% of respondents are attentive. |
direct |
Numeric. Direct questioning estimate for comparison purposes. |
verbose |
Logical. If |
... |
Arguments passed to |
The function implements the power calculation based on the Wald test:
where:
is the cumulative distribution function of the standard normal
is derived from the simulated null distribution
and are simulated standard errors
under H0 and H1 respectively
The function runs sim_cwdata() twice: once under H0 using pi.null
and once under H1 using pi.alt, to estimate the sampling distributions
at the specified sample size.
A numeric scalar representing the estimated statistical power (probability of correctly rejecting H0 when H1 is true) at the given sample size.
This function can take considerable time to run depending on N.sim and sample size. For quick exploration, use smaller N.sim values (for example, 100 to 500). For publication-quality results, use N.sim >= 2000.
Atsusaka and Stevenson (2023). Appendix C5: Sample Size Determination and Parameter Selection. doi:10.1017/pan.2021.43.
sim_cwdata for the underlying simulation function
# Compute power at a fixed sample size of 1000 pwr <- sim_power( N.sim = 500, sample = 1000, pi.null = 0, pi.alt = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.02 ) cat(sprintf("Estimated power: %.3f\n", pwr))# Compute power at a fixed sample size of 1000 pwr <- sim_power( N.sim = 500, sample = 1000, pi.null = 0, pi.alt = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.02 ) cat(sprintf("Estimated power: %.3f\n", pwr))
Tests multiple sample sizes to determine which achieves desired confidence interval coverage properties. Specifically, it calculates what percentage of 95% confidence intervals (1) exclude zero and (2) include the direct estimate. This helps researchers choose a sample size that provides sufficient precision.
sim_power_N(N.sim = 50, prevalence, p, p.prime, gamma, direct, verbose = TRUE) sim.power.N(...)sim_power_N(N.sim = 50, prevalence, p, p.prime, gamma, direct, verbose = TRUE) sim.power.N(...)
N.sim |
Integer. Number of Monte Carlo simulations per sample size. Default is 50. Larger values provide more stable estimates but increase computation time. |
prevalence |
Numeric. True prevalence rate of the sensitive attribute (between 0 and 1). |
p |
Numeric. Probability for the randomization item in sensitive question. |
p.prime |
Numeric. Probability for the anchor question (non-sensitive). |
gamma |
Numeric. Proportion of attentive respondents (between 0 and 1). |
direct |
Numeric. Direct questioning estimate for comparison purposes. |
verbose |
Logical. If |
... |
Arguments passed to |
This function is useful for planning studies where researchers want to:
Distinguish the estimated prevalence from zero with high confidence
Obtain narrow confidence intervals for precise estimation
Compare crosswise estimates with direct questioning estimates
For each sample size, the function:
Simulates N.sim datasets using the crosswise model
Computes bias-corrected estimates with bootstrap 95% CIs
Calculates what percentage of CIs contain zero
Calculates what percentage of CIs contain the direct estimate
A progress bar displays simulation progress.
A data frame with three columns:
Sample sizes tested: 100, 500, 1000, 1500, 2000, 2500, 3000
Percentage of 95% CIs that include zero. Lower values indicate better precision (CIs exclude zero).
Percentage of 95% CIs that include the direct estimate. Values near 95% suggest good agreement with direct questioning.
Low CoverageZero values indicate CIs that reliably exclude zero (good for establishing that prevalence is non-zero)
CoverageDirect near 95% suggests consistency between crosswise and direct questioning approaches
This function uses 500 bootstrap iterations per simulation
Atsusaka and Stevenson (2023). Appendix C5: Sample Size Determination and Parameter Selection. doi:10.1017/pan.2021.43.
sim_power for the underlying simulation function
# Find sample size needed to reliably exclude zero result <- sim_power_N( N.sim = 50, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.05 ) print(result) # Visualize results plot(result$SampleSize, result$CoverageZero, type = "b", xlab = "Sample Size", ylab = "% of CIs Including Zero", main = "Precision vs Sample Size")# Find sample size needed to reliably exclude zero result <- sim_power_N( N.sim = 50, prevalence = 0.1, p = 0.1, p.prime = 0.1, gamma = 0.8, direct = 0.05 ) print(result) # Visualize results plot(result$SampleSize, result$CoverageZero, type = "b", xlab = "Sample Size", ylab = "% of CIs Including Zero", main = "Precision vs Sample Size")