Description Usage Arguments Value Examples
View source: R/sim_obs_functions.R
This function is used in the
gen_norm_microbiome_obs
call.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
id |
vector of length |
time |
vector of length |
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 |
corr_str |
correlation structure selected. see
|
func_form |
character value specifying the functional form for the
longitduinal mean trend. see |
beta |
vector value specifying the parameters for the differential
abundance function. see |
IP |
vector specifying any inflection points. depends on the type of
functional form specified. see |
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
|
zero_trunc |
logical indicator designating whether simulated outcomes should be zero truncated. default is set to TRUE |
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
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.