CLOSED_FORM$gen | R Documentation |
This function generates random values from the expression. Random values or closed form expression will share the same value as long as they have the same name.
CLOSED_FORM$gen(n, rhs_val = FALSE, computed = NULL)
n |
Integer. Number of observations. |
rhs_val |
Boolean. Whether or not to keep the right hand side values of the expression. |
computed |
List. If it is provided, random variables or random closed form expression will use the values from the list, which makes the expression potentially deterministic. |
Numeric values.
# Constant variable
a <- 1
# Random uniform variable
b <- rand_uniform()
# Define a closed form expression
cf <- closed_form(~3 * (exp(a) + b))
# Generate 5 values
cf$gen(5)
# Generate 5 values, and keep RHS
cf$gen(5, rhs_val = TRUE)
d <- rand_normal()
# Define a closed form expression with another closed form expression
cf2 <- closed_form(~cf + 3 * d)
# Generate 5 values
cf2$gen(5)
# Generate 5 values, and keep RHS
cf2$gen(5, rhs_val = TRUE)
# Define a closed form expression with two random variables of the same name
cf3 <- closed_form(~d + d)
# Both `d` will share the same values
cf3$gen(5, rhs_val = TRUE)
# Define a closed form expression with two closed form expressions of the same name
cf4 <- closed_form(~cf3 + cf3)
# Both `cf3` will share the same values, both `d` will share the same values as well
cf4$gen(5, rhs_val = TRUE)
# Define a closed form expression with two different closed form expressions,
# but contains same random variables
cf5 <- closed_form(~cf3 + cf4)
# Both `d` in `cf3` and `cf4` will share the same value
cf5$gen(5, rhs_val = TRUE)
# Control the value of `d`
cf5$gen(5, rhs_val = TRUE, computed = list(d = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.