Last active
April 23, 2025 10:31
-
-
Save StaffanBetner/2137dc62a7abbfe26276b43aa030489c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Third order Delta method | |
bias_adj <- function(mu, sigma, fun){ | |
first_deriv <- pracma::fderiv(fun, mu) | |
second_deriv <- pracma::fderiv(fun, mu, n = 2) | |
third_deriv <- pracma::fderiv(fun, mu, n = 3) | |
moment1 <- fun(mu)+ # first order | |
1/2*second_deriv*sigma^2 # second order | |
# the third order part evaluates to zero due to symmetry | |
moment2 <- sqrt((first_deriv*sigma)^2+ # first order | |
1/2*(second_deriv*sigma^2)^2+ # second order | |
5/12*third_deriv^2*sigma^6+first_deriv*third_deriv*sigma^4) # third order | |
return(c("mean" = moment1, "sd" = moment2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment