Skip to content

Instantly share code, notes, and snippets.

Created July 18, 2019 21:24
What would you like to do?
bcf <- function(observed, model_name) {
# another way to correct for back-transformation bias
# based on this:
# 1. Compute exp(Xβ^), i.e. the retransformed but unadjusted prediction
a <- exp(predict(model_name))
# 2. Regress Y against exp(Xβ^) without an intercept. Call the resulting regression coefficient γ.
b <- lm(observed ~ a -1) #adding -1 in the formula removes the intercept
b <- as.numeric(coefficients(b))
# 3. Compute the adjusted retransformed prediction as γexp(Xβ^).
return(b * exp(predict(model_name)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment