cbc_power: Estimate power analysis for choice experiment designs

View source: R/power.R

cbc_powerR Documentation

Estimate power analysis for choice experiment designs

Description

This function estimates the same model multiple times using different sample sizes to assess statistical power. It returns both the estimated models and a summary of coefficient estimates, standard errors, and power statistics.

Usage

cbc_power(
  data,
  outcome = "choice",
  obsID = "obsID",
  pars = NULL,
  randPars = NULL,
  n_breaks = 10,
  n_q = NULL,
  panelID = NULL,
  alpha = 0.05,
  return_models = FALSE,
  n_cores = NULL,
  ...
)

Arguments

data

A data frame containing choice data. Can be a cbc_choices object or any data frame with the required columns.

outcome

Name of the outcome variable column (1 for chosen, 0 for not). Defaults to "choice".

obsID

Name of the observation ID column. Defaults to "obsID".

pars

Names of the parameters to estimate. If NULL (default), will auto-detect from column names for cbc_choices objects.

randPars

Named vector of random parameters and their distributions ('n' for normal, 'ln' for log-normal). Defaults to NULL.

n_breaks

Number of sample size groups to test. Defaults to 10.

n_q

Number of questions per respondent. Auto-detected for cbc_choices objects if not specified.

panelID

Name of the panel ID column for panel data. Auto-detected as "respID" for multi-respondent cbc_choices objects.

alpha

Significance level for power calculations. Defaults to 0.05.

return_models

If TRUE, includes full model objects in returned list. Defaults to FALSE.

n_cores

Number of cores for parallel processing. Defaults to parallel::detectCores() - 1.

...

Additional arguments passed to logitr::logitr().

Value

A cbc_power object containing:

  • power_summary: Data frame with sample sizes, coefficients, estimates, standard errors, t-statistics, and power

  • models: List of estimated models (if return_models = TRUE)

  • sample_sizes: Vector of sample sizes tested

  • n_breaks: Number of breaks used

  • alpha: Significance level used

Examples

library(cbcTools)

# Create profiles and design
profiles <- cbc_profiles(
  price = c(1, 2, 3),
  type = c("A", "B", "C"),
  quality = c("Low", "High")
)

design <- cbc_design(profiles, n_alts = 2, n_q = 6)

# Simulate choices
priors <- cbc_priors(profiles, price = -0.1, type = c(0.5, 0.2), quality = 0.3)
choices <- cbc_choices(design, priors)

# Run power analysis
power_results <- cbc_power(choices, n_breaks = 8)

# View results
print(power_results)
plot(power_results)

cbcTools documentation built on Aug. 21, 2025, 6:03 p.m.