update_model function

Fit causal model using 'stan'

Fit causal model using 'stan'

Takes a model and data and returns a model object with data attached and a posterior model

update_model( model, data = NULL, data_type = NULL, keep_type_distribution = TRUE, keep_event_probabilities = FALSE, keep_fit = FALSE, censored_types = NULL, ... )

Arguments

  • model: A causal_model. A model object generated by make_model.

  • data: A data.frame. Data of nodes that can take three values: 0, 1, and NA. In long form as generated by make_events

  • data_type: Either 'long' (as made by make_data) or 'compact' (as made by collapse_data). Compact data must have entries for each member of each strategy family to produce a valid simplex. When long form data is provided with missingness, missing data is assumed to be missing at random.

  • keep_type_distribution: Logical. Whether to keep the (transformed) distribution of the causal types. Defaults to TRUE

  • keep_event_probabilities: Logical. Whether to keep the (transformed) distribution of event probabilities. Defaults to FALSE

  • keep_fit: Logical. Whether to keep the stanfit object produced by sampling for further inspection. See ?stanfit for more details. Defaults to FALSE. Note the stanfit

    object has internal names for parameters (lambda), event probabilities (w), and the type distribution (types)

  • censored_types: vector of data types that are selected out of the data, e.g. c("X0Y0")

  • ...: Options passed onto sampling call. For details see ?rstan::sampling

Returns

An object of class causal_model with posterior distribution on parameters and other elements generated by updating; all elements accessible via get and inspect.

Examples

model <- make_model('X->Y') data_long <- make_data(model, n = 4) data_short <- collapse_data(data_long, model) model <- update_model(model, data_long) model <- update_model(model, data_short) # It is possible to implement updating without data, in which # case the posterior is a stan object that reflects the prior update_model(model) ## Not run: # Censored data types illustrations # Here we update less than we might because we are aware of filtered data data <- data.frame(X=rep(0:1, 10), Y=rep(0:1,10)) uncensored <- make_model("X->Y") |> update_model(data) |> query_model(te("X", "Y"), using = "posteriors") censored <- make_model("X->Y") |> update_model( data, censored_types = c("X1Y0")) |> query_model(te("X", "Y"), using = "posteriors") # Censored data: We learn nothing because the data # we see is the only data we could ever see make_model("X->Y") |> update_model( data, censored_types = c("X1Y0", "X0Y0", "X0Y1")) |> query_model(te("X", "Y"), using = "posteriors") ## End(Not run)

See Also

make_model to create a new model, summary.causal_model provides a summary method for output objects of class causal_model