mvrnorm_sim_obs: Simulate Microbiome Longitudinal Data from Multivariate...

Description Usage Arguments Value Examples

View source: R/sim_obs_functions.R

Description

This function is used in the gen_norm_microbiome_obs call.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
mvrnorm_sim_obs(
  id,
  time,
  group,
  ref,
  control_mean,
  sigma,
  rho,
  corr_str = c("ar1", "compound", "ind"),
  func_form = c("linear", "quadratic", "cubic", "M", "W", "L_up", "L_down"),
  beta,
  IP = NULL,
  dis_plot = FALSE,
  plot_trend = FALSE,
  zero_trunc = TRUE
)

Arguments

id

vector of length N that identifies repeated measurements for each unit

time

vector of length N that determines when values will be sampled for each unit

group

factor vector with two levels indicating the group assignment for each respective id

ref

character value identifying which group value to treat as control and which value to treat as treatment

control_mean

numeric value specifying the mean value for control subjects. all control subjects are assummed to have the same population mean value.

sigma

numeric value specifying the global population standard deviation for both control and treated individuals.

rho

value for the correlation parameter. must be between [0, 1]. see mvrnorm_corr_gen for details.

corr_str

correlation structure selected. see mvrnorm_corr_gen for details.

func_form

character value specifying the functional form for the longitduinal mean trend. see mean_trend for details.

beta

vector value specifying the parameters for the differential abundance function. see mean_trend for details.

IP

vector specifying any inflection points. depends on the type of functional form specified. see mean_trend for details. by default this is set to NULL.

dis_plot

logical argument on whether to plot the simulated data or not. by default plotting is turned off.

plot_trend

specifies whether to plot the true mean trend. see mean_trend for details.

zero_trunc

logical indicator designating whether simulated outcomes should be zero truncated. default is set to TRUE

Value

This function returns a list with the following objects:

df - data.frame object with complete outcome Y, subject ID, time, group, and outcome with missing data

Y - vector of complete outcome

Mu - vector of complete mean specifications used during simulation

Sigma - block diagonal symmetric matrix of complete data used during simulation

N - total number of observations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
set.seed(011520)
id_list <- lapply(seq_len(30), function(i){
obs <- sample(seq_len(10), size=1)
id_rep <- rep(i, obs)
})

time_interval <- c(0, 10)
time_list <- lapply(id_list, function(x){
time_len <- length(x)
times <- runif(time_len, min=time_interval[1], max=time_interval[2])
times <- times[order(times)]
})

group_list <- lapply(id_list, function(x){
group_len <- length(x)
tx_ind <- sample(seq_len(2), 1)
tx_group <- ifelse(tx_ind==1, "Control", "Treatment")
groups <- rep(tx_group, group_len)
})
id <- unlist(id_list)
group <- factor(unlist(group_list), levels = c("Control", "Treatment"))
time <- unlist(time_list)

# N=173 total repeated measurements
length(id)

# 15 control and 15 treated subjects
table(group[unique(id)])

# control times
ct <- unlist(lapply(unique(id[group=="Control"]), function(x){
length(id[id==x])
}))

#treatment times
tt <- unlist(lapply(unique(id[group=="Treatment"]), function(x){
length(id[id==x])
}))

# on average the treatment group has one more observation than control
mean(ct)
mean(tt)

mvrnorm_sim_obs(id=id, time=time, group=group, ref="Control", control_mean=2,
               sigma=1, rho=0.7, corr_str="compound", func_form="L_up",
               beta=1, IP=5, plot_trend=TRUE, dis_plot=TRUE, zero_trunc=TRUE)

microbiomeDASim documentation built on Nov. 8, 2020, 10:58 p.m.