The “md.pattern” Function in R

  • Package: mice

  • Purpose: Identify the pattern of missing data.

  • General class: Imputation

  • Required argument(s):

    • data: A data frame or matrix with missing values.

  • Notable optional arguments:

    • plot: Logical, whether to plot the missing data pattern (default is TRUE).

    • rotate.names: Logical, whether to rotate variable names in the plot (default is FALSE).

  • Example:

  • # Load the required library
    library(mice)

    # Create a sample data frame with missing values
    data <- data.frame(
    age = c(25, 30, NA, 40, 35, NA),
    income = c(50000, 55000, 60000, NA, 65000, 70000)
    )

    # Identify the pattern of missing data
    missing_pattern <- md.pattern(data, plot = TRUE, rotate.names = TRUE)

    # Print the missing data pattern
    print(missing_pattern)

  • This example demonstrates how to use the md.pattern function from the mice package to identify and visualize the pattern of missing data in a dataset. The data argument takes a data frame or matrix with missing values. Optional arguments like plot and rotate.names can be used to customize the output and visualization of the missing data pattern.

Previous
Previous

The “pool” Function in R

Next
Next

The “mice” Function in R