We print out the inference table and then provide a helper function to let you quickly see the conditional inferences.
You can also see the solutions in Chapter 12 or by using the shiny.
1 Set up and helper function
Code
library(CausalQueries)library(knitr)library(tidyverse)data_consistent <-function(my_table, seen =c("S1", "Y0")) {for(j in seen){ my_table <- my_table[c(names(my_table)[grepl(j, names(my_table))], "in_query", "priors")] } my_table <- my_table |>filter( my_table |>select(-in_query, -priors) |>apply(1, sum) >0) my_table |>select(-in_query, -priors) pDQ <- my_table |>filter(in_query) |>pull(priors) |>sum() pD <- my_table |>pull(priors) |>sum()print(c("prob of Data and Query:", pDQ))print(c("prob of Data:", pD))print(c("prob Query | Data:", pDQ/pD))print(my_table)}
2 Model parameters
Check that the model has the parameters we want!
Code
model <-make_model("S -> C -> Y <- R <- X; X -> C -> R") |>set_restrictions(labels =list(C =c('1110', '1111'), R =c('0000', '0001'), Y ='0001'),keep =TRUE)query <-"Y[X=1] > Y[X=0]"model$parameters_df |>kable()