Title: | Mutate Data Frames with Random Variates |
---|---|
Description: | Work within the 'dplyr' workflow to add random variates to your data frame. Variates can be added at any level of an existing column. Also, bounds can be specified for simulated variates. |
Authors: | Kyle T Baron [aut, cre, cph] |
Maintainer: | Kyle T Baron <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.2.9002 |
Built: | 2024-11-09 02:51:33 UTC |
Source: | https://github.com/kylebaron/dmutate |
Create individual data frame from a covset object
as_idata(.covset, .n)
as_idata(.covset, .n)
.covset |
a covset object |
.n |
number of IDs to simulate |
cov1 <- covset(Y ~ rbinomial(0.2), Z ~ rnorm(2,2)) as_idata(cov1, 10)
cov1 <- covset(Y ~ rbinomial(0.2), Z ~ rnorm(2,2)) as_idata(cov1, 10)
build_covform
formulates then parses a formula that
can be used in a covset. build_covobj
just assembles
the object directly.
build_covform(var, dist, args, lower = NULL, upper = NULL, by = NULL, envir = parent.frame()) build_covobj(var, dist, args, upper = NULL, lower = NULL, by = NULL, envir = parent.frame())
build_covform(var, dist, args, lower = NULL, upper = NULL, by = NULL, envir = parent.frame()) build_covobj(var, dist, args, upper = NULL, lower = NULL, by = NULL, envir = parent.frame())
var |
variable name, character |
dist |
distribution function name |
args |
character vector of arguments for |
lower |
lower limits for var |
upper |
upper limits for var |
by |
grouping variable |
envir |
environment for resolving symbols in expressions |
When length of var
is greater than one,
both lower
and upper
must be named vectors when specifiation is
made. However, it is acceptable to specify nothing or to use unnamed limits
when the lenght of var is 1.
build_covform("WT", "rnorm", c("mu = 80", "sd = 40"), lower = 40, upper = 140) build_covform("WT", "rnorm", "80,40", lower = 40, upper = 140) build_covobj("WT", "rnorm", "80,40", lower = 40, upper = 140)
build_covform("WT", "rnorm", c("mu = 80", "sd = 40"), lower = 40, upper = 140) build_covform("WT", "rnorm", "80,40", lower = 40, upper = 140) build_covobj("WT", "rnorm", "80,40", lower = 40, upper = 140)
Covobj and covset objects.
Create a set of covariates.
new_covobj(x, envir = parent.frame(), ...) ## S3 method for class 'covobj' print(x, ...) ## S4 method for signature 'covobj' as.list(x, ...) ## S4 method for signature 'covset' as.list(x, ...) ## S3 method for class 'covset' print(x, ...) covset(..., envir = parent.frame()) rvset(...) as.covset(x)
new_covobj(x, envir = parent.frame(), ...) ## S3 method for class 'covobj' print(x, ...) ## S4 method for signature 'covobj' as.list(x, ...) ## S4 method for signature 'covset' as.list(x, ...) ## S3 method for class 'covset' print(x, ...) covset(..., envir = parent.frame()) rvset(...) as.covset(x)
x |
a formula; may be quoted |
envir |
for formulae |
... |
formulae to use for the covset |
rvset
is an alias for covset
.
obj <- new_covobj(Y[0,80] ~ rnorm(20,50)) obj as.list(obj) a <- Y ~ runif(0,1) b <- Z ~ rbeta(1,1) set <- covset(a,b) set as.list(set)
obj <- new_covobj(Y[0,80] ~ rnorm(20,50)) obj as.list(obj) a <- Y ~ runif(0,1) b <- Z ~ rbeta(1,1) set <- covset(a,b) set as.list(set)
mutate a data frame, adding random variables.
Apply formulae to a data frame
dmutate(data, ...)
dmutate(data, ...)
data |
a data frame |
... |
formulae and other arguments for |
idata <- dplyr::data_frame(ID = 1:10) dmutate(idata, y ~ rbinomial(0.5), wt ~ rnorm(mu,sd), envir = list(mu = 50, sd = 20))
idata <- dplyr::data_frame(ID = 1:10) dmutate(idata, y ~ rbinomial(0.5), wt ~ rnorm(mu,sd), envir = list(mu = 50, sd = 20))
Add random variates to a data frame.
mutate_random(data, input, ...) ## S4 method for signature 'data.frame,formula' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,character' mutate_random(data, input, envir = parent.frame(), ...) ## S4 method for signature 'data.frame,list' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,covset' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,covobj' mutate_random(data, input, envir = parent.frame(), ...)
mutate_random(data, input, ...) ## S4 method for signature 'data.frame,formula' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,character' mutate_random(data, input, envir = parent.frame(), ...) ## S4 method for signature 'data.frame,list' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,covset' mutate_random(data, input, ...) ## S4 method for signature 'data.frame,covobj' mutate_random(data, input, envir = parent.frame(), ...)
data |
the data.frame to mutate |
input |
an unquoted R formula; see details |
... |
additional inputs |
envir |
environment for object lookup |
data <- data.frame(ID=1:10, GROUP = sample(c(1,2,3),10,replace=TRUE)) mutate_random(data, AGE[40,90] ~ rnorm(55,50)) mutate_random(data, RE ~ rbeta(1,1) | GROUP) e <- list(lower=40,upper=140,mu=100,sd=100) egfr <- covset(EGFR[lower,upper] ~ rnorm(mu,sd)) mutate_random(data,egfr,envir=e)
data <- data.frame(ID=1:10, GROUP = sample(c(1,2,3),10,replace=TRUE)) mutate_random(data, AGE[40,90] ~ rnorm(55,50)) mutate_random(data, RE ~ rbeta(1,1) | GROUP) e <- list(lower=40,upper=140,mu=100,sd=100) egfr <- covset(EGFR[lower,upper] ~ rnorm(mu,sd)) mutate_random(data,egfr,envir=e)
Wrapper for rbinom
with trial size of 1.
rbinomial(n, p, ...) rbern(n, p, ...)
rbinomial(n, p, ...) rbern(n, p, ...)
n |
number of variates |
p |
probability of success |
... |
passed along as appropriate |
The size
of each trial is always 1.
Simulate from multivariate normal distribution.
rmvnorm(n, mu, Sigma) rlmvnorm(n, ...) rmassnorm(n, ...) rlmassnorm(n, ...)
rmvnorm(n, mu, Sigma) rlmvnorm(n, ...) rmassnorm(n, ...) rlmassnorm(n, ...)
n |
number of variates |
mu |
vector of means |
Sigma |
variance-covariance matrix with number of columns equal to
length of |
... |
arguments passed to |
rlmvnorm
is a multivariate log normal.
rmassnorm
and rlmassnorm
simulate the
multivariate normal using the MASS
package.
Returns a matrix of variates with number of rows
equal to n
and mumber of columns equal to length of mu
.