Learn R Programming

imt (version 1.0.0)

negativeBinomial: Bayesian Negative Binomial Model Factory

Description

Bayesian Negative Binomial Model Factory

Bayesian Negative Binomial Model Factory

Arguments

Active bindings

version

Package version used to fit the model

mcmChecks

MCMC diagnostics

credible_interval

Credible interval for the treatment effect

tau_draws

Posterior draws for the treatment effect

Methods


Method new()

Create a new Bayesian Negative Binomial Model object.

Usage

negativeBinomial$new(
  data,
  y,
  x,
  treatment,
  tau_mean,
  tau_sd,
  run_estimation = 1,
  seed = 1982,
  ...
)

Arguments

data

Data frame to be used

y

Name of the outcome variable in the data frame

x

Vector of names of all covariates in the data frame

treatment

Name of the treatment indicator variable in the data frame

tau_mean

Prior mean for the treatment effect estimation

tau_sd

Prior standard deviation for the treatment effect estimation

run_estimation

Integer flag to control whether estimation is run (1) or not (0)

seed

Seed for Stan fitting

...

Additional arguments for Stan

Returns

invisible


Method tracePlot()

Plot MCMC trace for the eta and sigma parameters.

Usage

negativeBinomial$tracePlot(...)

Arguments

...

Additional arguments for Stan

Returns

A ggplot object.


Method posteriorProb()

Calculate posterior probability of effect exceeding a threshold

This function calculates the posterior probability of the effect being larger or smaller than a specified threshold.

Usage

negativeBinomial$posteriorProb(threshold = 0, gt = TRUE)

Arguments

threshold

A numeric value specifying the threshold.

gt

A logical value indicating whether to calculate the probability of the effect being greater than (TRUE) or less than (FALSE) the threshold.

Details

This function uses the private$..tau_draws internal variable to obtain draws from the posterior distribution of the effect size. Based on the specified arguments, the function calculates the proportion of draws exceeding/falling below the threshold and returns a formatted statement describing the estimated probability.

Calculate point estimate of the effect

This R6 method calculates the point estimate of the effect size based on the posterior draws of the tau parameter.

Returns

A character string summarizing the estimated probability.


Method pointEstimate()

Usage

negativeBinomial$pointEstimate(median = TRUE)

Arguments

median

Logical value. If TRUE (default), the median of the tau draws is returned. If FALSE, the mean is returned.

Details

This method uses the private$..tau_draws internal variable which contains MCMC draws of the tau parameter representing the effect size. Based on the specified median argument, the method calculates and returns either the median or the mean of the draws. Calculates credible interval for the effect of the intervention

This R6 method calculates and returns a formatted statement summarizing the credible interval of a specified width for the effect of the intervention.

Returns

A numeric value representing the point estimate.


Method credibleInterval()

Usage

negativeBinomial$credibleInterval(width = 0.75, round = 0)

Arguments

width

Numeric value between 0 and 1 representing the desired width of the credible interval (e.g., 0.95 for a 95% credible interval).

round

Integer value indicating the number of decimal places to round the lower and upper bounds of the credible interval.

Details

This method uses the private$..tau_draws internal variable containing MCMC draws of the tau parameter representing the effect size. It calculates the credible interval, stores it internally, and returns a formatted statement summarizing the findings.

Returns

A character string with the following information:

  • The probability associated with the specified width

  • The lower and upper bounds of the credible interval, rounded to the specified number of decimal places


Method vizdraws()

Plots impact's prior and posterior distributions.

For more details see vizdraws::vizdraws().

Usage

negativeBinomial$vizdraws(...)

Arguments

...

other arguments passed to vizdraws.

Returns

An interactive plot of the prior and posterior distributions.


Method clone()

The objects of this class are cloneable with this method.

Usage

negativeBinomial$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.