<commit_before>binomial.fun <- function(theta, x, y) {
  # parameters
  # theta1, theta2

  # flat priors
  #log.priors <- sum(dbeta(theta[1], 1, 1, log=T)) +
  #              sum(dbeta(theta[2], 1, 1, log=T))

  # Jeffrey's priors
  log.priors <- sum(dbeta(theta[1], .5, .5, log=T)) +
                sum(dbeta(theta[2], .5, .5, log=T))

  # likelihood
  log.like <- sum(dbinom(x[, 1], x[, 2], theta[1], log=T)) +
              sum(dbinom(y[, 1], y[, 2], theta[2], log=T))

  ll <- log.priors + log.like

  ifelse(is.na(ll) | is.nan(ll), -Inf, ll)
}

bayes.binomial.test <- function(x, y, nmc=20000, nbi=20000) {
  theta.init <- c((sum(x[, 1])+1) / (sum(x[, 2])+2), (sum(y[, 1])+1) / (sum(y[, 2])+2))
  out <- bayes::mcmc(binomial.fun, theta.init, nmc, nbi, x=x, y=y)
  return(out)
}<commit_msg>binomial (exact).. arghhh. forgot the exact<commit_after>binomial.fun <- function(theta, x) {

  # parameters
  # x[, 1] ... number of success
  # x[, 2] ... number of trials

  # flat priors
  #log.priors <- sum(dbeta(theta, 1, 1, log=T))

  # Jeffrey's priors
  log.priors <- sum(dbeta(theta, .5, .5, log=T))

  # likelihood
  log.like <- sum(dbinom(x[, 1], x[, 2], theta, log=T))

  ll <- log.priors + log.like

  ifelse(is.na(ll) | is.nan(ll), -Inf, ll)
}

bayes.binomial.test <- function(x, nmc=20000, nbi=20000) {
  theta.init <- (sum(x[, 1])+1) / (sum(x[, 2])+2)
  out <- bayes::mcmc(binomial.fun, theta.init, nmc, nbi, x=x)
  return(out)
}
{'fraction_non_alphanumeric': 0.23354123354123354, 'fraction_numerical': 0.04158004158004158, 'mean_word_length': 3.044817927170868, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3118288', 'n_tokens_mistral': 731, 'n_tokens_neox': 629, 'n_words': 136}