miList
to
miVariable
to ordinary
objects when possible.
miTrim(x, miVar = T, trimClassed = NULL) miTrimAux(x1, x, miVar = T, trimClassed = NULL)
TRUE
,
miList
objects are converted to
miVariable
objects when possible.
FALSE
, avoid changes that would create objects with
an
oldClass
that contain any
mi
objects.
If
TRUE
or
1
allow an the object to contain
miVariable
objects, and if
2
allow
miList
objects.
If
NULL
the decision is
made by each
miTrimAux
method (
TRUE
for the
data.frame
method,
FALSE
for other current methods).
This argument does not affect objects with slots; no change
will be made that puts an object into a slot that is not
acceptable for the slot.
x
,
in that
miSubscript
gives identical
results for
x
and this object.
The result has
mi
objects moved to the lowest levels
possible (subject to the
trimClassed
constraint),
redundant multiple imputations eliminated, and
(if
miVar=TRUE
)
miList
objects are converted
to
miVariable
objects where possible.
miTrim
converts
miList
objects containing lists to
lists containing
miVariable
or
miList
objects,
and converts
miList
to
miVariable
to ordinary objects
if possible.
If
x
is of class
miList
and the elements of
x
(call these "multiple imputations") are (unclassed)
lists with the same length, mode, names, and attributes,
the result is a list with the
latter elements at the top level, each of which contains the information
from the multiple imputations.
If the imputations are redundant, the element is an ordinary object.
Otherwise, if the imputations are not lists, the
element is an
miVariable
object if the imputations are compatible
(same length, mode, and attributes), else an
miList
object.
If the imputations are lists or have slots, then
miTrim
is called
recursively on the elements.
For example, if
x
is an
miList
of length 2 containing
multiple imputations
"MI1"
and
"MI2"
, each of which is a list
with elements
"A"
,
"B"
,
"C"
and
"D"
.
The result is a list with elements
"A"
,
"B"
,
"C"
, and
"D"
.
Suppose the original two
A
elements are identical;
then
A
is an ordinary element, with the redundant copy eliminated.
Suppose the two
B
elements are numerical or character
vectors of the same length, mode, and attributes;
then
B
is a numerical or character
miVariable
object
(if
miVar=T
) or an
miList
object (if
miVar=F
).
Suppose the
C
elements not lists but have different length or
attributes;
then
C
is an
miList
object.
Suppose the
D
elements are lists;
then the function is called recursively.
The functions avoid making such conversions if the result
might be an illegal object, for example an
lm
object for
which some of the components are
miList
or
miVariable
objects; instead the original object is returned, e.g.
an
miList
object whose components are ordinary
lm
objects.
For objects with slots, an illegal object would be
one for which a slot specification does not allow an
miList
or
miVariable
object. For an object with an old-style class,
the behavior is determined by the
trimClassed
argument;
trimClassed=TRUE
allows
miVariable
objects, and
trimClassed=2
allows either type of
mi
object.
miTrimAux
should not normally be called directly.
There is an
miTrimAux.data.frame
method
for which the implicit default value of
trimClassed
is
TRUE
; this allows
miVariable
(but not
miList
) objects
to be variables in a data frame.
x <- miList(list(MI1 = list(a = 1:4, b = c(1:5,7:8)), MI2 = list(a = 1:4, b = c(1:5,6,8)))) miTrim(x) object.size(crimeImpExample) # 6827 object.size(miTrim(crimeImpExample)) # 2008 x <- miList(list(MI1 = data.frame(a = 1:4, b = c(1:4)), MI2 = data.frame(a = 1:4, b = c(1:2,4:3)))) miTrim(x) # data frame containing an miVariable miPrint(miTrim(x)) # show the imputations too x <- miList(list(MI1 = data.frame(a = 1:4, b = 1:4), MI2 = data.frame(a = 1:5, b = 1:5))) miTrim(x) # Did nothing, due to varying lengths