For the process_data
argument. It do three types of processing
in one step: Creating ordinal variables,
generating missing values, and computing
scales scores.
Arguments
- data
A data frame.
- cut_patterns
A named vector. The names are the names of the latent variables for which indicator scores will be converted. Each value must be the name of one of the built-in patterns (call
cut_patterns()to list the patterns and their names). Can be used withcutsbut a latent variable should appear only either incut_patternsorcuts, not both. If bothcut_patternsandcutsare set toNULL, then the original data (data) will be returned unchanged.- cuts
A named list. The names are the names of the latent variables for which indicator scores will be converted. Each element is a vector of the thresholds for the conversion.
-InfandInfwill be automatically included during the conversion. Can be used withcut_patternsbut a latent variable should appear only either incut_patternsorcuts, not both. If bothcut_patternsandcutsare set toNULL, then the original data (data) will be returned unchanged.- missing_values_args
A named list of optional arguments to be passed to
mice::ampute(). Note thatpropandmechwill override the values set for them inmissing_values_args, if any.- var_patterns
A list of named list. Used to specify the pattern at the latent variable level. Each list has two elements.
varsis the vector of latent variables names. The pattern will consist of all indicators of these latent variables.propis the proportion of missing for this pattern. If the values ofpropsummed to one, then the values will be used asfreqinmice::ampute(). If they do not summed to one andpropis not set manually, the sum will be used inprop, andpropdivided by the sum will be used asfreq.- vars_in_waves
A list of character vectors. Each vector denotes the latent variables or non-indicator observed variables in a wave. For example,
list("x", c("m1", "m2"), "y")means thatxis collected in Wave 1,m1andm2in Wave 2, andyin Wave 3.- attrition_rate
The probability that a case will drop out from one wave to another.
- prop
The proportion of missingness. Default is 0.5, about 50% of the cases have missing data. If set to
NULL, then the original data (data) will be returned unchanged.- mech
The missing data mechanism. Default is
"MCAR"(missing completely at random). Other possible values are"MAR"(missing at random) and"MNAR"(missing not at random). Please refer to the help ofmice::ampute()for details.- method
The method to be used to compute the scale scores. Can be
"mean"or"sum". Implemented bymean()andsum(). If set to"none", then the original data (data) will be returned unchanged.- na.rm
How missing value (
NA) are handled. Default isFALSE, the same default value formean()andsum().
Details
This function is to be used in
the process_data argument of
power4test().
This function is simply a wrapper of the following three functions:
Please refer to these functions on how the raw data is processed.
See also
power4test(). See also
ordinal_variables(), missing_values,
and scale_scores for the processes
employed.
Examples
# Specify the model
mod <-
"
m ~ x
y ~ m + x
"
# Specify the population values
mod_es <-
"
y ~ m: l
m ~ x: m
y ~ x: n
"
# Specify the numbers of indicators and reliability coefficients
k <- c(y = 3,
m = 4,
x = 5)
rel <- c(y = .70,
m = .70,
x = .70)
# Simulate the data
out <- power4test(
nrep = 2,
model = mod,
pop_es = mod_es,
n = 200,
number_of_indicators = k,
reliability = rel,
process_data = list(
fun = common_processes,
args = list(
prop = .75,
cut_patterns = c(x = "-ma3", y = "-ma3", m = "-ma3")
)
),
test_fun = test_parameters,
test_args = list(op = "~"),
parallel = FALSE,
iseed = 1234)
#> Recommend setting 'parallel' to TRUE for faster analysis
#> Simulate the data:
#> Fit the model(s):
#> Do the test(s): test_parameters: CIs (op: ~)
dat <- pool_sim_data(out)
head(dat, 50)
#> y1 y2 y3 m1 m2 m3 m4 x1 x2 x3 x4 x5
#> 1 2 1 1 1 1 NA 1 1 2 1 3 2
#> 2 3 2 3 3 NA 1 2 2 2 2 2 1
#> 3 1 2 2 3 3 2 2 2 1 NA 2 2
#> 4 2 3 2 NA 1 2 1 2 2 1 2 3
#> 5 2 2 3 3 3 2 3 1 NA 1 2 3
#> 6 2 3 1 3 3 2 2 NA 2 2 2 2
#> 7 3 2 3 2 2 3 1 2 1 2 2 3
#> 8 3 2 2 2 2 1 1 2 2 2 1 NA
#> 9 NA 2 2 2 2 1 2 2 2 3 2 2
#> 10 2 1 2 2 2 1 1 1 2 2 2 NA
#> 11 2 3 3 1 2 NA 1 1 1 2 2 2
#> 12 2 2 3 1 1 2 1 1 3 NA 2 2
#> 13 3 2 NA 1 2 2 2 2 2 2 2 1
#> 14 1 1 NA 2 2 1 1 2 3 3 1 2
#> 15 1 3 2 3 2 2 3 1 2 2 2 3
#> 16 2 2 2 2 2 1 3 3 3 2 2 3
#> 17 3 2 NA 2 3 3 2 3 3 3 3 3
#> 18 2 2 1 3 2 NA 2 2 2 2 2 2
#> 19 1 1 2 2 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