library(simDAG)
# without replacement
dag <- empty_dag() +
node("A", type="rsample", x=1:10, replace=FALSE)
data <- sim_from_dag(dag, n_sim=5)
head(data)
# with replacement and selection probabilities
dag <- empty_dag() +
node("X", type="rbernoulli", p=0.5) +
node("A", type="rsample", x=c(1, 2, 3, 4), replace=TRUE,
prob=c(0.1, 0.3, 0.1, 0.5))
data <- sim_from_dag(dag, n_sim=100)
head(data)
# sampling rows from a data.frame object
# NOTE: The node name for the rsample() node will be ignored, because
# a data.frame is supplied to "x". The names of the variables in the
# data are used directly instead.
dag <- empty_dag() +
node("placeholder", type="rsample", x=data) +
node("Y", type="binomial", formula= ~ -2 + A*0.5 + X*-1)
data2 <- sim_from_dag(dag, n_sim=50)
head(data2)
Run the code above in your browser using DataLab