Simulate measurement of a variable by adding random error.
The function allows adding a subject specific error (sub_bias_sd
), that varies between subjects.
Usage
simulate_measurement(
true_val,
sub_id,
residual_error_sd,
mean_bias = 0,
sub_bias_sd = 0,
proportional_errors = FALSE
)
Arguments
- true_val
A numeric vector of true values.
- sub_id
A factor or vector representing subject IDs. Must be the same length as var_true.
- residual_error_sd
Standard deviation of residual errors.
- mean_bias
Mean bias.
- sub_bias_sd
Standard deviation of subject-specific biases.
- proportional_errors
Should errors be proportional to true value. If TRUE, errors are added on a log scale, and the result is exponentiated. To add a bias of 10% (true_value * 1.1), the mean_bias should be set to log(1.1). A SD of log(1.2) corresponds to ±20%.