knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = TRUE,
  error = TRUE
)

Missing data

## Load libraries
library(here)
library(dplyr)
library(ggplot2)
library(Hmisc)
library(naniar) ## for missing data 
library(gt)
library(kableExtra)
library(DT)
load(here::here("data", "a_crash2.rda"))

Per variable missingness

Number and percentage of missing.

a_crash2 %>%
  select(-time2death,-ddeath, -entryid, -trandomised, -earlydeath) %>%
  miss_var_summary() %>%
  gt::gt() %>%
    gt::cols_label(
    variable = md("**Variable**"),
    n_miss = md("**Missing (count)**"),
    pct_miss = md("**Missing (%)**")
  ) %>%
  gt::fmt_number(
    columns = c(pct_miss),
    decimals = 2
  )

Display

a_crash2 %>%
  select(-time2death,-ddeath, -entryid, -trandomised, -earlydeath) %>%
  gg_miss_var(show_pct = TRUE) +
  theme_minimal(base_size = 12) +
  ggtitle("Number of missing observations per variable")

Missingness patterns over variables

Each row is a patient and each column is a measurement. Black indicates a missing observation.

a_crash2 %>%
  select(-time2death,-ddeath, -entryid, -trandomised, -earlydeath) %>%
  naniar::vis_miss(sort_miss = TRUE, show_perc_col = TRUE) +
  theme_minimal(base_size = 12) +
  ggtitle("Number of missing observations per variable")

Distribution of missing values per patients.

a_crash2 %>%
  select(-time2death,-ddeath, -entryid, -trandomised, -earlydeath) %>%
  gg_miss_case()

Relationship of missing values per patient per observation.

a_crash2 %>%
  select(-time2death,-ddeath, -entryid, -trandomised, -earlydeath) %>%
  gg_miss_upset()

(In)complete cases

This section presents patients with a least one missing value. First we list out patients with at least one missing value in a filterable table.

cc <-
  a_crash2 %>%  
  select(-time2death,-ddeath) %>% 
  filter(!complete.cases(.))

DT::datatable(cc)

Then we report the pattern of missing for this set of patients.

cc %>% gg_miss_upset()

Section session info

sessionInfo()


bailliem/ida22 documentation built on Jan. 2, 2022, 12:14 a.m.