Using the describe function

The summary() function provides a handy overview of descriptive statistics. There is also another function that can do the same thing, and provides more useful information: describe() from the psych package. We need to install the psych package once and then can load it via the library command.

install.packages("psych")
# Downloading packages -------------------------------------------------------
- Downloading psych from CRAN ...               OK [1.1 Mb in 0.16s]
Successfully downloaded 1 package in 2.3 seconds.

The following package(s) will be installed:
- psych [2.6.3]
These packages will be installed into "~/Documents/Open-Stat-Prog/descriptive-statistics/renv/library/macos/R-4.4/aarch64-apple-darwin20".

# Installing packages --------------------------------------------------------
- Installing psych ...                          OK [built from source and cached in 16s]
Successfully installed 1 package in 16 seconds.
library(psych)

describe(stocks)
          vars  n    mean    sd median trimmed   mad  min  max range  skew
YEAR         1 88 1971.50 25.55 1971.5 1971.50 32.62 1928 2015    87  0.00
TBONDS       2 82    5.46  8.00    4.0    4.88  5.93  -11   33    44  0.88
SPSTOCK      3 88   11.42 19.85   14.0   12.12 20.76  -44   53    97 -0.38
TBONDS_D     4 82    0.80  0.40    1.0    0.88  0.00    0    1     1 -1.51
SPSTOCK_D    5 88    0.72  0.45    1.0    0.76  0.00    0    1     1 -0.94
          kurtosis   se
YEAR         -1.24 2.72
TBONDS        1.10 0.88
SPSTOCK      -0.07 2.12
TBONDS_D      0.29 0.04
SPSTOCK_D    -1.13 0.05

Here we can also see, for example, the number of observations per variable (n) and the range (the difference between the minimum and maximum values observed).

Back to top