View source: R/base_simhelpers.R

simdata_quantized | R Documentation |

Simulate quantized exposures for testing methods

```
simdata_quantized(
outcometype = c("continuous", "logistic", "survival", "multinomial"),
n = 100,
corr = NULL,
b0 = 0,
coef = c(1, 0, 0, 0),
q = 4,
yscale = 1,
shape0 = 3,
scale0 = 5,
censtime = 4,
ncheck = TRUE,
...
)
```

`outcometype` |
Character variable that is one of c("continuous", "logistic", "survival"). Selects what type of outcome should be simulated (or how). continuous = normal, continous outcome, logistic= binary outcome from logistic model, survival = right censored survival outcome from Weibull model. |

`n` |
Sample size |

`corr` |
NULL, or vector of correlations between the first exposure and subsequent exposures (if length(corr) < (length(coef)-1), then this will be backfilled with zeros) |

`b0` |
(continuous, binary outcomes) model intercept |

`coef` |
Vector of coefficients for the outcome (i.e. model coefficients for exposures). The length of this determines the number of exposures. |

`q` |
Number of levels or "quanta" of each exposure |

`yscale` |
(continuous outcomes) error scale (residual error) for normally distributed outcomes |

`shape0` |
(survival outcomes) baseline shape of weibull distribution rweibull |

`scale0` |
(survival outcomes) baseline scale of weibull distribution rweibull |

`censtime` |
(survival outcomes) administrative censoring time |

`ncheck` |
(logical, default=TRUE) adjust sample size if needed so that exposures are exactly evenly distributed (so that qgcomp::quantize(exposure) = exposure) |

`...` |
unused |

Simulate continuous (normally distributed errors), binary (logistic function), or event-time outcomes as a linear function

a data frame

`qgcomp.glm.boot`

, and `qgcomp.glm.noboot`

```
set.seed(50)
qdat = simdata_quantized(
outcometype="continuous",
n=10000, corr=c(.9,.3), coef=c(1,1,0,0),
q = 8
)
cor(qdat)
qdat = simdata_quantized(
outcometype="continuous",
n=10000, corr=c(-.9,.3), coef=c(1,2,0,0),
q = 4
)
cor(qdat)
table(qdat$x1)
qgcomp.glm.noboot(y~.,data=qdat)
qdat = simdata_quantized(
outcometype="multinomial",
n=10000, corr=c(-.9), coef=cbind(c(1,-1,0,0), c(1,.2,0,0)),
q = 4
)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.