Functionality for altering priors:
make_priors
Generates priors for a model.
set_priors
Adds priors to a model.
Extracts priors as a named vector
Usage
make_priors(
model,
alphas = NA,
distribution = NA,
alter_at = NA,
node = NA,
nodal_type = NA,
label = NA,
param_set = NA,
given = NA,
statement = NA,
join_by = "|",
param_names = NA
)
set_priors(
model,
alphas = NA,
distribution = NA,
alter_at = NA,
node = NA,
nodal_type = NA,
label = NA,
param_set = NA,
given = NA,
statement = NA,
join_by = "|",
param_names = NA
)
get_priors(model, nodes = NULL)
Arguments
- model
A model object generated by make_model().
- alphas
Real positive numbers giving hyperparameters of the Dirichlet distribution
- distribution
string indicating a common prior distribution (uniform, jeffreys or certainty)
- alter_at
string specifying filtering operations to be applied to parameters_df, yielding a logical vector indicating parameters for which values should be altered. (see examples)
- node
string indicating nodes which are to be altered
- nodal_type
string. Label for nodal type indicating nodal types for which values are to be altered
- label
string. Label for nodal type indicating nodal types for which values are to be altered. Equivalent to nodal_type.
- param_set
string indicating the name of the set of parameters to be altered
- given
string indicates the node on which the parameter to be altered depends
- statement
causal query that determines nodal types for which values are to be altered
- join_by
string specifying the logical operator joining expanded types when
statement
contains wildcards. Can take values'&'
(logical AND) or'|'
(logical OR).- param_names
vector of strings. The name of specific parameter in the form of, for example, 'X.1', 'Y.01'
- nodes
a vector of nodes
Value
A vector indicating the parameters of the prior distribution of the nodal types ("hyperparameters").
An object of class causal_model
. It essentially returns a
list containing the elements comprising a model
(e.g. 'statement', 'nodal_types' and 'DAG') with the `priors` attached
to it.
A vector indicating the hyperparameters of the prior distribution of the nodal types.
Details
Seven arguments govern which parameters should be altered. The default is 'all' but this can be reduced by specifying
* alter_at
String specifying filtering operations to be applied to
parameters_df, yielding a logical vector indicating parameters for which
values should be altered. "node == 'X' & nodal_type
* node
, which restricts for example to parameters associated with node
'X'
* label
or nodal_type
The label of a particular nodal type,
written either in the form Y0000 or Y.Y0000
* param_set
The param_set of a parameter.
* given
Given parameter set of a parameter.
* statement
, which restricts for example to nodal types that satisfy
the statement 'Y[X=1] > Y[X=0]'
* param_set
, given
, which are useful when setting confound
statements that produce several sets of parameters
Two arguments govern what values to apply:
* alphas
is one or more non-negative numbers and
* distribution
indicates one of a common class: uniform, Jeffreys, or
'certain'
Forbidden statements include:
Setting
distribution
andvalues
at the same time.Setting a
distribution
other than uniform, Jeffreys, or certainty.Setting negative values.
specifying
alter_at
with any ofnode
,nodal_type
,param_set
,given
,statement
, orparam_names
specifying
param_names
with any ofnode
,nodal_type
,param_set
,given
,statement
, oralter_at
specifying
statement
with any ofnode
ornodal_type
Examples
# make_priors examples:
# Pass all nodal types
model <- make_model("Y <- X")
make_priors(model, alphas = .4)
#> X.0 X.1 Y.00 Y.10 Y.01 Y.11
#> 0.4 0.4 0.4 0.4 0.4 0.4
make_priors(model, distribution = "jeffreys")
#> Altering all parameters.
#> X.0 X.1 Y.00 Y.10 Y.01 Y.11
#> 0.5 0.5 0.5 0.5 0.5 0.5
model <- CausalQueries::make_model("X -> M -> Y; X <-> Y")
#altering values using \code{alter_at}
make_priors(model = model, alphas = c(0.5,0.25),
alter_at = "node == 'Y' & nodal_type %in% c('00','01') & given == 'X.0'")
#> X.0 X.1 M.00 M.10 M.01 M.11 Y.00_X.0 Y.10_X.0
#> 1.00 1.00 1.00 1.00 1.00 1.00 0.50 1.00
#> Y.01_X.0 Y.11_X.0 Y.00_X.1 Y.10_X.1 Y.01_X.1 Y.11_X.1
#> 0.25 1.00 1.00 1.00 1.00 1.00
#altering values using \code{param_names}
make_priors(model = model, alphas = c(0.5,0.25),
param_names = c("Y.10_X.0","Y.10_X.1"))
#> X.0 X.1 M.00 M.10 M.01 M.11 Y.00_X.0 Y.10_X.0
#> 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.50
#> Y.01_X.0 Y.11_X.0 Y.00_X.1 Y.10_X.1 Y.01_X.1 Y.11_X.1
#> 1.00 1.00 1.00 0.25 1.00 1.00
#altering values using \code{statement}
make_priors(model = model, alphas = c(0.5,0.25),
statement = "Y[M=1] > Y[M=0]")
#> Warning: Possible ambiguity: use additional arguments or check behavior in parameters_df.
#> X.0 X.1 M.00 M.10 M.01 M.11 Y.00_X.0 Y.10_X.0
#> 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00
#> Y.01_X.0 Y.11_X.0 Y.00_X.1 Y.10_X.1 Y.01_X.1 Y.11_X.1
#> 0.50 1.00 1.00 1.00 0.25 1.00
#altering values using a combination of other arguments
make_priors(model = model, alphas = c(0.5,0.25),
node = "Y", nodal_type = c("00","01"), given = "X.0")
#> X.0 X.1 M.00 M.10 M.01 M.11 Y.00_X.0 Y.10_X.0
#> 1.00 1.00 1.00 1.00 1.00 1.00 0.50 1.00
#> Y.01_X.0 Y.11_X.0 Y.00_X.1 Y.10_X.1 Y.01_X.1 Y.11_X.1
#> 0.25 1.00 1.00 1.00 1.00 1.00
# set_priors examples:
# Pass all nodal types
model <- make_model("Y <- X")
set_priors(model, alphas = .4)
#>
#> Causal statement:
#> X -> Y
#>
#> Number of types by node:
#> X Y
#> 2 4
#>
#> Number of causal types: 8
set_priors(model, distribution = "jeffreys")
#> Altering all parameters.
#>
#> Causal statement:
#> X -> Y
#>
#> Number of types by node:
#> X Y
#> 2 4
#>
#> Number of causal types: 8
model <- CausalQueries::make_model("X -> M -> Y; X <-> Y")
#altering values using \code{alter_at}
set_priors(model = model, alphas = c(0.5,0.25),
alter_at = "node == 'Y' & nodal_type %in% c('00','01') & given == 'X.0'")
#>
#> Causal statement:
#> M -> Y; X -> M; X <-> Y
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of causal types: 32
#altering values using \code{param_names}
set_priors(model = model, alphas = c(0.5,0.25),
param_names = c("Y.10_X.0","Y.10_X.1"))
#>
#> Causal statement:
#> M -> Y; X -> M; X <-> Y
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of causal types: 32
#altering values using \code{statement}
set_priors(model = model, alphas = c(0.5,0.25),
statement = "Y[M=1] > Y[M=0]")
#> Warning: Possible ambiguity: use additional arguments or check behavior in parameters_df.
#>
#> Causal statement:
#> M -> Y; X -> M; X <-> Y
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of causal types: 32
#altering values using a combination of other arguments
set_priors(model = model, alphas = c(0.5,0.25), node = "Y",
nodal_type = c("00","01"), given = "X.0")
#>
#> Causal statement:
#> M -> Y; X -> M; X <-> Y
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of causal types: 32