Skip to contents

For the process_data argument. It introduces missing values in the generated data.

Usage

missing_values(data, ..., prop = 0.5, mech = "MCAR")

Arguments

data

A data frame.

...

Optional arguments to be passed to mice::ampute().

prop

The proportion of missingness. Default is 0.5, about 50% of the cases have missing data.

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 of mice::ampute() for details.

Value

It returns a data frame with the missing values inserted.

Details

This function is to be used in the process_data argument of power4test().

The missing values are generated by mice::ampute(). Please refer to its help page, the vignette for this function: Generate missing values with ampute, and Schouten, Lugtig, and Vink (2018).

In addition to data, only two arguments are explicitly defined for missing_values(): prop and mech. The argument prop is defined to remind users of the default value for this argument. The argument mech, specifying the missing data mechanism, is defined because its default value is different from that of mice::ampute(). For missing_values(), the default value is "MCAR", missing completely at random.

Please refer to the help page of mice::ampute() for other available arguments.

Note for patterns and other arguments with variable names

If arguments such as patterns are specified, the variable names need to be those in the generated data. If indicator scores are generated, the names need to be the names of the indicators, not the names of the latent variables.

References

Schouten, R. M., Lugtig, P., & Vink, G. (2018). Generating missing values for simulation purposes: A multivariate amputation procedure. Journal of Statistical Computation and Simulation, 88(15), 2909–2930. doi:10.1080/00949655.2018.1491577

See also

power4test(). See also mice::ampute() for the amputation method.

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
"
# Simulate the data

out <- power4test(
         nrep = 2,
         model = mod,
         pop_es = mod_es,
         n = 200,
         process_data = list(fun = "missing_values",
                             args = list(prop = .75)),
         test_fun = test_parameters,
         test_args = list(op = "~"),
         parallel = FALSE,
         iseed = 1234)
#> Simulate the data:
#> Fit the model(s):
#> Do the test: test_parameters: CIs (op: ~) 

dat <- pool_sim_data(out)
head(dat, 50)
#>             m           y           x
#> 1  -1.5195119 -0.33953718          NA
#> 2   0.2754965  0.74116771          NA
#> 3          NA  0.61469627 -0.42139311
#> 4  -2.5074623          NA -0.89936441
#> 5   0.5345913          NA  0.41744132
#> 6          NA  0.92296971  0.15344474
#> 7  -0.1092821  1.54097927  1.46328305
#> 8  -0.8579043  0.53438233 -1.12150250
#> 9  -0.6937893 -0.31860684          NA
#> 10         NA -1.40090417 -0.07494709
#> 11 -0.8775498 -0.07672623          NA
#> 12 -1.0378117          NA -0.28470587
#> 13 -0.9529504  0.81692778 -0.70817118
#> 14 -0.5828019          NA -2.14763900
#> 15         NA  0.05502231 -0.28383716
#> 16         NA  0.23275632 -0.53407216
#> 17 -0.1475689 -0.20519217  1.13301019
#> 18         NA -1.05016512 -0.60406892
#> 19         NA -0.57957489  0.55751160
#> 20  2.3473487  1.71886859  0.14262929
#> 21 -0.2431461          NA -1.23686021
#> 22         NA  0.39384025  0.37414397
#> 23 -0.4520817  1.74285362 -0.10608612
#> 24  0.4882390  1.26039820          NA
#> 25         NA  0.01698569  0.65803485
#> 26 -1.3473106 -1.24503294  0.11396292
#> 27  1.0238298  3.03996439          NA
#> 28 -0.9418393          NA  0.11555344
#> 29 -0.3906407          NA -1.25399904
#> 30         NA -0.17363243  0.74186478
#> 31  0.6846544          NA -1.22290161
#> 32 -1.0293551          NA -1.91889413
#> 33         NA -1.26830940 -0.80993639
#> 34         NA -0.24959540 -0.74467723
#> 35 -1.7363079 -0.59175308          NA
#> 36 -0.6318099 -1.24908381  1.60675957
#> 37 -1.5889454          NA  1.63559945
#> 38 -1.0613986 -0.75142725          NA
#> 39 -0.6628889 -0.30588127 -1.27383493
#> 40 -0.4374940  0.29590920  0.02314656
#> 41  1.5288677  0.81564640  0.48712123
#> 42 -1.0605284          NA -0.13702750
#> 43 -0.7644422 -1.33291970          NA
#> 44 -0.5511355  0.34032811          NA
#> 45 -1.3348261          NA -1.28762031
#> 46 -0.5015741 -0.03285081  1.40776574
#> 47 -0.9761024  0.68738293  0.26737269
#> 48 -1.3168377 -0.30813888          NA
#> 49         NA  0.02788677  0.32527122
#> 50         NA  0.30452265  2.06248097