create_bootdata: Create list of cluster bootstrapped datasets

Description Usage Arguments Value See Also Examples

Description

Based on an original dataset which includes a clustering variable, this function creates a list of nboot bootstrapped datasets with the cluster variable (as opposed to rows) sampled with replacement. If using complete case analysis, the function returns that list; if using multiple imputation, the function returns a list of nboot mice::mids objects based on each of those bootstrapped datasets.

Usage

1
create_bootdata(df, cluster_var, nboot, seed = NULL, impute = FALSE, ...)

Arguments

df

data.frame in "long" format.

cluster_var

character; matches one column name in df.

nboot

numeric; specifies how many datasets to create. Coerced to integer.

seed

numeric; if specified, sets seed for reproducibility.

impute

logical; whether to use mice to impute each bootstrapped dataset.

...

Additional arguments to pass to mice if desired. See mice for default settings and additional information.

Value

A list of length nboot, where each element is either 1) a data.frame including all records from each sampled value of df$cluster_var, or 2) a mice object based on one of the bootstrapped datasets.

See Also

mice

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
my_df <- data.frame(
  id = sample(1:50, size = 500, replace = TRUE),
  x = rnorm(n = 500),
  y = rbinom(n = 500, size = 1, prob = 0.2)
)

## Without imputation:
create_bootdata(df = my_df, cluster_var = "id", nboot = 25)

## To demo imputation, make some data 10% MCAR
my_df_mcar <- my_df
my_df_mcar$x[sample(1:500, size = 50)] <- NA
my_df_mcar$y[sample(1:500, size = 50)] <- NA

## Use default arguments to mice()
create_bootdata(
  df = my_df_mcar,
  cluster_var = "id",
  nboot = 25,
  impute = TRUE
)

## Supply arguments to mice()
create_bootdata(
  df = my_df_mcar,
  cluster_var = "id",
  nboot = 25,
  impute = TRUE,
  m = 10,
  method = "mean"
)

jenniferthompson/ClusterMultinom documentation built on May 7, 2019, 8:59 p.m.