Last active
March 31, 2016 17:17
-
-
Save jwdink/450d3f0dc511d2361eff to your computer and use it in GitHub Desktop.
Fit the gamma distribution to unscaled data using MASS::fitdistr
This file contains 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
fitgamma <- function(x) { | |
# Equivalent to `MASS::fitdistr(x, densfun = "gamma")`, where x are first rescaled to | |
# the appropriate scale for a gamma distribution. Useful for fitting the gamma distribution to | |
# data which, when multiplied by a constant, follows this distribution | |
if (!requireNamespace("MASS")) stop("Requires MASS package.") | |
fit <- glm(formula = x ~ 1, family = Gamma) | |
out <- MASS::fitdistr(x * coef(fit), "gamma") | |
out$scaling_multiplier <- unname(coef(fit)) | |
out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment