The describe() compute descriptive statistic of numerical(INTEGER, NUMBER, etc.) column of the DBMS table through tbl_dbi for exploratory data analysis.
# S3 method for tbl_dbi describe( .data, ..., statistics = NULL, quantiles = NULL, all.combinations = FALSE, in_database = FALSE, collect_size = Inf )
.data | a tbl_dbi. |
---|---|
... | 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, describe() 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. |
statistics | character. the name of the descriptive statistic to calculate. The defaults is c("mean", "sd", "se_mean", "IQR", "skewness", "kurtosis", "quantiles") |
quantiles | numeric. list of quantiles to calculate. The values of elements must be between 0 and 1. and to calculate quantiles, you must include "quantiles" in the statistics argument value. The default is c(0, .01, .05, 0.1, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.75, 0.8, 0.9, 0.95, 0.99, 1). |
all.combinations | logical. When used with group_by(), this argument expresses all combinations of group combinations. If the argument value is TRUE, cases that do not exist as actual data are also included in the output. |
in_database | Specifies whether to perform in-database operations. If TRUE, most operations are performed in the DBMS. if FALSE, table data is taken in R and operated in-memory. Not yet supported in_database = TRUE. |
collect_size | a integer. The number of data samples from the DBMS to R. Applies only if in_database = FALSE. See vignette("EDA") for an introduction to these concepts. |
An object of the same class as .data.
This function is useful when used with the group_by
function
of the dplyr package.
If you want to calculate the statistic by level of the categorical data
you are interested in, rather than the whole statistic, you can use
grouped_df as the group_by() function.
From version 0.5.5, the 'variable' column in the "descriptive statistic information" tibble object has been changed to 'described_variables'. This is because there are cases where 'variable' is included in the variable name of the data. There is probably no case where 'described_variables' is included in the variable name of the data.
The information derived from the numerical data describe is as follows.
n : number of observations excluding missing values
na : number of missing values
mean : arithmetic average
sd : standard deviation
se_mean : standard error mean. sd/sqrt(n)
IQR : interquartile range (Q3-Q1)
skewness : skewness
kurtosis : kurtosis
p25 : Q1. 25% percentile
p50 : median. 50% percentile
p75 : Q3. 75% percentile
p01, p05, p10, p20, p30 : 1%, 5%, 20%, 30% percentiles
p40, p60, p70, p80 : 40%, 60%, 70%, 80% percentiles
p90, p95, p99, p100 : 90%, 95%, 99%, 100% percentiles
# \donttest{ library(dplyr) # connect DBMS con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") # copy heartfailure to the DBMS with a table named TB_HEARTFAILURE copy_to(con_sqlite, heartfailure, name = "TB_HEARTFAILURE", overwrite = TRUE) # Using pipes --------------------------------- # Positive values select variables con_sqlite %>% tbl("TB_HEARTFAILURE") %>% describe(platelets, creatinine, sodium)#> # A tibble: 3 x 26 #> described_variab… n na mean sd se_mean IQR skewness kurtosis #> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 platelets 299 0 2.63e5 9.78e4 5.66e+3 9.1e+4 1.46 6.21 #> 2 creatinine 299 0 1.39e0 1.03e0 5.98e-2 5 e-1 4.46 25.8 #> 3 sodium 299 0 1.37e2 4.41e0 2.55e-1 6 e+0 -1.05 4.12 #> # … with 17 more variables: p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, #> # p20 <dbl>, p25 <dbl>, p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, #> # p70 <dbl>, p75 <dbl>, p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, #> # p100 <dbl>con_sqlite %>% tbl("TB_HEARTFAILURE") %>% describe(platelets, creatinine, sodium, statistics = c("mean", "sd", "quantiles"), quantiles = 0.1)#> # A tibble: 3 x 6 #> described_variables n na mean sd p10 #> <chr> <int> <int> <dbl> <dbl> <dbl> #> 1 platelets 299 0 263358. 97804. 153000 #> 2 creatinine 299 0 1.39 1.03 0.8 #> 3 sodium 299 0 137. 4.41 132# Negative values to drop variables, and In-memory mode and collect size is 200 con_sqlite %>% tbl("TB_HEARTFAILURE") %>% describe(-platelets, -creatinine, -sodium, collect_size = 200)#> # A tibble: 4 x 26 #> described_variables n na mean sd se_mean IQR skewness kurtosis #> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 age 200 0 62.0 12.2 0.859 18 0.442 -0.209 #> 2 cpk_enzyme 200 0 598. 1099. 77.7 468. 4.39 22.2 #> 3 ejection_fraction 200 0 38.0 12.6 0.894 15 0.509 -0.232 #> 4 time 200 0 84.5 48.5 3.43 72.2 0.192 -0.732 #> # … with 17 more variables: p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, #> # p20 <dbl>, p25 <dbl>, p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, #> # p70 <dbl>, p75 <dbl>, p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, #> # p100 <dbl># Using pipes & dplyr ------------------------- # Find the statistic of all numerical variables by 'smoking' and 'death_event', # and extract only those with 'smoking' variable level is "Yes". con_sqlite %>% tbl("TB_HEARTFAILURE") %>% group_by(smoking, death_event) %>% describe() %>% filter(smoking == "Yes")#> # A tibble: 14 x 28 #> described_variabl… smoking death_event n na mean sd se_mean #> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> #> 1 age Yes No 66 0 5.83e1 1.05e+1 1.29e+0 #> 2 age Yes Yes 30 0 6.75e1 1.08e+1 1.98e+0 #> 3 cpk_enzyme Yes No 66 0 6.19e2 1.00e+3 1.23e+2 #> 4 cpk_enzyme Yes Yes 30 0 5.12e2 1.05e+3 1.92e+2 #> 5 creatinine Yes No 66 0 1.18e0 5.84e-1 7.19e-2 #> 6 creatinine Yes Yes 30 0 1.74e0 1.60e+0 2.92e-1 #> 7 ejection_fraction Yes No 66 0 3.94e1 1.02e+1 1.26e+0 #> 8 ejection_fraction Yes Yes 30 0 3.15e1 1.12e+1 2.04e+0 #> 9 platelets Yes No 66 0 2.63e5 1.10e+5 1.36e+4 #> 10 platelets Yes Yes 30 0 2.76e5 1.04e+5 1.90e+4 #> 11 sodium Yes No 66 0 1.37e2 4.54e+0 5.59e-1 #> 12 sodium Yes Yes 30 0 1.35e2 3.78e+0 6.90e-1 #> 13 time Yes No 66 0 1.58e2 6.66e+1 8.20e+0 #> 14 time Yes Yes 30 0 6.10e1 5.60e+1 1.02e+1 #> # … with 20 more variables: IQR <dbl>, skewness <dbl>, kurtosis <dbl>, #> # p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, p20 <dbl>, p25 <dbl>, #> # p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, p70 <dbl>, p75 <dbl>, #> # p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, p100 <dbl># Using all.combinations = TRUE con_sqlite %>% tbl("TB_HEARTFAILURE") %>% filter(!smoking %in% "Yes" | !death_event %in% "Yes") %>% group_by(smoking, death_event) %>% describe(all.combinations = TRUE) %>% filter(smoking == "Yes")#> # A tibble: 14 x 28 #> described_variab… smoking death_event n na mean sd se_mean #> <chr> <chr> <chr> <dbl> <int> <dbl> <dbl> <dbl> #> 1 age Yes No 66 0 5.83e1 1.05e+1 1.29e+0 #> 2 age Yes Yes 0 NA NA NA NA #> 3 cpk_enzyme Yes No 66 0 6.19e2 1.00e+3 1.23e+2 #> 4 cpk_enzyme Yes Yes 0 NA NA NA NA #> 5 creatinine Yes No 66 0 1.18e0 5.84e-1 7.19e-2 #> 6 creatinine Yes Yes 0 NA NA NA NA #> 7 ejection_fraction Yes No 66 0 3.94e1 1.02e+1 1.26e+0 #> 8 ejection_fraction Yes Yes 0 NA NA NA NA #> 9 platelets Yes No 66 0 2.63e5 1.10e+5 1.36e+4 #> 10 platelets Yes Yes 0 NA NA NA NA #> 11 sodium Yes No 66 0 1.37e2 4.54e+0 5.59e-1 #> 12 sodium Yes Yes 0 NA NA NA NA #> 13 time Yes No 66 0 1.58e2 6.66e+1 8.20e+0 #> 14 time Yes Yes 0 NA NA NA NA #> # … with 20 more variables: IQR <dbl>, skewness <dbl>, kurtosis <dbl>, #> # p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, p20 <dbl>, p25 <dbl>, #> # p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, p70 <dbl>, p75 <dbl>, #> # p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, p100 <dbl># extract only those with 'sex' variable level is "Male", # and find 'sodium' statistics by 'smoking' and 'death_event' con_sqlite %>% tbl("TB_HEARTFAILURE") %>% filter(sex == "Male") %>% group_by(smoking, death_event) %>% describe(sodium)#> # A tibble: 4 x 28 #> described_variables smoking death_event n na mean sd se_mean IQR #> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> #> 1 sodium No No 67 0 137. 3.77 0.460 5.5 #> 2 sodium No Yes 35 0 135. 3.82 0.646 3 #> 3 sodium Yes No 65 0 137. 4.56 0.566 4 #> 4 sodium Yes Yes 27 0 135. 3.90 0.750 6.5 #> # … with 19 more variables: skewness <dbl>, kurtosis <dbl>, p00 <dbl>, #> # p01 <dbl>, p05 <dbl>, p10 <dbl>, p20 <dbl>, p25 <dbl>, p30 <dbl>, #> # p40 <dbl>, p50 <dbl>, p60 <dbl>, p70 <dbl>, p75 <dbl>, p80 <dbl>, #> # p90 <dbl>, p95 <dbl>, p99 <dbl>, p100 <dbl>