Description Usage Arguments Value Examples
View source: R/empb_beta_negbinomial_c.R
empb_beta_negbinomial_c
1 2 3 4 5 6 7 8 | empb_beta_negbinomial_c(
df,
eta = 0.1,
tol = 1e-08,
maxIter = 10000,
starting_rab = NULL,
method = c("newton", "gdescent")
)
|
df |
data.frame object, containing at least columns 'x' containing non-negative integer values, and 'g' containing group labels. |
eta |
positive numeric dampening parameter for Newton's method, gradient descent algorithm. |
tol |
non-negative numeric tolerance parameter for exiting optimization algorithm. |
maxIter |
positive integer setting maximum number of iterations for optimization algorithm. |
starting_rab |
optional 3-long numeric vector, giving initial algorithm starting point for fitting empirical Bayes estimates for r, a, and b, respectively; default NULL. |
method |
string controlling optimization method; default 'newton'. |
list object containing empirical Bayes (EMPB) estimates of r, a, and b hyperparameters, assuming df$x ~ nbinom(r, p_g), and p_g ~ beta(a, b), where 'p_g' denotes a group-level parameter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # Generate example data:
set.seed(31)
r = 4
a = 3
b = 9
# Number of groups:
NG = 10
# Creating group IDs:
g = replicate(NG, paste(sample(LETTERS, 10), sep="", collapse=""))
# Generating 'true' p parameters:
p = rbeta(length(g), a, b)
# Number of experiments, i.e. rows in df:
numexps = 100
# Filling df with pseudo data; note the requisite columns 'x' and 'g':
df = data.frame('x' = numeric(0), 'g' = character(0))
for(k in 1:numexps){
gk = sample(g, 1)
xk = rnbinom(1, r, p[g == gk])
df = rbind(df, data.frame('x' = xk, 'g' = gk))
}
# Generating empirical Bayes (EMPB) solutions for r, a, and b:
rab_fit = empb_beta_negbinomial_c(df = df, method = 'gdescent')
# Compare fitted values to known values:
cbind(c(r, a, b), c(rab_fit$r, rab_fit$a, rab_fit$b))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.