Missing data


exploration, imputation,
and evaluation

Hanne Oberman

Utrecht University

Missing data

NAs


range(your_dataset$Y)
[1] NA NA

Complete-case analysis (CCA)


mean(your_dataset$Y)
[1] NA


mean(your_dataset$Y, na.rm = TRUE)
[1] 0

CCA decreases sample size

CCA biases estimates

CCA yields invalid inferences

Alternative solution

install.packages("mice")
install.packages("ggmice")
install.packages("ggplot2")
install.packages("palmerpenguins")

Notation

  • \(Y\) random variable with missing data

    • \(Y^\mathrm{obs}\) true and observed values of \(Y\)
    • \(Y^\mathrm{mis}\) true but unobserved values of \(Y\)
  • \(X\) complete covariate

  • \(R\) response indicator

    • \(R = 1\) if \(Y\) is observed
    • \(R = 0\) if \(Y\) is missing

Missing data model

\[ P(R|Y^\mathrm{obs}, Y^\mathrm{mis}, X, \psi) \]

%%{
init: {
  "flowchart": {"useMaxWidth": "true", "htmlLabels": "true", "theme": "neutral"},
  "securityLevel": "loose"
}}%%
flowchart TD
    subgraph incomplete variable
          A[Y<sup>obs</sup>]
          B[Y<sup>mis</sup>]
    end
    subgraph covariate
          C[X]
    end
    D(ψ)
    E(R)
    A -.-> E
    B -.-> E    
    C -.-> E 
    D --> E 

MCAR: Missing Completely at Random

\[ P(R|Y^\mathrm{obs}, Y^\mathrm{mis}, X, \psi) = P(R|\psi) \]

Examples:

  • data transmission error
  • random sample

MAR: Missing at Random

\[ P(R|Y^\mathrm{obs}, Y^\mathrm{mis}, X, \psi) = P(R|Y^\mathrm{obs}, X, \psi) \]

Examples:

  • income, where we have \(X\) related to wealth
  • branch patterns (e.g. how old are your children?)

MNAR: Missing Not at Random

\[ P(R|Y^\mathrm{obs}, Y^\mathrm{mis}, X, \psi) \text{ does not simplify } \]

Examples:

  • income, without covariates related to income
  • self-reported body weight

Implications

  • Missing Completely At Random (MCAR) \(\approx\) not data dependent
  • Missing At Random (MAR) \(\approx\) seen data dependent
  • Missing Not At Random (MNAR) \(\approx\) unseen data dependent

Imputation

MICE

mice

Case study

set.seed(123)
library(palmerpenguins)
library(mice)
library(ggmice)
library(ggplot2)

Research question

Code
ggplot(penguins, aes(body_mass_g, flipper_length_mm, color = species)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) + 
  scale_color_manual(values = c("Adelie" = "darkorange", "Chinstrap" = "darkorchid", "Gentoo" = "cyan4")) +
  theme_classic()

Research question

Code
ggmice(penguins, aes(body_mass_g, flipper_length_mm, group = species)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) 

Incomplete data

str(penguins)
tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
 $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
 $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
 $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
 $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
 $ sex              : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
 $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...

Incomplete data

visdat::vis_dat(penguins)

Response indicator

is.na(penguins)
       species island bill_length_mm bill_depth_mm flipper_length_mm
  [1,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [2,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [3,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [4,]   FALSE  FALSE           TRUE          TRUE              TRUE
  [5,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [6,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [7,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [8,]   FALSE  FALSE          FALSE         FALSE             FALSE
  [9,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [10,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [11,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [12,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [13,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [14,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [15,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [16,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [17,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [18,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [19,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [20,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [21,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [22,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [23,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [24,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [25,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [26,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [27,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [28,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [29,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [30,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [31,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [32,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [33,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [34,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [35,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [36,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [37,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [38,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [39,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [40,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [41,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [42,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [43,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [44,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [45,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [46,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [47,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [48,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [49,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [50,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [51,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [52,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [53,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [54,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [55,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [56,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [57,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [58,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [59,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [60,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [61,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [62,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [63,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [64,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [65,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [66,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [67,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [68,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [69,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [70,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [71,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [72,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [73,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [74,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [75,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [76,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [77,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [78,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [79,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [80,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [81,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [82,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [83,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [84,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [85,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [86,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [87,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [88,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [89,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [90,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [91,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [92,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [93,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [94,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [95,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [96,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [97,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [98,]   FALSE  FALSE          FALSE         FALSE             FALSE
 [99,]   FALSE  FALSE          FALSE         FALSE             FALSE
[100,]   FALSE  FALSE          FALSE         FALSE             FALSE
[101,]   FALSE  FALSE          FALSE         FALSE             FALSE
[102,]   FALSE  FALSE          FALSE         FALSE             FALSE
[103,]   FALSE  FALSE          FALSE         FALSE             FALSE
[104,]   FALSE  FALSE          FALSE         FALSE             FALSE
[105,]   FALSE  FALSE          FALSE         FALSE             FALSE
[106,]   FALSE  FALSE          FALSE         FALSE             FALSE
[107,]   FALSE  FALSE          FALSE         FALSE             FALSE
[108,]   FALSE  FALSE          FALSE         FALSE             FALSE
[109,]   FALSE  FALSE          FALSE         FALSE             FALSE
[110,]   FALSE  FALSE          FALSE         FALSE             FALSE
[111,]   FALSE  FALSE          FALSE         FALSE             FALSE
[112,]   FALSE  FALSE          FALSE         FALSE             FALSE
[113,]   FALSE  FALSE          FALSE         FALSE             FALSE
[114,]   FALSE  FALSE          FALSE         FALSE             FALSE
[115,]   FALSE  FALSE          FALSE         FALSE             FALSE
[116,]   FALSE  FALSE          FALSE         FALSE             FALSE
[117,]   FALSE  FALSE          FALSE         FALSE             FALSE
[118,]   FALSE  FALSE          FALSE         FALSE             FALSE
[119,]   FALSE  FALSE          FALSE         FALSE             FALSE
[120,]   FALSE  FALSE          FALSE         FALSE             FALSE
[121,]   FALSE  FALSE          FALSE         FALSE             FALSE
[122,]   FALSE  FALSE          FALSE         FALSE             FALSE
[123,]   FALSE  FALSE          FALSE         FALSE             FALSE
[124,]   FALSE  FALSE          FALSE         FALSE             FALSE
[125,]   FALSE  FALSE          FALSE         FALSE             FALSE
[126,]   FALSE  FALSE          FALSE         FALSE             FALSE
[127,]   FALSE  FALSE          FALSE         FALSE             FALSE
[128,]   FALSE  FALSE          FALSE         FALSE             FALSE
[129,]   FALSE  FALSE          FALSE         FALSE             FALSE
[130,]   FALSE  FALSE          FALSE         FALSE             FALSE
[131,]   FALSE  FALSE          FALSE         FALSE             FALSE
[132,]   FALSE  FALSE          FALSE         FALSE             FALSE
[133,]   FALSE  FALSE          FALSE         FALSE             FALSE
[134,]   FALSE  FALSE          FALSE         FALSE             FALSE
[135,]   FALSE  FALSE          FALSE         FALSE             FALSE
[136,]   FALSE  FALSE          FALSE         FALSE             FALSE
[137,]   FALSE  FALSE          FALSE         FALSE             FALSE
[138,]   FALSE  FALSE          FALSE         FALSE             FALSE
[139,]   FALSE  FALSE          FALSE         FALSE             FALSE
[140,]   FALSE  FALSE          FALSE         FALSE             FALSE
[141,]   FALSE  FALSE          FALSE         FALSE             FALSE
[142,]   FALSE  FALSE          FALSE         FALSE             FALSE
[143,]   FALSE  FALSE          FALSE         FALSE             FALSE
[144,]   FALSE  FALSE          FALSE         FALSE             FALSE
[145,]   FALSE  FALSE          FALSE         FALSE             FALSE
[146,]   FALSE  FALSE          FALSE         FALSE             FALSE
[147,]   FALSE  FALSE          FALSE         FALSE             FALSE
[148,]   FALSE  FALSE          FALSE         FALSE             FALSE
[149,]   FALSE  FALSE          FALSE         FALSE             FALSE
[150,]   FALSE  FALSE          FALSE         FALSE             FALSE
[151,]   FALSE  FALSE          FALSE         FALSE             FALSE
[152,]   FALSE  FALSE          FALSE         FALSE             FALSE
[153,]   FALSE  FALSE          FALSE         FALSE             FALSE
[154,]   FALSE  FALSE          FALSE         FALSE             FALSE
[155,]   FALSE  FALSE          FALSE         FALSE             FALSE
[156,]   FALSE  FALSE          FALSE         FALSE             FALSE
[157,]   FALSE  FALSE          FALSE         FALSE             FALSE
[158,]   FALSE  FALSE          FALSE         FALSE             FALSE
[159,]   FALSE  FALSE          FALSE         FALSE             FALSE
[160,]   FALSE  FALSE          FALSE         FALSE             FALSE
[161,]   FALSE  FALSE          FALSE         FALSE             FALSE
[162,]   FALSE  FALSE          FALSE         FALSE             FALSE
[163,]   FALSE  FALSE          FALSE         FALSE             FALSE
[164,]   FALSE  FALSE          FALSE         FALSE             FALSE
[165,]   FALSE  FALSE          FALSE         FALSE             FALSE
[166,]   FALSE  FALSE          FALSE         FALSE             FALSE
[167,]   FALSE  FALSE          FALSE         FALSE             FALSE
[168,]   FALSE  FALSE          FALSE         FALSE             FALSE
[169,]   FALSE  FALSE          FALSE         FALSE             FALSE
[170,]   FALSE  FALSE          FALSE         FALSE             FALSE
[171,]   FALSE  FALSE          FALSE         FALSE             FALSE
[172,]   FALSE  FALSE          FALSE         FALSE             FALSE
[173,]   FALSE  FALSE          FALSE         FALSE             FALSE
[174,]   FALSE  FALSE          FALSE         FALSE             FALSE
[175,]   FALSE  FALSE          FALSE         FALSE             FALSE
[176,]   FALSE  FALSE          FALSE         FALSE             FALSE
[177,]   FALSE  FALSE          FALSE         FALSE             FALSE
[178,]   FALSE  FALSE          FALSE         FALSE             FALSE
[179,]   FALSE  FALSE          FALSE         FALSE             FALSE
[180,]   FALSE  FALSE          FALSE         FALSE             FALSE
[181,]   FALSE  FALSE          FALSE         FALSE             FALSE
[182,]   FALSE  FALSE          FALSE         FALSE             FALSE
[183,]   FALSE  FALSE          FALSE         FALSE             FALSE
[184,]   FALSE  FALSE          FALSE         FALSE             FALSE
[185,]   FALSE  FALSE          FALSE         FALSE             FALSE
[186,]   FALSE  FALSE          FALSE         FALSE             FALSE
[187,]   FALSE  FALSE          FALSE         FALSE             FALSE
[188,]   FALSE  FALSE          FALSE         FALSE             FALSE
[189,]   FALSE  FALSE          FALSE         FALSE             FALSE
[190,]   FALSE  FALSE          FALSE         FALSE             FALSE
[191,]   FALSE  FALSE          FALSE         FALSE             FALSE
[192,]   FALSE  FALSE          FALSE         FALSE             FALSE
[193,]   FALSE  FALSE          FALSE         FALSE             FALSE
[194,]   FALSE  FALSE          FALSE         FALSE             FALSE
[195,]   FALSE  FALSE          FALSE         FALSE             FALSE
[196,]   FALSE  FALSE          FALSE         FALSE             FALSE
[197,]   FALSE  FALSE          FALSE         FALSE             FALSE
[198,]   FALSE  FALSE          FALSE         FALSE             FALSE
[199,]   FALSE  FALSE          FALSE         FALSE             FALSE
[200,]   FALSE  FALSE          FALSE         FALSE             FALSE
[201,]   FALSE  FALSE          FALSE         FALSE             FALSE
[202,]   FALSE  FALSE          FALSE         FALSE             FALSE
[203,]   FALSE  FALSE          FALSE         FALSE             FALSE
[204,]   FALSE  FALSE          FALSE         FALSE             FALSE
[205,]   FALSE  FALSE          FALSE         FALSE             FALSE
[206,]   FALSE  FALSE          FALSE         FALSE             FALSE
[207,]   FALSE  FALSE          FALSE         FALSE             FALSE
[208,]   FALSE  FALSE          FALSE         FALSE             FALSE
[209,]   FALSE  FALSE          FALSE         FALSE             FALSE
[210,]   FALSE  FALSE          FALSE         FALSE             FALSE
[211,]   FALSE  FALSE          FALSE         FALSE             FALSE
[212,]   FALSE  FALSE          FALSE         FALSE             FALSE
[213,]   FALSE  FALSE          FALSE         FALSE             FALSE
[214,]   FALSE  FALSE          FALSE         FALSE             FALSE
[215,]   FALSE  FALSE          FALSE         FALSE             FALSE
[216,]   FALSE  FALSE          FALSE         FALSE             FALSE
[217,]   FALSE  FALSE          FALSE         FALSE             FALSE
[218,]   FALSE  FALSE          FALSE         FALSE             FALSE
[219,]   FALSE  FALSE          FALSE         FALSE             FALSE
[220,]   FALSE  FALSE          FALSE         FALSE             FALSE
[221,]   FALSE  FALSE          FALSE         FALSE             FALSE
[222,]   FALSE  FALSE          FALSE         FALSE             FALSE
[223,]   FALSE  FALSE          FALSE         FALSE             FALSE
[224,]   FALSE  FALSE          FALSE         FALSE             FALSE
[225,]   FALSE  FALSE          FALSE         FALSE             FALSE
[226,]   FALSE  FALSE          FALSE         FALSE             FALSE
[227,]   FALSE  FALSE          FALSE         FALSE             FALSE
[228,]   FALSE  FALSE          FALSE         FALSE             FALSE
[229,]   FALSE  FALSE          FALSE         FALSE             FALSE
[230,]   FALSE  FALSE          FALSE         FALSE             FALSE
[231,]   FALSE  FALSE          FALSE         FALSE             FALSE
[232,]   FALSE  FALSE          FALSE         FALSE             FALSE
[233,]   FALSE  FALSE          FALSE         FALSE             FALSE
[234,]   FALSE  FALSE          FALSE         FALSE             FALSE
[235,]   FALSE  FALSE          FALSE         FALSE             FALSE
[236,]   FALSE  FALSE          FALSE         FALSE             FALSE
[237,]   FALSE  FALSE          FALSE         FALSE             FALSE
[238,]   FALSE  FALSE          FALSE         FALSE             FALSE
[239,]   FALSE  FALSE          FALSE         FALSE             FALSE
[240,]   FALSE  FALSE          FALSE         FALSE             FALSE
[241,]   FALSE  FALSE          FALSE         FALSE             FALSE
[242,]   FALSE  FALSE          FALSE         FALSE             FALSE
[243,]   FALSE  FALSE          FALSE         FALSE             FALSE
[244,]   FALSE  FALSE          FALSE         FALSE             FALSE
[245,]   FALSE  FALSE          FALSE         FALSE             FALSE
[246,]   FALSE  FALSE          FALSE         FALSE             FALSE
[247,]   FALSE  FALSE          FALSE         FALSE             FALSE
[248,]   FALSE  FALSE          FALSE         FALSE             FALSE
[249,]   FALSE  FALSE          FALSE         FALSE             FALSE
[250,]   FALSE  FALSE          FALSE         FALSE             FALSE
[251,]   FALSE  FALSE          FALSE         FALSE             FALSE
[252,]   FALSE  FALSE          FALSE         FALSE             FALSE
[253,]   FALSE  FALSE          FALSE         FALSE             FALSE
[254,]   FALSE  FALSE          FALSE         FALSE             FALSE
[255,]   FALSE  FALSE          FALSE         FALSE             FALSE
[256,]   FALSE  FALSE          FALSE         FALSE             FALSE
[257,]   FALSE  FALSE          FALSE         FALSE             FALSE
[258,]   FALSE  FALSE          FALSE         FALSE             FALSE
[259,]   FALSE  FALSE          FALSE         FALSE             FALSE
[260,]   FALSE  FALSE          FALSE         FALSE             FALSE
[261,]   FALSE  FALSE          FALSE         FALSE             FALSE
[262,]   FALSE  FALSE          FALSE         FALSE             FALSE
[263,]   FALSE  FALSE          FALSE         FALSE             FALSE
[264,]   FALSE  FALSE          FALSE         FALSE             FALSE
[265,]   FALSE  FALSE          FALSE         FALSE             FALSE
[266,]   FALSE  FALSE          FALSE         FALSE             FALSE
[267,]   FALSE  FALSE          FALSE         FALSE             FALSE
[268,]   FALSE  FALSE          FALSE         FALSE             FALSE
[269,]   FALSE  FALSE          FALSE         FALSE             FALSE
[270,]   FALSE  FALSE          FALSE         FALSE             FALSE
[271,]   FALSE  FALSE          FALSE         FALSE             FALSE
[272,]   FALSE  FALSE           TRUE          TRUE              TRUE
[273,]   FALSE  FALSE          FALSE         FALSE             FALSE
[274,]   FALSE  FALSE          FALSE         FALSE             FALSE
[275,]   FALSE  FALSE          FALSE         FALSE             FALSE
[276,]   FALSE  FALSE          FALSE         FALSE             FALSE
[277,]   FALSE  FALSE          FALSE         FALSE             FALSE
[278,]   FALSE  FALSE          FALSE         FALSE             FALSE
[279,]   FALSE  FALSE          FALSE         FALSE             FALSE
[280,]   FALSE  FALSE          FALSE         FALSE             FALSE
[281,]   FALSE  FALSE          FALSE         FALSE             FALSE
[282,]   FALSE  FALSE          FALSE         FALSE             FALSE
[283,]   FALSE  FALSE          FALSE         FALSE             FALSE
[284,]   FALSE  FALSE          FALSE         FALSE             FALSE
[285,]   FALSE  FALSE          FALSE         FALSE             FALSE
[286,]   FALSE  FALSE          FALSE         FALSE             FALSE
[287,]   FALSE  FALSE          FALSE         FALSE             FALSE
[288,]   FALSE  FALSE          FALSE         FALSE             FALSE
[289,]   FALSE  FALSE          FALSE         FALSE             FALSE
[290,]   FALSE  FALSE          FALSE         FALSE             FALSE
[291,]   FALSE  FALSE          FALSE         FALSE             FALSE
[292,]   FALSE  FALSE          FALSE         FALSE             FALSE
[293,]   FALSE  FALSE          FALSE         FALSE             FALSE
[294,]   FALSE  FALSE          FALSE         FALSE             FALSE
[295,]   FALSE  FALSE          FALSE         FALSE             FALSE
[296,]   FALSE  FALSE          FALSE         FALSE             FALSE
[297,]   FALSE  FALSE          FALSE         FALSE             FALSE
[298,]   FALSE  FALSE          FALSE         FALSE             FALSE
[299,]   FALSE  FALSE          FALSE         FALSE             FALSE
[300,]   FALSE  FALSE          FALSE         FALSE             FALSE
[301,]   FALSE  FALSE          FALSE         FALSE             FALSE
[302,]   FALSE  FALSE          FALSE         FALSE             FALSE
[303,]   FALSE  FALSE          FALSE         FALSE             FALSE
[304,]   FALSE  FALSE          FALSE         FALSE             FALSE
[305,]   FALSE  FALSE          FALSE         FALSE             FALSE
[306,]   FALSE  FALSE          FALSE         FALSE             FALSE
[307,]   FALSE  FALSE          FALSE         FALSE             FALSE
[308,]   FALSE  FALSE          FALSE         FALSE             FALSE
[309,]   FALSE  FALSE          FALSE         FALSE             FALSE
[310,]   FALSE  FALSE          FALSE         FALSE             FALSE
[311,]   FALSE  FALSE          FALSE         FALSE             FALSE
[312,]   FALSE  FALSE          FALSE         FALSE             FALSE
[313,]   FALSE  FALSE          FALSE         FALSE             FALSE
[314,]   FALSE  FALSE          FALSE         FALSE             FALSE
[315,]   FALSE  FALSE          FALSE         FALSE             FALSE
[316,]   FALSE  FALSE          FALSE         FALSE             FALSE
[317,]   FALSE  FALSE          FALSE         FALSE             FALSE
[318,]   FALSE  FALSE          FALSE         FALSE             FALSE
[319,]   FALSE  FALSE          FALSE         FALSE             FALSE
[320,]   FALSE  FALSE          FALSE         FALSE             FALSE
[321,]   FALSE  FALSE          FALSE         FALSE             FALSE
[322,]   FALSE  FALSE          FALSE         FALSE             FALSE
[323,]   FALSE  FALSE          FALSE         FALSE             FALSE
[324,]   FALSE  FALSE          FALSE         FALSE             FALSE
[325,]   FALSE  FALSE          FALSE         FALSE             FALSE
[326,]   FALSE  FALSE          FALSE         FALSE             FALSE
[327,]   FALSE  FALSE          FALSE         FALSE             FALSE
[328,]   FALSE  FALSE          FALSE         FALSE             FALSE
[329,]   FALSE  FALSE          FALSE         FALSE             FALSE
[330,]   FALSE  FALSE          FALSE         FALSE             FALSE
[331,]   FALSE  FALSE          FALSE         FALSE             FALSE
[332,]   FALSE  FALSE          FALSE         FALSE             FALSE
[333,]   FALSE  FALSE          FALSE         FALSE             FALSE
[334,]   FALSE  FALSE          FALSE         FALSE             FALSE
[335,]   FALSE  FALSE          FALSE         FALSE             FALSE
[336,]   FALSE  FALSE          FALSE         FALSE             FALSE
[337,]   FALSE  FALSE          FALSE         FALSE             FALSE
[338,]   FALSE  FALSE          FALSE         FALSE             FALSE
[339,]   FALSE  FALSE          FALSE         FALSE             FALSE
[340,]   FALSE  FALSE          FALSE         FALSE             FALSE
[341,]   FALSE  FALSE          FALSE         FALSE             FALSE
[342,]   FALSE  FALSE          FALSE         FALSE             FALSE
[343,]   FALSE  FALSE          FALSE         FALSE             FALSE
[344,]   FALSE  FALSE          FALSE         FALSE             FALSE
       body_mass_g   sex  year
  [1,]       FALSE FALSE FALSE
  [2,]       FALSE FALSE FALSE
  [3,]       FALSE FALSE FALSE
  [4,]        TRUE  TRUE FALSE
  [5,]       FALSE FALSE FALSE
  [6,]       FALSE FALSE FALSE
  [7,]       FALSE FALSE FALSE
  [8,]       FALSE FALSE FALSE
  [9,]       FALSE  TRUE FALSE
 [10,]       FALSE  TRUE FALSE
 [11,]       FALSE  TRUE FALSE
 [12,]       FALSE  TRUE FALSE
 [13,]       FALSE FALSE FALSE
 [14,]       FALSE FALSE FALSE
 [15,]       FALSE FALSE FALSE
 [16,]       FALSE FALSE FALSE
 [17,]       FALSE FALSE FALSE
 [18,]       FALSE FALSE FALSE
 [19,]       FALSE FALSE FALSE
 [20,]       FALSE FALSE FALSE
 [21,]       FALSE FALSE FALSE
 [22,]       FALSE FALSE FALSE
 [23,]       FALSE FALSE FALSE
 [24,]       FALSE FALSE FALSE
 [25,]       FALSE FALSE FALSE
 [26,]       FALSE FALSE FALSE
 [27,]       FALSE FALSE FALSE
 [28,]       FALSE FALSE FALSE
 [29,]       FALSE FALSE FALSE
 [30,]       FALSE FALSE FALSE
 [31,]       FALSE FALSE FALSE
 [32,]       FALSE FALSE FALSE
 [33,]       FALSE FALSE FALSE
 [34,]       FALSE FALSE FALSE
 [35,]       FALSE FALSE FALSE
 [36,]       FALSE FALSE FALSE
 [37,]       FALSE FALSE FALSE
 [38,]       FALSE FALSE FALSE
 [39,]       FALSE FALSE FALSE
 [40,]       FALSE FALSE FALSE
 [41,]       FALSE FALSE FALSE
 [42,]       FALSE FALSE FALSE
 [43,]       FALSE FALSE FALSE
 [44,]       FALSE FALSE FALSE
 [45,]       FALSE FALSE FALSE
 [46,]       FALSE FALSE FALSE
 [47,]       FALSE FALSE FALSE
 [48,]       FALSE  TRUE FALSE
 [49,]       FALSE FALSE FALSE
 [50,]       FALSE FALSE FALSE
 [51,]       FALSE FALSE FALSE
 [52,]       FALSE FALSE FALSE
 [53,]       FALSE FALSE FALSE
 [54,]       FALSE FALSE FALSE
 [55,]       FALSE FALSE FALSE
 [56,]       FALSE FALSE FALSE
 [57,]       FALSE FALSE FALSE
 [58,]       FALSE FALSE FALSE
 [59,]       FALSE FALSE FALSE
 [60,]       FALSE FALSE FALSE
 [61,]       FALSE FALSE FALSE
 [62,]       FALSE FALSE FALSE
 [63,]       FALSE FALSE FALSE
 [64,]       FALSE FALSE FALSE
 [65,]       FALSE FALSE FALSE
 [66,]       FALSE FALSE FALSE
 [67,]       FALSE FALSE FALSE
 [68,]       FALSE FALSE FALSE
 [69,]       FALSE FALSE FALSE
 [70,]       FALSE FALSE FALSE
 [71,]       FALSE FALSE FALSE
 [72,]       FALSE FALSE FALSE
 [73,]       FALSE FALSE FALSE
 [74,]       FALSE FALSE FALSE
 [75,]       FALSE FALSE FALSE
 [76,]       FALSE FALSE FALSE
 [77,]       FALSE FALSE FALSE
 [78,]       FALSE FALSE FALSE
 [79,]       FALSE FALSE FALSE
 [80,]       FALSE FALSE FALSE
 [81,]       FALSE FALSE FALSE
 [82,]       FALSE FALSE FALSE
 [83,]       FALSE FALSE FALSE
 [84,]       FALSE FALSE FALSE
 [85,]       FALSE FALSE FALSE
 [86,]       FALSE FALSE FALSE
 [87,]       FALSE FALSE FALSE
 [88,]       FALSE FALSE FALSE
 [89,]       FALSE FALSE FALSE
 [90,]       FALSE FALSE FALSE
 [91,]       FALSE FALSE FALSE
 [92,]       FALSE FALSE FALSE
 [93,]       FALSE FALSE FALSE
 [94,]       FALSE FALSE FALSE
 [95,]       FALSE FALSE FALSE
 [96,]       FALSE FALSE FALSE
 [97,]       FALSE FALSE FALSE
 [98,]       FALSE FALSE FALSE
 [99,]       FALSE FALSE FALSE
[100,]       FALSE FALSE FALSE
[101,]       FALSE FALSE FALSE
[102,]       FALSE FALSE FALSE
[103,]       FALSE FALSE FALSE
[104,]       FALSE FALSE FALSE
[105,]       FALSE FALSE FALSE
[106,]       FALSE FALSE FALSE
[107,]       FALSE FALSE FALSE
[108,]       FALSE FALSE FALSE
[109,]       FALSE FALSE FALSE
[110,]       FALSE FALSE FALSE
[111,]       FALSE FALSE FALSE
[112,]       FALSE FALSE FALSE
[113,]       FALSE FALSE FALSE
[114,]       FALSE FALSE FALSE
[115,]       FALSE FALSE FALSE
[116,]       FALSE FALSE FALSE
[117,]       FALSE FALSE FALSE
[118,]       FALSE FALSE FALSE
[119,]       FALSE FALSE FALSE
[120,]       FALSE FALSE FALSE
[121,]       FALSE FALSE FALSE
[122,]       FALSE FALSE FALSE
[123,]       FALSE FALSE FALSE
[124,]       FALSE FALSE FALSE
[125,]       FALSE FALSE FALSE
[126,]       FALSE FALSE FALSE
[127,]       FALSE FALSE FALSE
[128,]       FALSE FALSE FALSE
[129,]       FALSE FALSE FALSE
[130,]       FALSE FALSE FALSE
[131,]       FALSE FALSE FALSE
[132,]       FALSE FALSE FALSE
[133,]       FALSE FALSE FALSE
[134,]       FALSE FALSE FALSE
[135,]       FALSE FALSE FALSE
[136,]       FALSE FALSE FALSE
[137,]       FALSE FALSE FALSE
[138,]       FALSE FALSE FALSE
[139,]       FALSE FALSE FALSE
[140,]       FALSE FALSE FALSE
[141,]       FALSE FALSE FALSE
[142,]       FALSE FALSE FALSE
[143,]       FALSE FALSE FALSE
[144,]       FALSE FALSE FALSE
[145,]       FALSE FALSE FALSE
[146,]       FALSE FALSE FALSE
[147,]       FALSE FALSE FALSE
[148,]       FALSE FALSE FALSE
[149,]       FALSE FALSE FALSE
[150,]       FALSE FALSE FALSE
[151,]       FALSE FALSE FALSE
[152,]       FALSE FALSE FALSE
[153,]       FALSE FALSE FALSE
[154,]       FALSE FALSE FALSE
[155,]       FALSE FALSE FALSE
[156,]       FALSE FALSE FALSE
[157,]       FALSE FALSE FALSE
[158,]       FALSE FALSE FALSE
[159,]       FALSE FALSE FALSE
[160,]       FALSE FALSE FALSE
[161,]       FALSE FALSE FALSE
[162,]       FALSE FALSE FALSE
[163,]       FALSE FALSE FALSE
[164,]       FALSE FALSE FALSE
[165,]       FALSE FALSE FALSE
[166,]       FALSE FALSE FALSE
[167,]       FALSE FALSE FALSE
[168,]       FALSE FALSE FALSE
[169,]       FALSE FALSE FALSE
[170,]       FALSE FALSE FALSE
[171,]       FALSE FALSE FALSE
[172,]       FALSE FALSE FALSE
[173,]       FALSE FALSE FALSE
[174,]       FALSE FALSE FALSE
[175,]       FALSE FALSE FALSE
[176,]       FALSE FALSE FALSE
[177,]       FALSE FALSE FALSE
[178,]       FALSE FALSE FALSE
[179,]       FALSE  TRUE FALSE
[180,]       FALSE FALSE FALSE
[181,]       FALSE FALSE FALSE
[182,]       FALSE FALSE FALSE
[183,]       FALSE FALSE FALSE
[184,]       FALSE FALSE FALSE
[185,]       FALSE FALSE FALSE
[186,]       FALSE FALSE FALSE
[187,]       FALSE FALSE FALSE
[188,]       FALSE FALSE FALSE
[189,]       FALSE FALSE FALSE
[190,]       FALSE FALSE FALSE
[191,]       FALSE FALSE FALSE
[192,]       FALSE FALSE FALSE
[193,]       FALSE FALSE FALSE
[194,]       FALSE FALSE FALSE
[195,]       FALSE FALSE FALSE
[196,]       FALSE FALSE FALSE
[197,]       FALSE FALSE FALSE
[198,]       FALSE FALSE FALSE
[199,]       FALSE FALSE FALSE
[200,]       FALSE FALSE FALSE
[201,]       FALSE FALSE FALSE
[202,]       FALSE FALSE FALSE
[203,]       FALSE FALSE FALSE
[204,]       FALSE FALSE FALSE
[205,]       FALSE FALSE FALSE
[206,]       FALSE FALSE FALSE
[207,]       FALSE FALSE FALSE
[208,]       FALSE FALSE FALSE
[209,]       FALSE FALSE FALSE
[210,]       FALSE FALSE FALSE
[211,]       FALSE FALSE FALSE
[212,]       FALSE FALSE FALSE
[213,]       FALSE FALSE FALSE
[214,]       FALSE FALSE FALSE
[215,]       FALSE FALSE FALSE
[216,]       FALSE FALSE FALSE
[217,]       FALSE FALSE FALSE
[218,]       FALSE FALSE FALSE
[219,]       FALSE  TRUE FALSE
[220,]       FALSE FALSE FALSE
[221,]       FALSE FALSE FALSE
[222,]       FALSE FALSE FALSE
[223,]       FALSE FALSE FALSE
[224,]       FALSE FALSE FALSE
[225,]       FALSE FALSE FALSE
[226,]       FALSE FALSE FALSE
[227,]       FALSE FALSE FALSE
[228,]       FALSE FALSE FALSE
[229,]       FALSE FALSE FALSE
[230,]       FALSE FALSE FALSE
[231,]       FALSE FALSE FALSE
[232,]       FALSE FALSE FALSE
[233,]       FALSE FALSE FALSE
[234,]       FALSE FALSE FALSE
[235,]       FALSE FALSE FALSE
[236,]       FALSE FALSE FALSE
[237,]       FALSE FALSE FALSE
[238,]       FALSE FALSE FALSE
[239,]       FALSE FALSE FALSE
[240,]       FALSE FALSE FALSE
[241,]       FALSE FALSE FALSE
[242,]       FALSE FALSE FALSE
[243,]       FALSE FALSE FALSE
[244,]       FALSE FALSE FALSE
[245,]       FALSE FALSE FALSE
[246,]       FALSE FALSE FALSE
[247,]       FALSE FALSE FALSE
[248,]       FALSE FALSE FALSE
[249,]       FALSE FALSE FALSE
[250,]       FALSE FALSE FALSE
[251,]       FALSE FALSE FALSE
[252,]       FALSE FALSE FALSE
[253,]       FALSE FALSE FALSE
[254,]       FALSE FALSE FALSE
[255,]       FALSE FALSE FALSE
[256,]       FALSE FALSE FALSE
[257,]       FALSE  TRUE FALSE
[258,]       FALSE FALSE FALSE
[259,]       FALSE FALSE FALSE
[260,]       FALSE FALSE FALSE
[261,]       FALSE FALSE FALSE
[262,]       FALSE FALSE FALSE
[263,]       FALSE FALSE FALSE
[264,]       FALSE FALSE FALSE
[265,]       FALSE FALSE FALSE
[266,]       FALSE FALSE FALSE
[267,]       FALSE FALSE FALSE
[268,]       FALSE FALSE FALSE
[269,]       FALSE  TRUE FALSE
[270,]       FALSE FALSE FALSE
[271,]       FALSE FALSE FALSE
[272,]        TRUE  TRUE FALSE
[273,]       FALSE FALSE FALSE
[274,]       FALSE FALSE FALSE
[275,]       FALSE FALSE FALSE
[276,]       FALSE FALSE FALSE
[277,]       FALSE FALSE FALSE
[278,]       FALSE FALSE FALSE
[279,]       FALSE FALSE FALSE
[280,]       FALSE FALSE FALSE
[281,]       FALSE FALSE FALSE
[282,]       FALSE FALSE FALSE
[283,]       FALSE FALSE FALSE
[284,]       FALSE FALSE FALSE
[285,]       FALSE FALSE FALSE
[286,]       FALSE FALSE FALSE
[287,]       FALSE FALSE FALSE
[288,]       FALSE FALSE FALSE
[289,]       FALSE FALSE FALSE
[290,]       FALSE FALSE FALSE
[291,]       FALSE FALSE FALSE
[292,]       FALSE FALSE FALSE
[293,]       FALSE FALSE FALSE
[294,]       FALSE FALSE FALSE
[295,]       FALSE FALSE FALSE
[296,]       FALSE FALSE FALSE
[297,]       FALSE FALSE FALSE
[298,]       FALSE FALSE FALSE
[299,]       FALSE FALSE FALSE
[300,]       FALSE FALSE FALSE
[301,]       FALSE FALSE FALSE
[302,]       FALSE FALSE FALSE
[303,]       FALSE FALSE FALSE
[304,]       FALSE FALSE FALSE
[305,]       FALSE FALSE FALSE
[306,]       FALSE FALSE FALSE
[307,]       FALSE FALSE FALSE
[308,]       FALSE FALSE FALSE
[309,]       FALSE FALSE FALSE
[310,]       FALSE FALSE FALSE
[311,]       FALSE FALSE FALSE
[312,]       FALSE FALSE FALSE
[313,]       FALSE FALSE FALSE
[314,]       FALSE FALSE FALSE
[315,]       FALSE FALSE FALSE
[316,]       FALSE FALSE FALSE
[317,]       FALSE FALSE FALSE
[318,]       FALSE FALSE FALSE
[319,]       FALSE FALSE FALSE
[320,]       FALSE FALSE FALSE
[321,]       FALSE FALSE FALSE
[322,]       FALSE FALSE FALSE
[323,]       FALSE FALSE FALSE
[324,]       FALSE FALSE FALSE
[325,]       FALSE FALSE FALSE
[326,]       FALSE FALSE FALSE
[327,]       FALSE FALSE FALSE
[328,]       FALSE FALSE FALSE
[329,]       FALSE FALSE FALSE
[330,]       FALSE FALSE FALSE
[331,]       FALSE FALSE FALSE
[332,]       FALSE FALSE FALSE
[333,]       FALSE FALSE FALSE
[334,]       FALSE FALSE FALSE
[335,]       FALSE FALSE FALSE
[336,]       FALSE FALSE FALSE
[337,]       FALSE FALSE FALSE
[338,]       FALSE FALSE FALSE
[339,]       FALSE FALSE FALSE
[340,]       FALSE FALSE FALSE
[341,]       FALSE FALSE FALSE
[342,]       FALSE FALSE FALSE
[343,]       FALSE FALSE FALSE
[344,]       FALSE FALSE FALSE

Response indicator

naniar::vis_miss(penguins)

Missingness rate

colSums(is.na(penguins))
          species            island    bill_length_mm     bill_depth_mm 
                0                 0                 2                 2 
flipper_length_mm       body_mass_g               sex              year 
                2                 2                11                 0 

Missingness rate

VIM::aggr(penguins, numbers = TRUE, prop = FALSE)

Missing data pattern

md.pattern(penguins)
    species island year bill_length_mm bill_depth_mm flipper_length_mm
333       1      1    1              1             1                 1
9         1      1    1              1             1                 1
2         1      1    1              0             0                 0
          0      0    0              2             2                 2
    body_mass_g sex   
333           1   1  0
9             1   0  1
2             0   0  5
              2  11 19

Missing data pattern

plot_pattern(penguins)

Imputation workflow

Imputation models

meth <- make.method(penguins)
pred <- make.predictorMatrix(penguins)
plot_pred(pred, method = meth, square = FALSE)

Imputation models

pred <- quickpred(penguins, mincor = 0.4)
plot_pred(pred, method = meth, square = FALSE)

Correlation

plot_corr(penguins, square = FALSE)

Plot \(Y\) by auxiliary variable

ggmice(penguins, aes(sex, flipper_length_mm)) +
  geom_point(size = 2)

Plot \(Y\) by auxiliary variable

ggmice(penguins, aes(x = sex, y = flipper_length_mm)) +
  geom_jitter(height = 0, width = 0.25) +
  geom_boxplot(alpha = 0.1)

Plot \(Y\) by missingness indicator

ggmice(penguins, aes(flipper_length_mm)) +
  geom_histogram(fill = "white") +
  facet_grid(factor(
  is.na(sex), 
  levels = c(TRUE, FALSE), 
  labels = c("missing sex", "observed sex")
  ) ~ ., scales = "free_y")

Plot \(Y\) by auxiliary variables

ggmice(penguins, aes(flipper_length_mm)) +
  geom_histogram(fill = "white") +
  facet_grid(factor(
  is.na(sex), 
  levels = c(TRUE, FALSE), 
  labels = c("missing sex", "observed sex")
  ) ~ species)

Adjust imputation models

meth["flipper_length_mm"] <- "norm"
pred["flipper_length_mm", c("species", "sex")] <- 1
pred["sex", "flipper_length_mm"] <- 1
plot_pred(pred, method = meth, square = FALSE)

Impute

imp <- mice(
  penguins, 
  pred = pred, 
  method = meth, 
  m = 10)

 iter imp variable
  1   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  1   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  2   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  3   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  4   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  5   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex

Trace plot

plot_trace(imp)

Add iterations

imp <- mice.mids(imp, maxit = 25)

 iter imp variable
  6   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  6   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  7   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  8   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  9   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  10   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  11   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  12   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  13   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  14   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  15   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  16   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  17   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  18   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  19   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  20   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  21   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  22   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  23   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  24   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  25   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  26   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  27   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  28   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  29   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   1  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   2  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   3  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   4  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   5  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   6  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   7  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   8  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   9  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex
  30   10  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex

Trace plot after iterating

plot_trace(imp)

Stripplot of the outcome

ggmice(imp, aes(x = .imp, y = flipper_length_mm)) +
  geom_point() +
  labs(x = "Imputation number")

Distribution of the outcome

ggmice(imp, aes(x = flipper_length_mm, group = .imp)) +
  geom_density()

Stripplot of predictor variable

ggmice(imp, aes(x = .imp, y = body_mass_g)) +
  geom_point() +
  labs(x = "Imputation number")

Stripplot of auxiliary variable

ggmice(imp, aes(x = .imp, y = sex)) +
  geom_jitter(height = 0.1, width = 0.05) +
  labs(x = "Imputation number")

Analysis results

Research question after imputation

ggmice(imp, aes(x = body_mass_g, y = flipper_length_mm)) +
  geom_point()

Analyze imputated data

fit <- with(imp, lm(flipper_length_mm ~ body_mass_g))
fit$analyses
[[1]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.9891       0.0152  


[[2]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.5145       0.0153  


[[3]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.6768       0.0153  


[[4]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.6814       0.0153  


[[5]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.7793       0.0153  


[[6]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.7109       0.0153  


[[7]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.4643       0.0153  


[[8]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.7935       0.0153  


[[9]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   137.1453       0.0152  


[[10]]

Call:
lm(formula = flipper_length_mm ~ body_mass_g)

Coefficients:
(Intercept)  body_mass_g  
   136.8018       0.0153  

Pooled results

Pooling analysis results

est <- pool(fit) 
est$pooled
term m estimate ubar b t dfcom df riv lambda fmi
(Intercept) 10 136.756 3.95 0.041 4 342 335 0.011 0.011 0.017
body_mass_g 10 0.015 0.00 0.000 0 342 334 0.012 0.012 0.018

Flexible approach

fit <- purrr::map(
  complete(imp, "all"), 
  ~lm(flipper_length_mm ~ body_mass_g, data = .x)
  )
est <- pool(fit) 
est$pooled
term m estimate ubar b t dfcom df riv lambda fmi
(Intercept) 10 136.756 3.95 0.041 4 342 335 0.011 0.011 0.017
body_mass_g 10 0.015 0.00 0.000 0 342 334 0.012 0.012 0.018

Take aways

  • Missing data cannot be ignored.
  • To obtain valid inferences, you should investigate the missingness mechanism.
  • Multiple imputation allows you to ‘correct for’ data-dependent missingness.

Take aways

  • The R package mice makes imputation easy…
    • … but specifying imputation models requires careful investigation,
    • … and the imputations cannot be trusted if the algorithm has not converged.
  • After imputation, you can analyze the data as if it were complete, and pool the estimates to obtain valid inferences.

Resources

Thank you!

My personal website (incl. this presentation): hanneoberman.github.io