I am developing 1000 simulation datasets where I add random noise to predictions from a regression model where the y-variable has been log-transformed to account for non-normality. I have notice that my simulation datasets exhibit a bias that I think is related to adding values in log-units then back-transforming. I would like to know if my method for correcting the bias is appropriate. Below is reproducible code.
First, create a dummy dataset:
set.seed(8675309)
Y_var <- rlnorm(50, meanlog = 5, sdlog = 0.5)
X_var <- Y_var * exp(rnorm(50, 0, 0.55))
Next, I fit the model with log-tranformed variables and perform bias-correction to back-transform the predictions from log-units to original units:
lfit <- lm(log(Y_var) ~ log(X_var))
summ_lfit <- summary(lfit)
RSE <- summ_lfit$sigma
bc_pred <- exp(predict(lfit)) * exp(0.5 * RSE^2)
mean(bc_pred)
> [1] 171.4359
I then create a matrix of my bias-corrected predictions (each column is a copy of the predictions which will form the basis for the simulated datasets) that is log-transformed so I can add random noise. The noise is created from a normal distribution with mean equal to zero and SD equal to the residual standard error (RSE) from the regression model. Since the y-variable was log-transformed, the residual standard error is in log-units (hence the need to log-transform the bias-corrected predictions):
log_bc_pred <- replicate(1000, log(bc_pred)) ### 1000 simulated datasets
noise <- replicate(1000, rnorm(length(bc_pred), 0, (RSE)))
I now will add the noise to the my predictions, and back-transform to get 1000 simulated dataset with noise in the original units. However, note that the mean of means of the individual simulated datasets does not match the mean of the original predictions (bc_pred). The histogram is also not centered in the mean of bc_pred (red dashed line):
bc_pred_with_noise <- exp(log_bc_pred) * exp(noise)
mean(apply(bc_pred_with_noise, 2, mean))
> [1] 181.8478
hist(apply(bc_pred_with_noise, 2, mean))
abline(v = mean(bc_pred), col="red", lwd=3, lty=2)
However, if I apply the bias-correction "in reverse" the mean of the means of the simulated datasets match the mean of bc_pred and the histogram is centered in the mean of bc_pred:
bc_pred_with_noise2 <- exp(log_bc_pred) * exp(noise) / exp(0.5 * RSE^2)
mean(apply(bc_pred_with_noise2, 2, mean))
> [1] 171.0853
hist(apply(bc_pred_with_noise2, 2, mean))
abline(v = mean(bc_pred), col="red", lwd=3, lty=2)
It appears the applying the bias-correction "in reverse" now has my simulated datasets centered on the original dataset (as I would like it to be). However, I've not seen this application before. Can any tell me whether this is an appropriate bias-correction in my situation?