Various summary statistics are calculated for different types of data.

stats(x, by)

Arguments

x

The data structure to compute the statistics. This can either be a vector, matrix (data sets are the columns), or a list (data sets are the components).

by

If x is a vector, an optional vector (either character or numerical) specifying the categories to divide x into separate data sets.

Value

A matrix where rows index the summary statistics and the columns index the separate data sets.

Details

Stats breaks x up into separate data sets and then calls describe to calculate the statistics. Statistics are found by columns for matrices, by components for a list and by the relevent groups when a numeric vector and a by vector are given. The default set of statistics are the number of (nonmissing) observations, mean, standard deviation, minimum, lower quartile, median, upper quartile, maximum, and number of missing observations. If any data set is nonnumeric, missing values are returned for the statistics. The by argument is a useful way to calculate statistics on parts of a data set according to different cases.

See also

stats.bin, stats.bplot, describe

Examples

#Statistics for 8 normal random samples: 
zork<- matrix( rnorm(200), ncol=8) 
stats(zork) 
#>                       [,1]        [,2]       [,3]        [,4]        [,5]
#> N              25.00000000 25.00000000 25.0000000 25.00000000 25.00000000
#> mean           -0.01752720 -0.02935052 -0.1535632 -0.38043498 -0.03956694
#> Std.Dev.        1.08131915  1.00083856  0.9857992  1.15017873  1.21902146
#> min            -2.26425497 -2.43644850 -2.8525655 -2.30175485 -2.48126796
#> Q1             -0.73801096 -0.75275976 -0.6579678 -1.06213238 -1.06496350
#> median         -0.01831535 -0.09055978 -0.1726492 -0.29168101  0.48219381
#> Q3              0.64381244  0.79448481  0.3294062 -0.07124966  1.07520650
#> max             2.08752090  1.58777168  1.6990454  3.55043575  1.36020388
#> missing values  0.00000000  0.00000000  0.0000000  0.00000000  0.00000000
#>                      [,6]        [,7]       [,8]
#> N              25.0000000 25.00000000 25.0000000
#> mean           -0.2257568 -0.30514346  0.1573250
#> Std.Dev.        1.0989661  1.23771378  0.9549399
#> min            -2.1163040 -2.41760012 -0.9761817
#> Q1             -1.0240263 -1.17097376 -0.5242037
#> median         -0.1217741 -0.36807491 -0.1541350
#> Q3              0.4719565  0.07013066  0.6811354
#> max             2.1425132  2.30111482  2.9343506
#> missing values  0.0000000  0.00000000  0.0000000

zork<- rnorm( 200)
id<- sample( 1:8, 200, replace=TRUE)
stats( zork, by=id)
#>                         2          4          1          7          8
#> N              21.0000000 28.0000000 24.0000000 26.0000000 26.0000000
#> mean           -0.1387133 -0.3845008 -0.2577053 -0.3007597  0.1923705
#> Std.Dev.        1.1001880  0.9189559  0.8722839  0.7906721  1.0735988
#> min            -2.4984312 -2.2668486 -1.8414066 -2.0699565 -2.7737386
#> Q1             -0.8821459 -0.9964838 -0.8681123 -0.8799735 -0.3910351
#> median         -0.2616115 -0.4354078 -0.2623669 -0.4439820  0.3088745
#> Q3              0.4992048  0.1753936  0.2488412  0.2623299  0.9148072
#> max             2.0377198  1.6373195  1.2669469  1.4811374  1.9504605
#> missing values  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>                          3          6          5
#> N              24.00000000 37.0000000 14.0000000
#> mean           -0.18109002  0.1767309 -0.1716936
#> Std.Dev.        1.29433530  1.0922973  0.8198512
#> min            -2.53599976 -2.7405849 -2.1270406
#> Q1             -1.23059766 -0.5375707 -0.4008471
#> median         -0.05590936  0.1475960 -0.2339443
#> Q3              0.52766472  1.1126824  0.2574636
#> max             2.24932428  2.0224308  1.0728166
#> missing values  0.00000000  0.0000000  0.0000000