Calculate kurtosis (measure of tailedness) of real column
Kurtosis measures the “tailedness” of the distribution: - kurtosis = 3: normal distribution (mesokurtic) - kurtosis > 3: heavy tails (leptokurtic) - kurtosis < 3: light tails (platykurtic)
Returns excess kurtosis (kurtosis - 3) for easier interpretation Uses the sample kurtosis formula with bias correction
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
integer, | intent(in) | :: | col_index |
function df_kurtosis_real(df, col_index) result(kurt) type(data_frame), intent(in) :: df integer, intent(in) :: col_index real(rk) :: kurt real(rk), dimension(:), allocatable :: col type(column) :: data_col real(rk) :: avg, std_dev, m4 integer :: n, i if (col_index < 1 .or. col_index > df % ncols()) error stop "column index out of range" data_col = df % get_data_col(col_index) if (data_col % get_type() /= REAL_NUM) error stop "column is not real type" col = data_col % getr() n = size(col) if (n < 4) then kurt = 0.0_rk return end if ! Calculate mean and standard deviation avg = sum(col) / real(n, rk) std_dev = sqrt(sum((col - avg)**2) / real(n - 1, rk)) if (std_dev < epsilon(1.0_rk)) then kurt = 0.0_rk return end if ! Calculate fourth moment m4 = sum(((col - avg) / std_dev)**4) / real(n, rk) ! Apply bias correction and return excess kurtosis kurt = (real(n * (n + 1), rk) * m4 - 3.0_rk * real((n - 1)**2, rk)) / & real((n - 2) * (n - 3), rk) end function df_kurtosis_real