Skip to content

Instantly share code, notes, and snippets.

@bayesball
Created February 6, 2016 16:04
Show Gist options
  • Save bayesball/8f51899930192776bfd8 to your computer and use it in GitHub Desktop.
Save bayesball/8f51899930192776bfd8 to your computer and use it in GitHub Desktop.
Function to fit a beta-binomial exchangeable model
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