# 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')))
model$parameters_df
model <- make_model('X-> Y <- W') %>%
set_restrictions(statement = decreasing('X', 'Y'))
model$parameters_df
model <- make_model('X->Y') %>%
set_restrictions(decreasing('X', 'Y'))
model$parameters_df
model <- make_model('X->Y') %>%
set_restrictions(c(increasing('X', 'Y'), decreasing('X', 'Y')))
model$parameters_df
# \donttest{
# Restrict to define a model with monotonicity
model <- make_model('X->Y') %>%
set_restrictions(statement = c('Y[X=1] < Y[X=0]'))
grab(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)
grab(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(grab(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(grab(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)
grab(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'))
grab(model, "parameter_matrix")
# Restrictions on levels for endogenous nodes aren't allowed
if (FALSE) {
model <- make_model('X->Y') %>%
set_restrictions(statement = '(Y == 1)')
}
# 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'))
grab(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)
grab(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'))
grab(model, "parameter_matrix")
# }
Run the code above in your browser using DataLab