Descriptive Statistics

Sameer Mathur

Load the mtcars dataset

mt <- mtcars[c("mpg", "hp", "wt", "am")]
head(mt)
                   mpg  hp    wt am
Mazda RX4         21.0 110 2.620  1
Mazda RX4 Wag     21.0 110 2.875  1
Datsun 710        22.8  93 2.320  1
Hornet 4 Drive    21.4 110 3.215  0
Hornet Sportabout 18.7 175 3.440  0
Valiant           18.1 105 3.460  0

Descriptive statistics using summary

mt <- mtcars[c("mpg", "hp", "wt", "am")]
summary(mt)
      mpg              hp              wt              am        
 Min.   :10.40   Min.   : 52.0   Min.   :1.513   Min.   :0.0000  
 1st Qu.:15.43   1st Qu.: 96.5   1st Qu.:2.581   1st Qu.:0.0000  
 Median :19.20   Median :123.0   Median :3.325   Median :0.0000  
 Mean   :20.09   Mean   :146.7   Mean   :3.217   Mean   :0.4062  
 3rd Qu.:22.80   3rd Qu.:180.0   3rd Qu.:3.610   3rd Qu.:1.0000  
 Max.   :33.90   Max.   :335.0   Max.   :5.424   Max.   :1.0000  

Descriptive statistics using describe in the Hmisc package

library(Hmisc)
myvars <- c("mpg", "hp", "wt")

Descriptive statistics using describe in the Hmisc package

describe(mtcars[myvars])
mtcars[myvars] 

 3  Variables      32  Observations
---------------------------------------------------------------------------
mpg 
       n  missing distinct     Info     Mean      Gmd      .05      .10 
      32        0       25    0.999    20.09    6.796    12.00    14.34 
     .25      .50      .75      .90      .95 
   15.43    19.20    22.80    30.09    31.30 

lowest : 10.4 13.3 14.3 14.7 15.0, highest: 26.0 27.3 30.4 32.4 33.9
---------------------------------------------------------------------------
hp 
       n  missing distinct     Info     Mean      Gmd      .05      .10 
      32        0       22    0.997    146.7    77.04    63.65    66.00 
     .25      .50      .75      .90      .95 
   96.50   123.00   180.00   243.50   253.55 

lowest :  52  62  65  66  91, highest: 215 230 245 264 335
---------------------------------------------------------------------------
wt 
       n  missing distinct     Info     Mean      Gmd      .05      .10 
      32        0       29    0.999    3.217    1.089    1.736    1.956 
     .25      .50      .75      .90      .95 
   2.581    3.325    3.610    4.048    5.293 

lowest : 1.513 1.615 1.835 1.935 2.140, highest: 3.845 4.070 5.250 5.345 5.424
---------------------------------------------------------------------------

Descriptive statistics using describe in the psych package

library(psych)
myvars <- c("mpg", "hp", "wt")
describe(mtcars[myvars])
    vars  n   mean    sd median trimmed   mad   min    max  range skew
mpg    1 32  20.09  6.03  19.20   19.70  5.41 10.40  33.90  23.50 0.61
hp     2 32 146.69 68.56 123.00  141.19 77.10 52.00 335.00 283.00 0.73
wt     3 32   3.22  0.98   3.33    3.15  0.77  1.51   5.42   3.91 0.42
    kurtosis    se
mpg    -0.37  1.07
hp     -0.14 12.12
wt     -0.02  0.17