na.pattern | R Documentation |
This function computes a summary of missing data patterns, i.e., number ( cases with a specific missing data pattern and plots the missing data patterns.
na.pattern(..., data = NULL, order = FALSE, n.pattern = NULL, plot = FALSE,
square = TRUE, rotate = FALSE, fill.col = c("#B61A51B3", "#006CC2B3"),
alpha = 0.6, plot.margin = c(4, 16, 0, 4),
legend.box.margin = c(-8, 6, 6, 6), legend.key.size = 12,
legend.text.size = 9, saveplot = FALSE, file = "NA_Patternt.pdf",
width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 600,
digits = 2, as.na = NULL, write = NULL, append = TRUE, check = TRUE,
output = TRUE)
... |
a matrix or data frame with incomplete data, where missing
values are coded as |
data |
a data frame when specifying one or more variables in the
argument |
order |
logical: if |
n.pattern |
an integer value indicating the minimum number of cases sharing
a missing data pattern to be included in the result table and the plot, e.g., specifying
|
plot |
logical: if |
square |
logical: if |
rotate |
logical: if |
fill.col |
a character string indicating the color for the |
alpha |
a numeric value between 0 and 1 for the |
plot.margin |
a numeric vector indicating the |
legend.box.margin |
a numeric vector indicating the |
legend.key.size |
a numeric value indicating the |
legend.text.size |
a numeric value indicating the |
saveplot |
logical: if |
file |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
units |
a character string indicating the |
dpi |
a numeric value indicating the |
digits |
an integer value indicating the number of decimal places to be used for displaying percentages. |
as.na |
a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis. |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
list with data frames, i.e., |
args |
specification of function arguments |
result |
result table |
plot |
ggplot2 object for plotting the results |
pattern |
a numeric vector indicating the missing data pattern for each case |
The code for plotting missing data patterns is based on the plot_pattern
function in the ggmice package by Hanne Oberman.
Takuya Yanagida takuya.yanagida@univie.ac.at
Enders, C. K. (2010). Applied missing data analysis. Guilford Press.
Graham, J. W. (2009). Missing data analysis: Making it work in the real world. Annual Review of Psychology, 60, 549-576. https://doi.org/10.1146/annurev.psych.58.110405.085530
Oberman, H. (2023). ggmice: Visualizations for 'mice' with 'ggplot2'. R package version 0.1.0. https://doi.org/10.32614/CRAN.package.ggmice
van Buuren, S. (2018). Flexible imputation of missing data (2nd ed.). Chapman & Hall.
write.result
, as.na
, na.as
,
na.auxiliary
, na.coverage
, na.descript
,
na.indicator
, na.prop
, na.test
## Not run:
# Example 1a: Compute a summary of missing data patterns
dat.pattern <- na.pattern(airquality)
# Example 1b: Alternative specification using the 'data' argument
dat.pattern <- na.pattern(., data = airquality)
# Example 2a: Compute and plot a summary of missing data patterns
na.pattern(airquality, plot = TRUE)
# Example 2b: Plot missing data patterns with at least 3 cases
na.pattern(airquality, plot = TRUE, n.pattern = 3)
# Example 3: Vector of missing data pattern for each case
dat.pattern$pattern
# Data frame without cases with missing data pattern 2 and 4
airquality[!dat.pattern$pattern
# Example 4a: Write Results into a text file
result <- na.pattern(airquality, write = "NA_Pattern.xlsx")
# Example 4b: Write Results into a Excel file
result <- na.pattern(airquality, write = "NA_Pattern.xlsx")
result <- 4c.pattern(dat, output = FALSE)
write.result(result, "NA_Pattern.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.