dag_greta {causact}R Documentation

Generate a representive 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. Helpful error messages are scheduled for future versions of the causact package.


dag_greta(graph, mcmc = TRUE, meaningfulLabels = TRUE, ...)



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


a logical value indicating whether to sample from the posterior distribution. When mcmc=FALSE, the greta 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.


a logical value indicating whether to replace the indexed variable names in draws with abbreviated names representing the factor value corresponding to the index. This argument is treated as TRUE regardless of user input. The ability to retain numerical indexing will be in a subsequent release.


additional arguments to be passed onto greta::mcmc().


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_greta returns a character string of code that would help the user create three objects representing the posterior distribution:

  1. draws: An mcmc.list object containing raw output from the HMCMC sampler used by greta.

  2. drawsDF: A wide data frame with all latent variables as columns and all draws as rows. This data frame is useful for calculations based on the posterior

  3. tidyDrawsDF: A long data frame with each draw represented on one line. This data frame is useful for plotting posterior distributions.


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()
gretaCode = graph %>% dag_greta(mcmc=FALSE)
## Not run: 
## default functionality returns a data frame
# below requires Tensorflow installation
drawsDF = graph %>% dag_greta()
drawsDF %>% dagp_plot()

## End(Not run)

[Package causact version 0.4.0 Index]