View source: R/set_restrictions.R
| set_restrictions | R Documentation |
Restrict a model's parameter space. This reduces the number of nodal types and in consequence the number of unit causal types.
set_restrictions(
model,
statement = NULL,
join_by = "|",
labels = NULL,
param_names = NULL,
given = NULL,
keep = FALSE
)
model |
A |
statement |
A quoted expressions defining the restriction.
If values for some parents are not specified, statements should be
surrounded by parentheses, for instance |
join_by |
A string. The logical operator joining expanded types when
|
labels |
A list of character vectors specifying nodal types to be kept
or removed from the model. Use |
param_names |
A character vector of names of parameters to restrict on. |
given |
A character vector or list of character vectors specifying
nodes on which the parameter set to be restricted depends.
When restricting by |
keep |
Logical. If 'FALSE', removes and if 'TRUE' keeps only causal
types specified by |
Restrictions are made to nodal types, not to unit causal types.
Thus for instance in a model X -> M -> Y, one cannot apply a simple
restriction so that Y is nondecreasing in X, however one can
restrict so that M is nondecreasing in X and Y
nondecreasing in M. To have a restriction that Y be
nondecreasing in X would otherwise require restrictions on
causal types, not nodal types, which implies a form of undeclared
confounding (i.e. that in cases in which M is decreasing in X,
Y is decreasing in M).
Since restrictions are to nodal types, all parents of a node are
implicitly fixed. Thus for model make_model(`X -> Y <- W`) the
request set_restrictions(`(Y[X=1] == 0)`) is interpreted as
set_restrictions(`(Y[X=1, W=0] == 0 | Y[X=1, W=1] == 0)`).
Statements with implicitly controlled nodes should be surrounded by parentheses, as in these examples.
Note that prior probabilities are redistributed over remaining types.
An object of class model. The causal types and nodal types
in the model are reduced according to the stated restriction.
Other set:
set_confound(),
set_prior_distribution()
# 1. Restrict parameter space using statements
model <- make_model('X->Y') |>
set_restrictions(statement = c('X[] == 0'))
model <- make_model('X->Y') |>
set_restrictions(non_increasing('X', 'Y'))
model <- make_model('X -> Y <- W') |>
set_restrictions(c(decreasing('X', 'Y'), substitutes('X', 'W', 'Y')))
inspect(model, "parameters_df")
model <- make_model('X-> Y <- W') |>
set_restrictions(statement = decreasing('X', 'Y'))
inspect(model, "parameters_df")
model <- make_model('X->Y') |>
set_restrictions(decreasing('X', 'Y'))
inspect(model, "parameters_df")
model <- make_model('X->Y') |>
set_restrictions(c(increasing('X', 'Y'), decreasing('X', 'Y')))
inspect(model, "parameters_df")
# Restrict to define a model with monotonicity
model <- make_model('X->Y') |>
set_restrictions(statement = c('Y[X=1] < Y[X=0]'))
inspect(model, "parameter_matrix")
# Restrict to a single type in endogenous node
model <- make_model('X->Y') |>
set_restrictions(statement = '(Y[X = 1] == 1)', join_by = '&', keep = TRUE)
inspect(model, "parameter_matrix")
# Use of | and &
# Keep node if *for some value of B* Y[A = 1] == 1
model <- make_model('A->Y<-B') |>
set_restrictions(statement = '(Y[A = 1] == 1)', join_by = '|', keep = TRUE)
dim(inspect(model ,"parameter_matrix"))
# Keep node if *for all values of B* Y[A = 1] == 1
model <- make_model('A->Y<-B') |>
set_restrictions(statement = '(Y[A = 1] == 1)', join_by = '&', keep = TRUE)
dim(inspect(model, "parameter_matrix"))
# Restrict multiple nodes
model <- make_model('X->Y<-M; X -> M' ) |>
set_restrictions(statement = c('(Y[X = 1] == 1)', '(M[X = 1] == 1)'),
join_by = '&', keep = TRUE)
inspect(model, "parameter_matrix")
# Restrict using statements and given:
model <- make_model("X -> Y -> Z; X <-> Z") |>
set_restrictions(list(decreasing('X','Y'), decreasing('Y','Z')),
given = c(NA,'X.0'))
inspect(model, "parameter_matrix")
# Restrictions on levels for endogenous nodes aren't allowed
## Not run:
model <- make_model('X->Y') |>
set_restrictions(statement = '(Y == 1)')
## End(Not run)
# 2. Restrict parameter space Using labels:
model <- make_model('X->Y') |>
set_restrictions(labels = list(X = '0', Y = '00'))
# Restrictions can be with wildcards
model <- make_model('X->Y') |>
set_restrictions(labels = list(Y = '?0'))
inspect(model, "parameter_matrix")
# Deterministic model
model <- make_model('S -> C -> Y <- R <- X; X -> C -> R') |>
set_restrictions(labels = list(C = '1000', R = '0001', Y = '0001'),
keep = TRUE)
inspect(model, "parameter_matrix")
# Restrict using labels and given:
model <- make_model("X -> Y -> Z; X <-> Z") |>
set_restrictions(labels = list(X = '0', Z = '00'), given = c(NA,'X.0'))
inspect(model, "parameter_matrix")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.