na.descript: Descriptive Statistics for Missing Data in Single-Level,...

View source: R/na.descript.R

na.descriptR Documentation

Descriptive Statistics for Missing Data in Single-Level, Two-Level and Three-Level Data

Description

This function computes descriptive statistics for missing data in single-level, two-level, and three-level data, e.g. number of incomplete cases, number of missing values, and summary statistics for the number of missing values across all variables.

Usage

na.descript(..., data = NULL, cluster = NULL,  table = FALSE, digits = 2,
            as.na = NULL, write = NULL, append = TRUE, check = TRUE,
            output = TRUE)

Arguments

...

a matrix or data frame with incomplete data, where missing values are coded as NA. Alternatively, an expression indicating the variable names in data e.g., na.descript(x1, x2, x3, data = dat). Note that the operators ., +, -, ~, :, ::, and ! can also be used to select variables, see 'Details' in the df.subset function.

data

a data frame when specifying one or more variables in the argument .... Note that the argument is NULL when specifying a matrix or data frame for the argument ....

cluster

a character string indicating the name of the cluster variable in ... or data for two-level data, a character vector indicating the names of the cluster variables in ... for three-level data, or a vector or data frame representing the nested grouping structure (i.e., group or cluster variables). Alternatively, a character string or character vector indicating the variable name(s) of the cluster variable(s) in data. Note that the cluster variable at Level 3 come first in a three-level model, i.e., cluster = c("level3", "level2").

table

logical: if TRUE, a frequency table with number of observed values ("nObs"), percent of observed values ("pObs"), number of missing values ("nNA"), and percent of missing values ("pNA") is printed for each variable on the console.

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 ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

data

data frame used for the current analysis

args

specification of function arguments

result

list with results

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

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

van Buuren, S. (2018). Flexible imputation of missing data (2nd ed.). Chapman & Hall.

See Also

write.result, as.na, na.as, na.auxiliary, na.coverage, na.indicator, na.pattern, na.prop, na.test

Examples

#----------------------------------------------------------------------------
# Single-Level Data

# Example 1a: Descriptive statistics for missing data
na.descript(airquality)

# Example 1b: Alternative specification using the 'data' argument
na.descript(., data = airquality)

# Example 2: Descriptive statistics for missing data, print results with 3 digits
na.descript(airquality, digits = 3)

# Example 3: Descriptive statistics for missing data with frequency table
na.descript(airquality, table = TRUE)

#----------------------------------------------------------------------------
# Two-Level Data

# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")

# Example 4: escriptive statistics for missing data
na.descript(Demo.twolevel, cluster = "cluster")

#----------------------------------------------------------------------------
# Three-Level Data

# Create arbitrary three-level data
Demo.threelevel <- data.frame(Demo.twolevel, cluster2 = Demo.twolevel$cluster,
                                             cluster3 = rep(1:10, each = 250))

# Example 5: Descriptive statistics for missing data
na.descript(Demo.threelevel, cluster = c("cluster3", "cluster2"))

#----------------------------------------------------------------------------
# Write Results

## Not run: 
# Example 6a: Write Results into a text file
na.descript(airquality, table = TRUE, write = "NA_Descriptives.txt")

# Example 6b: Write Results into a Excel file
na.descript(airquality, table = TRUE, write = "NA_Descriptives.xlsx")

result <- na.descript(airquality, table = TRUE, output = FALSE)
write.result(result, "NA_Descriptives.xlsx")

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to na.descript in misty...