This function binds the shadow matrix to the data.
Usage
shadow_bind_data(
data,
shadow = NULL,
naniar_shadow = FALSE,
id_cols = union(get_id_cols_abcd(), get_id_cols_hbcd()),
suffix = "_shadow"
)
Arguments
- data
tibble. The data.
- shadow
tibble. The shadow matrix. If
naniar_shadow
isTRUE
, this argument is ignored.- naniar_shadow
logical. Whether to use
naniar::as_shadow()
to create the shadow matrix from data instead of providing it as an argument.- id_cols
character. The columns to join by (the identifier column(s)) in the data and shadow matrices (Default: identifier columns used in ABCD and HBCD). In
naniar_shadow = TRUE
, these columns are not included in the shadow matrix.- suffix
character. The suffix to add to the shadow columns. Default is
"_shadow"
. For example, if the column name is"var1"
and the suffix is"_shadow"
, the resulted column name will be"var1_shadow"
.If
naniar_shadow = TRUE
, the suffix is_NA
, as this suffix will have the most compatibility with other functions in thenaniar
package.
Value
a dataframe of the data matrix with shadow columns. It will be 2x the size of the original data matrix.
Details
Data requirements
If naniar_shadow = FASLE
and shadow
is provided, the two dataframes
must have the same columns, order of the columns does not matter, but
ID columns must be the same in both dataframes. If there are extra
rows in the shadow matrix, they will be ignored.
ABCD and HBCD data
NBDC releases HBCD data with shadow matrices, which can be used for
the shadow
argument. To work with ABCD data, the option for
now is to use naniar_shadow = TRUE
, which will create a shadow matrix
from the data using naniar::as_shadow()
.
Examples
shadow <- tibble::tibble(
participant_id = c("1", "2", "3"),
session_id = c("1", "2", "3"),
var1 = c("Unknown", NA, NA),
var2 = c("Wish not to answer", NA, NA)
)
data <- tibble::tibble(
participant_id = c("1", "2", "3"),
session_id = c("1", "2", "3"),
var1 = c(NA, NA, 1),
var2 = c(NA, 2, NA)
)
shadow_bind_data(data, shadow)
#> Error in check_pkgs(pkgs = list(NBDCtoolsData = list(remote = "nbdc-datahub/NBDCtoolsData")), abort_msg = "NBDCtoolsData package is not installed", quiet = quiet): NBDCtoolsData package is not installed
#> ✖ `NBDCtoolsData`
#> ℹ Please install the missing packages with:
#>
#> renv::install(c("nbdc-datahub/NBDCtoolsData"))
if (FALSE) { # \dontrun{
shadow_bind_data(data, naniar_shadow = TRUE)
} # }