node_negative_binomial {simDAG} | R Documentation |
Simulate a Node Using Negative Binomial Regression
Description
Data from the parents is used to generate the node using negative binomial regression by applying the betas to the design matrix and sampling from the rnbinom
function.
Usage
node_negative_binomial(data, parents, formula=NULL, betas,
intercept, theta)
Arguments
data |
A |
parents |
A character vector specifying the names of the parents that this particular child node has. If non-linear combinations or interaction effects should be included, the user may specify the |
formula |
An optional |
betas |
A numeric vector with length equal to |
intercept |
A single number specifying the intercept that should be used when generating the node. |
theta |
A single number specifying the theta parameter ( |
Details
This function uses the linear predictor defined by the betas
and the input design matrix to sample from a subject-specific negative binomial distribution. It does to by calculating the linear predictor using the data
, betas
and intercept
, exponentiating it and passing it to the mu
argument of the rnbinom
function of the stats package.
Value
Returns a numeric vector of length nrow(data)
.
Author(s)
Robin Denz
See Also
empty_dag
, node
, node_td
, sim_from_dag
, sim_discrete_time
Examples
library(simDAG)
set.seed(124554)
dag <- empty_dag() +
node("age", type="rnorm", mean=50, sd=4) +
node("sex", type="rbernoulli", p=0.5) +
node("smoking", type="negative_binomial", parents=c("sex", "age"),
betas=c(1.1, 0.4), intercept=-2, theta=0.05)
sim_dat <- sim_from_dag(dag=dag, n_sim=100)