Description Usage Arguments Value Examples

Create multivariate (correlated) data - for general distributions

1 2 3 |

`n` |
Number of observations |

`nvars` |
Number of variables |

`params1` |
A single vector specifying the mean of the distribution. The vector is of length 1 if the mean is the same across all observations, otherwise the vector is of length nvars. In the case of the uniform distribution the vector specifies the minimum. |

`params2` |
A single vector specifying a possible second parameter for the distribution. For the normal distribution, this will be the variance; for the gamma distribution, this will be the dispersion; and for the uniform distribution, this will be the maximum. The vector is of length 1 if the mean is the same across all observations, otherwise the vector is of length nvars. |

`dist` |
A string indicating "binary", "poisson" or "gamma", "normal", or "uniform". |

`rho` |
Correlation coefficient, -1 <= rho <= 1. Use if corMatrix is not provided. |

`corstr` |
Correlation structure of the variance-covariance matrix defined by sigma and rho. Options include "cs" for a compound symmetry structure and "ar1" for an autoregressive structure. |

`corMatrix` |
Correlation matrix can be entered directly. It must be symmetrical and positive semi-definite. It is not a required field; if a matrix is not provided, then a structure and correlation coefficient rho must be specified. |

`wide` |
The layout of the returned file - if wide = TRUE, all new correlated variables will be returned in a single record, if wide = FALSE, each new variable will be its own record (i.e. the data will be in long form). Defaults to FALSE. |

`cnames` |
Explicit column names. A single string with names separated by commas. If no string is provided, the default names will be V#, where # represents the column. |

`method` |
Two methods are available to generate correlated data. (1) "copula" uses the multivariate Gaussian copula method that is applied to all other distributions; this applies to all available distributions. (2) "ep" uses an algorithm developed by Emrich and Piedmonte. |

`idname` |
Character value that specifies the name of the id variable. |

data.table with added column(s) of correlated data

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```
set.seed(23432)
l <- c(8, 10, 12)
genCorGen(1000, nvars = 3, params1 = l, dist = "poisson", rho = .7, corstr = "cs")
genCorGen(1000, nvars = 3, params1 = 5, dist = "poisson", rho = .7, corstr = "cs")
genCorGen(1000, nvars = 3, params1 = l, dist = "poisson", rho = .7, corstr = "cs", wide = TRUE)
genCorGen(1000, nvars = 3, params1 = 5, dist = "poisson", rho = .7, corstr = "cs", wide = TRUE)
genCorGen(1000, nvars = 3, params1 = l, dist = "poisson", rho = .7, corstr = "cs",
cnames = "new_var")
genCorGen(1000, nvars = 3, params1 = l, dist = "poisson", rho = .7, corstr = "cs",
wide = TRUE, cnames = "a, b, c")
genCorGen(1000, nvars = 3, params1 = c(.3, .5, .7), dist = "binary", rho = .3, corstr = "cs")
genCorGen(1000, nvars = 3, params1 = l, params2 = c(1,1,1), dist = "gamma", rho = .3,
corstr = "cs", wide = TRUE)
genCorGen(1000, nvars = 3, params1 = c(.3, .5, .7), dist = "binary",
corMatrix = genCorMat(3), method = "ep")
genCorGen(1000, nvars = 3, params1 = c(.3, .5, .7), dist = "binary",
corMatrix = genCorMat(3), method = "copula")
``` |

kgoldfeld/simstudy documentation built on Dec. 23, 2018, 5:33 a.m.

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.