compute_data_summary: Compute a Descriptive Statistics Summary

View source: R/data_summary.R

compute_data_summaryR Documentation

Compute a Descriptive Statistics Summary

Description

compute_data_summary() computes a comprehensive set of descriptive statistics for a numeric vector and returns them as a named list. It is called automatically by fitverse() and summary.fitverse(), but can also be used independently for exploratory data analysis.

Usage

compute_data_summary(x, xlab = "x", n_raw = NULL)

Arguments

x

A numeric vector, already cleaned of non-finite values (or not – the function removes them internally).

xlab

Character: variable name, stored in the returned list for labelling. Default "x".

n_raw

Integer or NULL: the original sample size before cleaning. If supplied, n_missing is computed as n_raw - n. If NULL, n_missing is set to NA.

Details

Skewness and kurtosis are computed using the bias-corrected (unbiased) estimators:

g_1 = \frac{n}{(n-1)(n-2)} \sum_{i=1}^n \left(\frac{x_i - \bar{x}}{s}\right)^3

g_2 = \frac{n(n+1)}{(n-1)(n-2)(n-3)} \sum_{i=1}^n \left(\frac{x_i - \bar{x}}{s}\right)^4 - \frac{3(n-1)^2}{(n-2)(n-3)}

These correspond to the skewness and kurtosis functions in the moments package (type 3 in e1071) and are consistent with the convention in Applied Statistics textbooks. The Normal distribution has skewness 0 and excess kurtosis 0.

Value

compute_data_summary() returns a named list with the following elements:

n

Integer: number of finite (non-missing) observations used.

n_missing

Integer or NA: number of non-finite values removed.

mean

Arithmetic mean.

sd

Standard deviation (denominator n-1).

cv

Coefficient of variation (sd / mean). NA when mean == 0.

median

Sample median.

iqr

Interquartile range (Q_{0.75} - Q_{0.25}).

skewness

Sample skewness (Fisher's g_1).

kurtosis

Excess kurtosis (Fisher's g_2).

min

Sample minimum.

max

Sample maximum.

range

Range (max - min).

q25

25th percentile.

q75

75th percentile.

xlab

Character: the variable label.

Author(s)

Karuna G. Reddy karuna.reddy@auckland.ac.nz
M. G. M. Khan mgm.khan@usp.ac.fj

See Also

fitverse (calls this automatically), summary.fitverse.

Examples

set.seed(3)
x <- rlnorm(500, meanlog = 1, sdlog = 0.5)

ds <- compute_data_summary(x, xlab = "Claim amount", n_raw = 510)
ds$skewness
ds$cv

FitVerse documentation built on Dec. 1, 2026, 1:07 a.m.