Returned by KaguModel$discover() (equivalently kagu_discover()). Holds the
posterior probability distribution over candidate DAGs, together with the
per-graph log marginal likelihoods and the cache of unique local fits.
Public fields
dagsList of candidate DAG specifications evaluated.
labelsCharacter vector of short ids (one per DAG) - user-supplied names if the
dagslist was named, otherwise spreadsheet-style ids ("A","B", ...,"AA"). Used to reference DAGs in summaries and in$get_dag()/$plot_dag().nodesCharacter vector of node names.
dataThe data used for the search (for refitting via
$as_model()).log_marglikNumeric vector - log marginal likelihood per DAG.
log_priorNumeric vector - log prior per DAG.
log_posteriorNumeric vector - normalised log posterior per DAG.
probNumeric vector - posterior probability per DAG (sums to 1).
local_logmlNamed numeric - cached log marginal likelihood of each unique local model, keyed by
"node|sorted,parents".local_fitsNamed list - the fitted model for each unique local model (reused for effect propagation; same keys as
local_logml).mechanismsNamed list of
Mechanisminstances, one per node.n_modelsInteger - number of candidate DAGs.
n_unique_fitsInteger - number of unique local models fitted.
Methods
DiscoveryResult$new()
Create a DiscoveryResult (normally called by kagu_discover).
Usage
DiscoveryResult$new(
dags,
labels,
nodes,
data,
log_marglik,
log_prior,
log_posterior,
prob,
local_logml,
local_fits,
mechanisms,
n_unique_fits
)DiscoveryResult$summary()
Ranked summary table of the most probable DAGs.
Each DAG is referenced by its short id (see $labels) rather than by a
full edge listing - inspect a structure with $get_dag(id) or
$plot_dag(id).
DiscoveryResult$plot_dag()
Plot a candidate DAG by its id (see $labels).
Arguments
idCharacter scalar - a DAG id from
$summary()/$labels.node_posOptional named list of
c(row, col)node positions, passed tokagu_plot_dag().
DiscoveryResult$edge_probabilities()
Marginal posterior probability of each directed edge.
For each directed edge, sums the posterior probability of all DAGs that
contain it: P(from -> to | data) = sum_{G: from->to in G} P(G | data).
DiscoveryResult$effects()
Estimate a causal effect, averaged over the DAG posterior.
Computes the Bayesian model-averaged causal effect, \(P(Q \mid X) = \sum_G P(Q \mid X, G)\, P(G \mid X)\), by combining each DAG's effect posterior weighted by its posterior probability. This reflects structural uncertainty as well as parameter uncertainty, and is preferred over committing to a single DAG (e.g. the MAP) when the structure is not certain.
The signature mirrors KaguModel$effects() and the return value is the
same EffectResult type, so summaries, plots and downstream code are
identical to the single-DAG workflow. DAGs in which source has no causal
path to target contribute a zero effect, exactly as they should.
Usage
DiscoveryResult$effects(
source,
target,
values = NULL,
std_units = FALSE,
conditions = NULL,
sweep = FALSE,
sweep_n = 50L,
sweep_range = NULL,
hdi = 0.9,
prob_threshold = 0.001,
n_samples = 4000L
)Arguments
source, targetCharacter scalars - intervention and outcome nodes.
values, std_units, conditions, sweep, sweep_n, sweep_range, hdiPassed to
KaguModel$effects()(identical meaning).prob_thresholdNumeric - DAGs with posterior probability below this are skipped for efficiency (default 1e-3).
n_samplesInteger - size of the pooled mixture posterior (default 4000).
Returns
An EffectResult.
DiscoveryResult$map()
The maximum a posteriori (most probable) DAG.
Provided for inspection of the single most probable structure. For
estimating causal effects under structural uncertainty, prefer
$effects(), which averages over the whole posterior.
DiscoveryResult$as_model()
Refit a chosen DAG as a full KaguModel.
DiscoveryResult$plot()
Plot the posterior over DAGs.