Learn R Programming

imt (version 1.0.0)

logit: Bayesian Logit Model Factory

Description

A class for creating and managing Bayesian Logit Models

Arguments

Active bindings

version

im package version used to fit model

tau_draws

Posterior draws for the treatment effect

mcmChecks

MCMC diagnostics

credible_interval

Credible interval for the treatment effect

prior_eta

Prior distribution for eta

prior_tau

Prior distribution for tau

prior_mean_y

Prior distribution for mean y

eta_draws

Posterior draws for eta

predict_list

List of predictions

Methods


Method new()

Get the package version

Get the posterior draws for tau

Get the MCMC diagnostics

Get the credible interval

Get the prior for eta

Get the prior for tau

Get the prior for mean y

Get the posterior draws for eta

Get the list of predictions

Create a new Bayesian Logit Model object.

Usage

logit$new(
  data,
  y,
  x,
  treatment,
  mean_alpha,
  sd_alpha,
  mean_beta,
  sd_beta,
  tau_mean,
  tau_sd,
  seed = 1982,
  fit = TRUE,
  ...
)

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

mean_alpha

Prior mean for alpha

sd_alpha

Prior standard deviation for alpha

mean_beta

Prior mean for beta

sd_beta

Prior standard deviation for beta

tau_mean

Prior mean for the treatment effect estimation

tau_sd

Prior standard deviation for the treatment effect estimation

seed

Seed for Stan fitting

fit

Flag for fitting the data to the model or not

...

Additional arguments for Stan

Returns

invisible


Method tracePlot()

Plot MCMC trace for the eta and sigma parameters.

Usage

logit$tracePlot(...)

Arguments

...

Additional arguments for Stan

Returns

A ggplot object.


Method calcProb()

Calculates the posterior of an effect being greater than, less than, or within a range defined by thresholds.

Usage

logit$calcProb(a = 0, b = NULL, prior = FALSE)

Arguments

a

Optional. Lower bound for the threshold.

b

Optional. Upper bound for the threshold.

prior

Logical. If TRUE, calculates probabilities based on the prior distribution. If FALSE (default), uses the posterior distribution.

x

A numeric vector containing draws from the posterior

Returns

A character string summarizing 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 eta parameter.


Method pointEstimate()

Usage

logit$pointEstimate(median = TRUE)

Arguments

median

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

Details

This method uses the private$..eta_draws internal variable which contains MCMC draws of the eta 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

logit$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$..eta_draws internal variable containing MCMC draws of the eta 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.

Usage

logit$vizdraws(tau = FALSE, ...)

Arguments

tau

Logical. If TRUE, plot tau instead of eta

...

other arguments passed to vizdraws.

Returns

An interactive plot of the prior and posterior distributions.


Method lollipop()

Plots lollipop chart for the prior and posterior of the impact being greater or less than a threshold.

For more details see vizdraws::lollipops().

Usage

logit$lollipop(threshold = 0, ...)

Arguments

threshold

cutoff used to calculate the probability. Defaults to zero percent points

...

other arguments passed to vizdraws.

Returns

A lollipop chart with the prior and posterior probability of the impact being above or below a threshold.


Method plotPrior()

Plots draws from the prior distribution of the outcome, tau, and impact in percentage points.

Usage

logit$plotPrior()


Method predict()

Predict new data

Usage

logit$predict(new_data, name = NULL, M = NULL, ...)

Arguments

new_data

Data frame to be predicted

name

Group name of the prediction

M

Number of posterior draws to sample from

...

Additional arguments

Returns

invisible(self)


Method getPred()

Get posterior predictive draws

Usage

logit$getPred(name = NULL, ...)

Arguments

name

Group name of the prediction

...

Additional arguments (not used)

Returns

Matrix of posterior predictive draws


Method predSummary()

Get point estimate, credible interval and prob summary of predictive draws

Usage

logit$predSummary(
  name = NULL,
  subgroup = NULL,
  median = TRUE,
  width = 0.75,
  round = 0,
  a = NULL,
  b = NULL,
  ...
)

Arguments

name

Optional. Group name of the prediction

subgroup

Optional. A boolean vector to get summary on the conditional group average

median

Optional. Logical value for using median or mean

width

Optional. Numeric value for credible interval width

round

Optional. Integer value for rounding

a

Optional. Lower bound threshold

b

Optional. Upper bound threshold

...

Additional arguments

Returns

A character string with summary information


Method predCompare()

Compare the average of the posterior draws of two groups

Usage

logit$predCompare(
  name1,
  name2,
  subgroup1 = NULL,
  subgroup2 = NULL,
  median = TRUE,
  width = 0.75,
  round = 0,
  a = NULL,
  b = NULL,
  ...
)

Arguments

name1

Group name of the first prediction to be compared

name2

Group name of the second prediction to be compared

subgroup1

Optional. A boolean vector for the first group

subgroup2

Optional. A boolean vector for the second group

median

Optional. Logical value for using median or mean

width

Optional. Numeric value for credible interval width

round

Optional. Integer value for rounding

a

Optional. Lower bound threshold

b

Optional. Upper bound threshold

...

Additional arguments

Returns

A character string with comparison summary


Method clone()

The objects of this class are cloneable with this method.

Usage

logit$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.