# NOT RUN {
model <- make_model('X->Y')
data_long <- simulate_data(model, n = 4)
data_short <- collapse_data(data_long, model)
# }
# NOT RUN {
model_1 <- update_model(model, data_long)
# }
# NOT RUN {
# Throws error unless compact data indicated:
model_3 <- update_model(model, data_short)
# }
# NOT RUN {
model_4 <- update_model(model, data_short, data_type = 'compact')
# It is possible to implement updating without data, in which case the posterior
# is a stan object that reflects the prior
model5 <- update_model(model)
# Advanced: Example of a model with tailored parameters.
# We take a model and add a tailored P matrix (which maps from parameters
# to causal types) and a tailored parameters_df which reports that
# all parameters are in one family.
# Parameters in this example are not connected with nodal types in any way.
model <- make_model('X->Y')
P <- diag(8)
colnames(P) <- rownames(model$causal_types)
model <- set_parameter_matrix(model, P = P)
model$parameters_df <- data.frame(
param_names = paste0('x',1:8),
param_set = 1, priors = 1, parameters = 1/8)
# Update fully confounded model on strongly correlated data
data <- make_data(make_model('X->Y'), n = 100,
parameters = c(.5, .5, .1,.1,.7,.1))
fully_confounded <- update_model(model, data, keep_fit = TRUE)
fully_confounded$stan_fit
query_model(fully_confounded, 'Y[X = 1] > Y[X=0]', using = 'posteriors')
# To see the confounding:
with(fully_confounded$posterior_distribution %>% data.frame(),
{par(mfrow = c(1,2))
plot(x1, x5, main = 'joint distribution of X0.Y00, X0.Y01')
plot(x1, x6, main = 'joint distribution of X0.Y00, X1.Y01')})
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab