df_skewness_real Function

public function df_skewness_real(df, col_index) result(skew)

Calculate skewness (measure of asymmetry) of real column

Skewness measures the asymmetry of the distribution: - skewness = 0: symmetric distribution - skewness > 0: right-skewed (tail on the right) - skewness < 0: left-skewed (tail on the left)

Uses the sample skewness formula with bias correction (Fisher’s moment coefficient)

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
integer, intent(in) :: col_index

Return Value real(kind=rk)


Source Code

    function df_skewness_real(df, col_index) result(skew)
        type(data_frame), intent(in) :: df
        integer, intent(in) :: col_index
        real(rk) :: skew

        real(rk), dimension(:), allocatable :: col
        type(column) :: data_col
        real(rk) :: avg, std_dev, m3
        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 < 3) then
            skew = 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
            skew = 0.0_rk
            return
        end if

        ! Calculate third moment
        m3 = sum(((col - avg) / std_dev)**3) / real(n, rk)

        ! Apply bias correction
        skew = m3 * sqrt(real(n * (n - 1), rk)) / real(n - 2, rk)
    end function df_skewness_real