Created
February 6, 2016 16:04
-
-
Save bayesball/8f51899930192776bfd8 to your computer and use it in GitHub Desktop.
Function to fit a beta-binomial exchangeable model
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
fit.model <- function(data){ | |
# data is a list with two components | |
# - y: binomial counts | |
# - n: binomial sample sizes | |
require(LearnBayes) | |
mode <- laplace(betabinexch, c(1, 1), | |
cbind(data$y, data$n))$mode | |
eta <- exp(mode[1]) / (1 + exp(mode[1])) | |
K <- exp(mode[2]) | |
list(eta=eta, K=K, | |
d=data.frame(data, est=(data$y + K * eta) / (data$n + K))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment