Package 'ExclusionTable'

Title: Creating Tables of Excluded Observations
Description: Instead of counting observations before and after a subset() call, the ExclusionTable() function reports the number before and after each subset() call together with the number of observations that have been excluded. This is especially useful in observational studies for keeping track how many observations have been excluded for each in-/ or exclusion criteria. You just need to provide ExclusionTable() with a dataset and a list of logical filter statements.
Authors: Joshua P. Entrop [aut, cre] , Simon Steiger [ctb]
Maintainer: Joshua P. Entrop <[email protected]>
License: CC BY 4.0
Version: 1.1.0.9000
Built: 2024-11-09 05:08:28 UTC
Source: https://github.com/entjos/exclusiontable

Help Index


Exclusion Table

Description

This function keeps track of how many observations you exclude by using specific inclusion and exclusion criteria. It assumes that your criteria are logical filter statements, i.e. statements that you would pass to dplyr::filter() or to {data.table}.

Usage

exclusion_table(
  data = NULL,
  inclusion_criteria = NULL,
  exclusion_criteria = NULL,
  labels_inclusion = inclusion_criteria,
  labels_exclusion = exclusion_criteria,
  obj = NULL,
  keep_data = TRUE,
  id = NULL
)

Arguments

data

A dataframe on which the exclusions are to be performed.

inclusion_criteria

A character vector of logical expressions that are used for inclusions. All individuals who meet these criteria will be included. Specifically, observations for which the logical expression is FALSE will be excluded. Please keep in mind how your expression will handle NA values.

exclusion_criteria

A character vector of logical expressions that are used for exclusions. All observations who meet this criteria will be excluded. Specifically, observations for which the logical expression is TRUE will be excluded. Please keep in mind how your expression will handle NA values.

labels_inclusion

An optional character vector of labels that are used to label the steps of inclusions. The default labels are the logical expressions passed to inclusion_criteria

labels_exclusion

An optional character vector of labels that are used to label the steps of exclusions. The default labels are the logical expressions passed to exclusion_criteria.

obj

A named list of objects that will be passed to the filtering call. The list can be access using ⁠obj$<name of object>⁠ in the filtering call.

keep_data

A logical statement to indicate whether the new dataset without the excluded observations should be outputted. The default is TRUE.

id

Optional name of a unique ID variable in the dataset.

Value

exclusion_table returns a exl_tbl object which is a list of data frames including the following information:

table_in

a data.frame including the number of observations excluded for each inclusion criteria listed in inclusion_criteria.

table_ex

a data.frame including the number of observations excluded for each exclusion criteria listed in exclusion_criteria.

dataset

a data.frame of the supplied dataset after applying all inclusion and exclusion criteria.

If id is supplied, an additional column is added to table_in and table_ex including a list of the ids that have been excluded from the dataset in each step.

Examples

#Example without using the obj argument
exclusion_table(
   data = mtcars,
   exclusion_criteria = c("disp <= 70 | disp >= 300",
                          "as.character(gear) == '4'"),
   labels_exclusion   = c("First exclusion",
                          "Second exclusion")
)

#Example using the obj argument
my_selection <- c(8, 6)

exclusion_table(
  data = mtcars,
  exclusion_criteria = c("cyl %in% my_selection"),
  labels_exclusion   = c("First exclusion"),
  obj = list(my_selection = my_selection)
)

Prints exl_tbl objects

Description

This is a print function for exl_tbl objects, created with exlcusion_table(). The function improves the readability of the output.

Usage

## S3 method for class 'exl_tbl'
print(x, ...)

Arguments

x

An exl_tbl object.

...

Other arguments that should be passed to print.

Value

No return value, called for side effects.