Skip to content

Instantly share code, notes, and snippets.

@adamkucharski
Created January 10, 2023 10:21
Show Gist options
  • Save adamkucharski/db8a58107f0f7d1e64c48f0a7a212eae to your computer and use it in GitHub Desktop.
Save adamkucharski/db8a58107f0f7d1e64c48f0a7a212eae to your computer and use it in GitHub Desktop.
Estimate R and k from clusters sizes using MLE
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Code to estimate R and k from clusters sizes using MLE via quickfit
# Adam Kucharski (2023)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
library(devtools)
library(rstan)
library(MASS)
#devtools::install_github("adamkucharski/quickfit")
#devtools::install_github('sbfnk/bpmodels')
library(quickfit)
library(bpmodels)
# Monkeypox data, 1970s:
cluster_sizes <- c(rep(1,27),rep(2,11))
# Estimate R and k
log_l <- function(x,a,b){
bpmodels::chain_ll(x,"nbinom",stat="size",
mu=a,size=b)
}
quickfit::calculate_profile(log_l,
data_in=cluster_sizes,
n_param=2,
a_initial = 0.5,
b_initial = 1,
precision=0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment