Created
July 7, 2014 15:59
-
-
Save ramhiser/04622f84aa2471fcade9 to your computer and use it in GitHub Desktop.
Exponentially weighting Bernoulli trials for a Beta prior
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
# For the standard conjugate beta prior for a binomial likelihood, a typical | |
# approach is to weight each prior observation equally, there are times where | |
# the prior Bernoulli trials should be weighted over time, so that the more | |
# recent trials are weighted near 1 and the oldest trials should be weighted | |
# near 0. | |
# Gompertz Function | |
# http://en.wikipedia.org/wiki/Gompertz_function | |
gompertz <- function(x, a=1, b=1, c=1) { | |
a * exp(-b * exp(-c * x)) | |
} | |
week <- seq(0, 52, by=1) | |
# Standard Gompertz | |
plot(gompertz(week), type='l', main='Standard Gompertz') | |
# Hand-selected values to get desired weights for each week over the last year. | |
# Perhaps a better approach is to artifically construct a small data set of | |
# desired values and then to estimate the appropriate parameters. | |
plot(gompertz(week, 1, 20, 1/8), | |
type='l', | |
main="Gompertz with a=1, b=20, c=1/8") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment