dag_greta: Generate a representive sample of the posterior distribution

Description Usage Arguments Value Examples

View source: R/dag_greta.R

Description

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.

Usage

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

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 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.

meaningfulLabels

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().

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_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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(greta)
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)

causact documentation built on Jan. 26, 2021, 1:07 a.m.