Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling deterministic child node #55

Open
flyaflya opened this issue Dec 6, 2022 · 0 comments
Open

Handling deterministic child node #55

flyaflya opened this issue Dec 6, 2022 · 0 comments

Comments

@flyaflya
Copy link
Owner

flyaflya commented Dec 6, 2022

See the issue described here: https://github.com/prabinov42/Greta_causact_question/blob/main/greta_causact_2.md

If a child node is deterministic and not used as a parent node, causact incorrectly labels it as a distribution.

Temporary fix (use mcmc=FALSE):

graph %>% dag_greta(mcmc=FALSE)

Then delete distribution(lbs) <- kgs * 2.2 #LIKELIHOOD in the output code so you are left with the below:

## The below greta code will return a posterior distribution 
## for the given DAG. Either copy and paste this code to use greta
## directly, evaluate the output object using 'eval', or 
## or (preferably) use dag_greta(mcmc=TRUE) to return a data frame of
## the posterior distribution: 
lbs <- as_data(df$weight_lbs)   #DATA
mu     <- normal(mean = 90, sd = 10)      #PRIOR
sigma  <- exponential(rate = 1/20)        #PRIOR
kgs    <- normal(mean = mu, sd = sigma)   #PRIOR
lbs    <- kgs * 2.2   #OPERATION
#### DELETED LINE LOCATION ##########
gretaModel  <- model(kgs,mu,sigma)   #MODEL
meaningfulLabels(graph)
draws       <- mcmc(gretaModel)              #POSTERIOR
drawsDF     <- replaceLabels(draws) %>% as.matrix() %>%
                dplyr::as_tibble()           #POSTERIOR
tidyDrawsDF <- drawsDF %>% addPriorGroups()  #POSTERIOR

Run the above code to get drawsDF. If you now do drawsDF %>% dagp_plot(), you will see kgs as a column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant