compare_mids()
is a combination of
all.equal()
and
identical()
for mids
objects. Like
all.equal()
, it displays a summary of element-wise differences (it also
explicitly lists elements that are equal). However, rather than outputting
these differences as a character
vector if found, it always returns either
TRUE
or FALSE
. If quiet = FALSE
, the return value is invisible.
Usage
compare_mids(
x,
y,
show_msg = TRUE,
show_rtn = !show_msg,
ignore_rng = NULL,
ignore_call = TRUE,
ignore_version = TRUE,
ignore_date = TRUE
)
Arguments
- x, y
mids
objects to compare, as created bymice::mice()
,future_mice()
,mice::mice.mids()
,future_mids()
, etc.- show_msg
Should the message displaying element-wise comparisons be shown?
- show_rtn
Should the return value be visible? The default is the opposite of
show_msg
, so that either the message or return value is shown, but not both.- ignore_rng
Should elements or components of elements affected by the RNG state be ignored? See Details for more information. The default is to ignore when different package namespaces are detected in the
mids$call
, otherwise to check.- ignore_call, ignore_version, ignore_date
Should the corresponding
mids
element (mids$call
,mids$version
,mids$date
, respectively) be ignored in equality comparison? These elements do not usually impact results if all other elements are identical and can thus usually be safely ignored.
Details
Proper random number generation requires different methods when performing
operations in parallel; thus, is it generally not possible to exactly
replicate mids
objects produced sequentially when imputing chains in
parallel. In particular, the imputed values will differ, as well as any
functions of those values (chainMean
, chainVar
, loggedEvents
). This
function takes the stance that imputations performed by functions in the
same package should be consistent, but functions from different packages
may handle random number generation differently. Thus, if compare_mids()
can detect that two functions came from the same package, it will compare
the full RNG-related elements by default. Otherwise, it will check that
attributes independent of random number generation are the same, but it will
allow differences between attributes and data dependent on the RNG state. If
RNG-related attributes are ignored, the RNG state itself is also ignored, so
differences in seed
and lastSeedValue
are also allowed in this case.
Examples
m_mids <- mice::mice(mice::nhanes, m = 1L, maxit = 1L)
#>
#> iter imp variable
#> 1 1 bmi hyp chl
f_mids <- future_mice(mice::nhanes, m = 1L, maxit = 1L)
#> Warning: Sampling did not converge in 1 iteration
#> R-hat: NA
compare_mids(m_mids, f_mids)
#> Elements of `x` not in `y`
#> ✔ None
#> Elements of `y` not in `x`
#> ✔ None
#> Shared elements with differences:
#> ✔ None
#> Shared elements without differences:
#> ✔ data
#> ✔ imp
#> ✔ m
#> ✔ where
#> ✔ blocks
#> ✔ nmis
#> ✔ method
#> ✔ predictorMatrix
#> ✔ visitSequence
#> ✔ formulas
#> ✔ post
#> ✔ blots
#> ✔ ignore
#> ✔ iteration
#> ✔ chainMean
#> ✔ chainVar
#> Shared elements ignored:
#> ℹ call
#> ℹ seed
#> ℹ lastSeedValue
#> ℹ loggedEvents
#> ℹ version
#> ℹ date