The diagnose_numeric() produces information for diagnosing the quality of the numerical data.

diagnose_numeric(.data, ...)

# S3 method for data.frame
diagnose_numeric(.data, ...)

Arguments

.data

a data.frame or a tbl_df.

...

one or more unquoted expressions separated by commas. You can treat variable names like they are positions. Positive values select variables; negative values to drop variables. If the first expression is negative, diagnose_numeric() will automatically start with all variables. These arguments are automatically quoted and evaluated in a context where column names represent column positions. They support unquoting and splicing.

Value

an object of tbl_df.

Details

The scope of the diagnosis is the calculate a statistic that can be used to understand the distribution of numerical data. min, Q1, mean, median, Q3, max can be used to estimate the distribution of data. If the number of zero or minus is large, it is necessary to suspect the error of the data. If the number of outliers is large, a strategy of eliminating or replacing outliers is needed.

Numerical diagnostic information

The information derived from the numerical data diagnosis is as follows.

  • variables : variable names

  • min : minimum

  • Q1 : 25 percentile

  • mean : arithmetic average

  • median : median. 50 percentile

  • Q3 : 75 percentile

  • max : maximum

  • zero : count of zero values

  • minus : count of minus values

  • outlier : count of outliers

See vignette("diagonosis") for an introduction to these concepts.

See also

Examples

# \donttest{ # Diagnosis of numerical variables diagnose_numeric(heartfailure)
#> # A tibble: 7 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 age 40 51 6.08e1 6 e1 7 e1 9.5 e1 0 0 0 #> 2 cpk_enzyme 23 116. 5.82e2 2.5 e2 5.82e2 7.86e3 0 0 29 #> 3 ejection_fr… 14 30 3.81e1 3.8 e1 4.5 e1 8 e1 0 0 2 #> 4 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 5 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 6 sodium 113 134 1.37e2 1.37e2 1.4 e2 1.48e2 0 0 4 #> 7 time 4 73 1.30e2 1.15e2 2.03e2 2.85e2 0 0 0
# Select the variable to diagnose diagnose_numeric(heartfailure, cpk_enzyme, sodium)
#> # A tibble: 2 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 cpk_enzyme 23 116. 582. 250 582 7861 0 0 29 #> 2 sodium 113 134 137. 137 140 148 0 0 4
diagnose_numeric(heartfailure, -cpk_enzyme, -sodium)
#> # A tibble: 5 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 age 40 51 6.08e1 6 e1 7 e1 9.5 e1 0 0 0 #> 2 ejection_fr… 14 30 3.81e1 3.8 e1 4.5 e1 8 e1 0 0 2 #> 3 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 4 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 5 time 4 73 1.30e2 1.15e2 2.03e2 2.85e2 0 0 0
diagnose_numeric(heartfailure, "cpk_enzyme", "sodium")
#> # A tibble: 2 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 cpk_enzyme 23 116. 582. 250 582 7861 0 0 29 #> 2 sodium 113 134 137. 137 140 148 0 0 4
diagnose_numeric(heartfailure, 5)
#> # A tibble: 1 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 ejection_fraction 14 30 38.1 38 45 80 0 0 2
# Using pipes --------------------------------- library(dplyr) # Diagnosis of all numerical variables heartfailure %>% diagnose_numeric()
#> # A tibble: 7 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 age 40 51 6.08e1 6 e1 7 e1 9.5 e1 0 0 0 #> 2 cpk_enzyme 23 116. 5.82e2 2.5 e2 5.82e2 7.86e3 0 0 29 #> 3 ejection_fr… 14 30 3.81e1 3.8 e1 4.5 e1 8 e1 0 0 2 #> 4 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 5 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 6 sodium 113 134 1.37e2 1.37e2 1.4 e2 1.48e2 0 0 4 #> 7 time 4 73 1.30e2 1.15e2 2.03e2 2.85e2 0 0 0
# Positive values select variables heartfailure %>% diagnose_numeric(cpk_enzyme, sodium)
#> # A tibble: 2 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 cpk_enzyme 23 116. 582. 250 582 7861 0 0 29 #> 2 sodium 113 134 137. 137 140 148 0 0 4
# Negative values to drop variables heartfailure %>% diagnose_numeric(-cpk_enzyme, -sodium)
#> # A tibble: 5 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 age 40 51 6.08e1 6 e1 7 e1 9.5 e1 0 0 0 #> 2 ejection_fr… 14 30 3.81e1 3.8 e1 4.5 e1 8 e1 0 0 2 #> 3 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 4 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 5 time 4 73 1.30e2 1.15e2 2.03e2 2.85e2 0 0 0
# Positions values select variables heartfailure %>% diagnose_numeric(5)
#> # A tibble: 1 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 ejection_fraction 14 30 38.1 38 45 80 0 0 2
# Negative values to drop variables heartfailure %>% diagnose_numeric(-1, -5)
#> # A tibble: 5 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 cpk_enzyme 23 116. 5.82e2 2.5 e2 5.82e2 7.86e3 0 0 29 #> 2 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 3 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 4 sodium 113 134 1.37e2 1.37e2 1.4 e2 1.48e2 0 0 4 #> 5 time 4 73 1.30e2 1.15e2 2.03e2 2.85e2 0 0 0
# Using pipes & dplyr ------------------------- # List of variables containing outliers heartfailure %>% diagnose_numeric() %>% filter(outlier > 0)
#> # A tibble: 5 x 10 #> variables min Q1 mean median Q3 max zero minus outlier #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 cpk_enzyme 23 116. 5.82e2 2.5 e2 5.82e2 7.86e3 0 0 29 #> 2 ejection_fr… 14 30 3.81e1 3.8 e1 4.5 e1 8 e1 0 0 2 #> 3 platelets 25100 212500 2.63e5 2.62e5 3.04e5 8.5 e5 0 0 21 #> 4 creatinine 0.5 0.9 1.39e0 1.1 e0 1.4 e0 9.4 e0 0 0 29 #> 5 sodium 113 134 1.37e2 1.37e2 1.4 e2 1.48e2 0 0 4
# }