Simulate Linear Regression Data with Known Coefficients
Source:R/simulate_latent.R
simulate_regression.RdGenerate a dataset suitable for linear regression with
fully specified ground-truth coefficients and predictor standard
deviations. Designed so that lm(y ~ ., data = r$data) recovers
the true coefficients at large n.
Arguments
- coefs
Named numeric vector. May include
"(Intercept)". All other names become predictor column names. Predictors are generated as independent \(N(0, \sigma_j)\) variables.- predictor_sds
Named numeric vector. Names must exactly match the non-intercept names in
coefs. All values must be positive.- error_sd
Positive numeric. Standard deviation of the residuals.
- n
Positive integer. Sample size.
- seed
Integer or NULL. Random seed.