# A simple example
posteriorDF = data.frame(x = rnorm(100),
y = rexp(100),
z = runif(100))
posteriorDF %>%
dagp_plot(densityPlot = TRUE)
# More complicated example requiring 'numpyro'
if (FALSE) {
# Create a 2 node graph
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")
graph %>% dag_render()
# below requires Tensorflow installation
drawsDF = graph %>% dag_numpyro(mcmc=TRUE)
drawsDF %>% dagp_plot()
}
# A multiple plate example
library(dplyr)
poolTimeGymDF = gymDF %>%
mutate(stretchType = ifelse(yogaStretch == 1,
"Yoga Stretch",
"Traditional")) %>%
group_by(gymID,stretchType,yogaStretch) %>%
summarize(nTrialCustomers = sum(nTrialCustomers),
nSigned = sum(nSigned))
graph = dag_create() %>%
dag_node("Cust Signed","k",
rhs = binomial(n,p),
data = poolTimeGymDF$nSigned) %>%
dag_node("Probability of Signing","p",
rhs = beta(2,2),
child = "k") %>%
dag_node("Trial Size","n",
data = poolTimeGymDF$nTrialCustomers,
child = "k") %>%
dag_plate("Yoga Stretch","x",
nodeLabels = c("p"),
data = poolTimeGymDF$stretchType,
addDataNode = TRUE) %>%
dag_plate("Observation","i",
nodeLabels = c("x","k","n")) %>%
dag_plate("Gym","j",
nodeLabels = "p",
data = poolTimeGymDF$gymID,
addDataNode = TRUE)
graph %>% dag_render()
if (FALSE) {
# below requires Tensorflow installation
drawsDF = graph %>% dag_numpyro(mcmc=TRUE)
drawsDF %>% dagp_plot()
}
Run the code above in your browser using DataLab