Calculates a particular set of summary statistics for a dataset.

get_stats(x)

Arguments

x

a numeric matrix or data frame with at least 2 columns/variables. Each column contains observations on a different variable. Missing observations are not allowed.

Value

A named list of summary statistics containing

  • n The sample size.

  • means The sample means of each variable.

  • variances The sample means of each variable.

  • correlation The sample correlation matrix.

  • intercepts,slopes,rsquared Matrices whose (i,j)th entries are the estimated regression coefficients in a regression of x[, i] on x[, j] and the resulting coefficient of determination \(R^2\).

Examples

get_stats(anscombe[, c(1, 5)])
#> $n
#> [1] 11
#> 
#> $means
#>       x1       y1 
#> 9.000000 7.500909 
#> 
#> $variances
#>        x1        y1 
#> 11.000000  4.127269 
#> 
#> $correlation
#>           x1        y1
#> x1 1.0000000 0.8164205
#> y1 0.8164205 1.0000000
#> 
#> $intercepts
#>          x1       y1
#> x1 0.000000 1.332843
#> y1 3.000091 0.000000
#> 
#> $slopes
#>           x1         y1
#> x1 1.0000000 -0.9975311
#> y1 0.5000909  1.0000000
#> 
#> $rsquared
#>           [,1]      [,2]
#> [1,] 1.0000000 0.6665425
#> [2,] 0.6665425 1.0000000
#>