unm_glm {unmconf}R Documentation

Fitting Multi-Staged Bayesian Regression Model with Unmeasured Confounders

Description

unm_glm() fits a multi-staged Bayesian regression model that accounts for unmeasured confounders. Users can input model information into unm_glm() in a similar manner as they would for the standard stats::glm() function, providing arguments like formula, family, and data. Results are stored as MCMC iterations.

Usage

unm_glm(
  form1,
  form2 = NULL,
  form3 = NULL,
  family1 = binomial(),
  family2 = NULL,
  family3 = NULL,
  data,
  n.iter = 2000,
  n.adapt = 1000,
  thin = 1,
  n.chains = 4,
  filename = tempfile(fileext = ".jags"),
  quiet = getOption("unm_quiet"),
  progress.bar = getOption("unm_progress.bar"),
  code_only = FALSE,
  priors,
  response_nuisance_priors,
  response_params_to_track,
  confounder1_nuisance_priors,
  confounder1_params_to_track,
  confounder2_nuisance_priors,
  confounder2_params_to_track,
  ...
)

jags_code(mod)

## S3 method for class 'unm_int'
print(x, digits = 3, ..., print_call = getOption("unm_print_call"))

## S3 method for class 'unm_int'
coef(object, ...)

Arguments

form1

The formula specification for the response model (stage I)

form2

The formula specification for the first unmeasured confounder model (stage II)

form3

The formula specification for the second unmeasured confounder model (stage III)

family1, family2, family3

The family object, communicating the types of models to be used for response (form1) and unmeasured confounder (⁠form2, form3⁠) models. See stats::family() for details

data

The dataset containing all variables (this function currently only supports a single dataset containing internally validated data)

n.iter

n.iter argument of rjags::coda.samples()

n.adapt

n.adapt argument of rjags::jags.model()

thin

thin argument of rjags::coda.samples()

n.chains

n.chains argument of rjags::jags.model()

filename

File name where to store jags code

quiet

The quiet parameter of rjags::jags.model(). Defaults to TRUE, but you can change it on a per-session basis with options(unm_quiet = FALSE).

progress.bar

The progress.bar parameter of rjags::update.jags(). Defaults to "none", but you can change it on a per-session basis with options(unm_progress.bar = "text").

code_only

Should only the code be created?

priors

Custom priors to use on regression coefficients, see examples.

response_nuisance_priors, confounder1_nuisance_priors, confounder2_nuisance_priors

JAGS code for the nuisance priors on parameters in a JAGS model (see examples)

response_params_to_track, confounder1_params_to_track, confounder2_params_to_track

Additional parameters to track when nuisance parameter priors are used (see examples)

...

Additional arguments to pass into rjags::jags.model(), such as inits

mod

The output of unm_glm()

x

Object to be printed

digits

Number of digits to round to; defaults to 3

print_call

Should the call be printed? Defaults to TRUE, but can be turned off with options("unm_print_call" = FALSE)

object

Model object for which the coefficients are desired

Value

(Invisibly) The output of rjags::coda.samples(), an object of class mcmc.list, along with attributes code containing the jags code used and file containing the filename of the jags code.

See Also

runm(), rjags::dic.samples()

Examples




# ~~ One Unmeasured Confounder Examples (II-Stage Model) ~~


# normal response, normal confounder model with internally validated data
(df <- runm(20, response = "norm"))

(unm_mod <- unm_glm(
  y ~ x + z1 + z2 + z3 + u1,  family1 = gaussian(),
  u1 ~ x + z1 + z2 + z3,      family2 = gaussian(),
  data = df
))

(unm_mod <- unm_glm(
  y ~ .,      family1 = gaussian(),
  u1 ~ . - y, family2 = gaussian(),
  data = df
))
glm(y ~ x + z1 + z2 + z3, data = df)
coef(unm_mod)

jags_code(unm_mod)
unm_glm(
  y ~ .,
  u1 ~ . - y,
  family1 = gaussian(),
  family2 = gaussian(),
  data = df, code_only = TRUE
)






[Package unmconf version 0.1.0 Index]