dag_numpyro: Generate a representative sample of the posterior...

View source: R/dag_numpyro.R

dag_numpyroR Documentation

Generate a representative sample of the posterior distribution

Description

Generate a representative sample of the posterior distribution. The input graph object should be of class causact_graph and created using dag_create(). The specification of a completely consistent joint distribution is left to the user.

Usage

dag_numpyro(
  graph,
  mcmc = TRUE,
  num_warmup = 1000,
  num_samples = 4000,
  seed = 111
)

Arguments

graph

a graph object of class causact_graph representing a complete and conistent specification of a joint distribution.

mcmc

a logical value indicating whether to sample from the posterior distribution. When mcmc=FALSE, the numpyro code is printed to the console, but not executed. The user can cut and paste the code to another script for running line-by-line. This option is most useful for debugging purposes. When mcmc=TRUE, the code is executed and outputs a dataframe of posterior draws.

num_warmup

an integer value for the number of initial steps that will be discarded while the markov chain finds its way into the typical set.

num_samples

an integer value for the number of samples.

seed

an integer-valued random seed that serves as a starting point for a random number generator. By setting the seed to a specific value, you can ensure the reproducibility and consistency of your results.

Value

If mcmc=TRUE, returns a dataframe of posterior distribution samples corresponding to the input causact_graph. Each column is a parameter and each row a draw from the posterior sample output. If mcmc=FALSE, running dag_numpyro returns a character string of code that would help the user generate the posterior distribution; useful for debugging.

Examples

graph = dag_create() %>%
  dag_node("Get Card","y",
           rhs = bernoulli(theta),
           data = carModelDF$getCard) %>%
  dag_node(descr = "Card Probability by Car",label = "theta",
           rhs = beta(2,2),
           child = "y") %>%
  dag_node("Car Model","x",
           data = carModelDF$carModel,
           child = "y") %>%
  dag_plate("Car Model","x",
            data = carModelDF$carModel,
            nodeLabels = "theta")

graph %>% dag_render()
numpyroCode = graph %>% dag_numpyro(mcmc=FALSE)
## Not run: 
## default functionality returns a data frame
# below requires numpyro installation
drawsDF = graph %>% dag_numpyro()
drawsDF %>% dagp_plot()

## End(Not run)

causact documentation built on Sept. 8, 2023, 5:46 p.m.