
Simulate within-subject demand data for TICKET-011 Phase 2 parity tests
Source:R/simulate-within-subject.R
dot-simulate_within_subject_demand.RdGenerates long-format demand data where each subject is observed at every
price under every level of an in-subject condition factor. Used by the
Phase 2 parity tests to confirm that fit_demand_tmb() matches
fit_demand_mixed() on factor-expanded random-effects specifications
(pdDiag(Q0+alpha~condition), pdSymm(Q0+alpha~condition) etc.).
Arguments
- n_subjects
Integer; number of subjects.
- n_conditions
Integer; number of within-subject condition levels (named
"C1","C2", ...).- prices
Numeric vector of prices each subject sees at every condition.
- log_q0_pop
Numeric; population log-Q0.
- log_alpha_pop
Numeric; population log-alpha.
- delta_q0
Numeric vector of length
n_conditions; per-condition shifts on log-Q0. Defaults to 0 for all conditions.- delta_alpha
Numeric vector of length
n_conditions; per-condition shifts on log-alpha. Defaults to 0 for all conditions.- sigma_b
Numeric; SD of per-(subject, condition) Q0 random deviation.
- sigma_d
Numeric; SD of per-(subject, condition) alpha random deviation.
- rho_bd
Numeric; correlation between b and d within (subject, condition).
- sigma_e
Numeric; residual SD on log-y.
- seed
Optional integer seed for reproducibility.
Value
A tibble with columns id (factor), condition (factor), x
(price), and y (consumption). Long-format, one row per
(subject, condition, price).
Details
Data-generating process: each subject i at condition c and price
p has consumption
$$y_{i,c,p} = Q_{0,i,c} \cdot \exp(-\alpha_{i,c} \cdot Q_{0,i,c} \cdot p) \cdot \exp(\epsilon)$$
where
$$\log Q_{0,i,c} = \log Q_{0,\text{pop}} + \delta^{Q_0}_c + b_{i,c}$$
$$\log \alpha_{i,c} = \log \alpha_{\text{pop}} + \delta^{\alpha}_c + d_{i,c}$$
with per-condition shifts delta_q0[c], delta_alpha[c] and per-subject
per-condition random deviations (b_{i,c}, d_{i,c}) ~ N(0, Sigma).