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)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
statementcontains 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'
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
distributionandvaluesat the same time.Setting a
distributionother than uniform, Jeffreys, or certainty.Setting negative values.
specifying
alter_atwith any ofnode,nodal_type,param_set,given,statement, orparam_namesspecifying
param_nameswith any ofnode,nodal_type,param_set,given,statement, oralter_atspecifying
statementwith any ofnodeornodal_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")
#> No specific parameters to alter values for specified. 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'")
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#> 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"))
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#> 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: A specified condition matches multiple parameters. In these cases it is unclear which parameter value should be assigned to which parameter. Assignment thus defaults to the order in which parameters appear in 'parameters_df'. We advise checking that parameter assignment was carried out as you intended.
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#> 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)
#>
#> Statement:
#> Y <- X
#>
#> Number of types by node:
#> X Y
#> 2 4
#>
#> Number of unit types: 8
#>
set_priors(model, distribution = "jeffreys")
#> No specific parameters to alter values for specified. Altering all parameters.
#>
#> Statement:
#> Y <- X
#>
#> Number of types by node:
#> X Y
#> 2 4
#>
#> Number of unit 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'")
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#>
#> Statement:
#> X -> M -> Y; X <-> Y; Y <-> X
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of unit 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"))
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#>
#> Statement:
#> X -> M -> Y; X <-> Y; Y <-> X
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of unit 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: A specified condition matches multiple parameters. In these cases it is unclear which parameter value should be assigned to which parameter. Assignment thus defaults to the order in which parameters appear in 'parameters_df'. We advise checking that parameter assignment was carried out as you intended.
#> Warning: You are altering parameters on confounded nodes. Alterations will be applied across all 'param_sets'. If this is not the alteration behavior you intended, try specifying the 'param_set' or 'given' option to more clearly indicate parameters whose values you wish to alter.
#>
#> Statement:
#> X -> M -> Y; X <-> Y; Y <-> X
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of unit 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")
#>
#> Statement:
#> X -> M -> Y; X <-> Y; Y <-> X
#>
#> Number of types by node:
#> X M Y
#> 2 4 4
#>
#> Number of unit types: 32
#>