View source: R/repeated_twoway_generation.R
twoway_simulation_correlated | R Documentation |
Both regular and internal function.
As regular function takes input generated by the calculate_mean_matrix
function and iteratively simulates repeated measures two-way factorial experiments.
Data are sampled from a normal, skewed normal or truncated normal distribution.
twoway_simulation_correlated(
group_size,
matrices_obj,
distribution = "normal",
shape = 0,
inferior_limit = -Inf,
superior_limit = Inf,
balanced = TRUE,
loss = NULL,
nsims = 200
)
group_size |
Integer or matrix - Sample size for each group (combination of factor levels). If |
matrices_obj |
List - Output generated by |
distribution |
Character - Type of distribution from which to sample, possible values are "normal", "skewed" and "truncated" |
shape |
Vector - Degree of skewness in the distribution. May be a single value, have a length equal to the number of levels of any one of the factors or a length equal to the product of the length of each factor. |
inferior_limit |
Numeric - Value for which the distribution is truncated on the left. Only valid if |
superior_limit |
Numeric - Value for which the distribution is truncated on the right. Only valid if |
balanced |
Logical - Whether the study will be performed with the same number of subjects in all groups. Default is |
loss |
Character - Type of selection of subjects in groups that have less observations than |
nsims |
Integer - Number of iterations |
As internal function runs with a single iteration inside graph_twoway_assumptions
, which in itself is inside 'calculate_mean_matrix' to generate data for the cell mean and standard deviation plot.
For unbalanced repeated measures designs, this function generates a simulation with max(group_size)
for all combinations of factors and then eliminates observations.
If loss="random"
elimination of in those factor combinations that have less participants or study subjects will occur at random. If loss="sequential"
the participants or subjects
from the groups with less observations will be a subset of participants or subjects of groups with more observations. This may not sound like the most efficient way to proceed, is quite fast anyhow.
The 'n' column in the output will reflect how many observations each factor combination has. This should match the input matrix.
Dataframe with simulated outcome values, factor level labels and iteration number.
## Repeated measures design, suppose subjects from 4 independent treatment groups
## measured at 5 different timepoints.
refmean <- 1
treatgroups <- 4
timepoints <- 5
treateff <- 1.5
timeeff <- 0.85
rho <- 0.8
withinf <- "fB"
factors_levels_names <- list(treatment=letters[1:treatgroups], time=1:timepoints)
effects_treat_time <- calculate_mean_matrix(refmean = refmean,
fAeffect = treateff, fBeffect = timeeff,
nlfA = treatgroups, nlfB = timepoints,
rho = rho, withinf = withinf,
label_list = factors_levels_names)
## Inspect plot to check if matrices correspond to design
effects_treat_time$meansplot
n <- 20
repeatedmeasures_experiment <- twoway_simulation_correlated(group_size = n,
matrices_obj = effects_treat_time)
head(repeatedmeasures_experiment, 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.