Module stikpetP.effect_sizes.eff_size_fei

Expand source code
from math import log
import pandas as pd

def es_fei(chi2, n, minExp):
    '''
    Fei
    -----------------------
     
    An effect size measure that could be used with a chi-square test of goodness-of-fit.

    Ben-Shachar et al. (2023) developed this effect size measure for goodness-of-fit tests. They divide the found chi-square test statistic by the maximum possible chi-square value, and then take the square root from this.
    
    The measure is therefor simply the square root from Johnston-Berry-Mielke E. Although Ben-Shachar et al. reference the article from Johnston et al (2006), in personal communication with them (pers. comm. 2024) they indicated that it was a case of independent discovery and only later found that similar attempts were made as theirs that were very close.
    
    Taking the square root makes sense, since as the name implies the chi-square is a squared value, and also other effect sizes use the square root, making Fei more aligned with those.

    This function is shown in this [YouTube video](https://youtu.be/A-XhADBqaj4) and the measure is also described at [PeterStatistics.com](https://peterstatistics.com/Terms/EffectSizes/Fei.html)
    
    Parameters
    ----------
    chi2 : float
        the chi-square test statistic
    n : int
        the sample size
    minExp: float
        the minimum expected count
        
    Returns
    -------
    f : float
        the value of Fei
   
    Notes
    -----
    The formula used (Ben-Shachar et al., 2023, p. 6):
    $$Fei = \\sqrt{\\frac{\\chi_{GoF}^2}{n\\times\\left(\\frac{1}{\\min\\left(p_E\\right)}-1\\right)}}$$
    
    *Symbols*
    
    * $\\chi_{GoF}^2$, the chi-square value of the goodness-of-fit chi-square test
    * $n$, the sample size
    * $p_E$, the expected proportions
    
    *Classification*
    
    A qualification rule-of-thumb could be obtained by converting this to Cohen's w (use **es_convert(Fei, fr="fei", to="cohenw", ex1=minExp/n)**)
    
    Before, After and Alternatives
    ------------------------------
    Before this you will need a chi-square value. From either:
    * [ts_pearson_gof](../tests/test_pearson_gof.html#ts_pearson_gof) for Pearson Chi-Square Goodness-of-Fit Test
    * [ts_freeman_tukey_gof](../tests/test_freeman_tukey_gof.html#ts_freeman_tukey_gof) for Freeman-Tukey Test of Goodness-of-Fit
    * [ts_freeman_tukey_read](../tests/test_freeman_tukey_read.html#ts_freeman_tukey_read) for Freeman-Tukey-Read Test of Goodness-of-Fit
    * [ts_g_gof](../tests/test_g_gof.html#ts_g_gof) for G (Likelihood Ratio) Goodness-of-Fit Test
    * [ts_mod_log_likelihood_gof](../tests/test_mod_log_likelihood_gof.html#ts_mod_log_likelihood_gof) for Mod-Log Likelihood Test of Goodness-of-Fit
    * [ts_neyman_gof](../tests/test_neyman_gof.html#ts_neyman_gof) for Neyman Test of Goodness-of-Fit
    * [ts_powerdivergence_gof](../tests/test_powerdivergence_gof.html#ts_powerdivergence_gof) for Power Divergence GoF Test
    * [ph_pairwise_gof](../other/poho_pairwise_gof.html#ph_pairwise_gof) for Pairwise Goodness-of-Fit Tests
    * [ph_residual_gof_gof](../other/poho_residual_gof_gof.html#ph_residual_gof_gof) for Residuals Using Goodness-of-Fit Tests

    After this you might want to use some rule-of-thumb for the interpretation by converting it to Cohen w:
    * [es_convert](../effect_sizes/convert_es.html#es_convert) to convert Fei to Cohen w (using fr="fei", to="cohenw", ex1=minExp/n)
    * [th_cohen_w](../other/thumb_cohen_w.html#th_cohen_w) for various rules-of-thumb for Cohen w

    Alternative effect sizes that use a chi-square value:
    * [es_cramer_v_gof](../effect_sizes/eff_size_cramer_v_gof.html#es_cramer_v_gof) for Cramer's V for Goodness-of-Fit
    * [es_cohen_w](../effect_sizes/eff_size_cohen_w.html#es_cohen_w) for Cohen's w
    * [es_jbm_e](../effect_sizes/eff_size_jbm_e.html#es_jbm_e) for Johnston-Berry-Mielke E
    
    References
    ----------
    Ben-Shachar, M. S., Patil, I., Thériault, R., Wiernik, B. M., & Lüdecke, D. (2023). Phi, fei, fo, fum: Effect sizes for categorical data that use the chi-squared statistic. *Mathematics, 11*(1982), 1–10. doi:10.3390/math11091982

    Johnston, J. E., Berry, K. J., & Mielke, P. W. (2006). Measures of effect size for chi-squared and likelihood-ratio goodness-of-fit tests. *Perceptual and Motor Skills, 103*(2), 412–414. doi:10.2466/pms.103.2.412-414
    
    Author
    ------
    Made by P. Stikker
    
    Companion website: https://PeterStatistics.com  
    YouTube channel: https://www.youtube.com/stikpet  
    Donations: https://www.patreon.com/bePatron?u=19398076

    Example
    --------
    >>> chi2 = 23.5
    >>> n = 53
    >>> minExp = 14
    >>> es_fei(chi2=chi2, n=n, minExp=minExp)
    0.39895848925547156
    
    '''
    pe = minExp/n
    f = (chi2/(n*(1/pe - 1)))**0.5
    return f

Functions

def es_fei(chi2, n, minExp)

Fei

An effect size measure that could be used with a chi-square test of goodness-of-fit.

Ben-Shachar et al. (2023) developed this effect size measure for goodness-of-fit tests. They divide the found chi-square test statistic by the maximum possible chi-square value, and then take the square root from this.

The measure is therefor simply the square root from Johnston-Berry-Mielke E. Although Ben-Shachar et al. reference the article from Johnston et al (2006), in personal communication with them (pers. comm. 2024) they indicated that it was a case of independent discovery and only later found that similar attempts were made as theirs that were very close.

Taking the square root makes sense, since as the name implies the chi-square is a squared value, and also other effect sizes use the square root, making Fei more aligned with those.

This function is shown in this YouTube video and the measure is also described at PeterStatistics.com

Parameters

chi2 : float
the chi-square test statistic
n : int
the sample size
minExp : float
the minimum expected count

Returns

f : float
the value of Fei

Notes

The formula used (Ben-Shachar et al., 2023, p. 6): Fei = \sqrt{\frac{\chi_{GoF}^2}{n\times\left(\frac{1}{\min\left(p_E\right)}-1\right)}}

Symbols

  • $\chi_{GoF}^2$, the chi-square value of the goodness-of-fit chi-square test
  • $n$, the sample size
  • $p_E$, the expected proportions

Classification

A qualification rule-of-thumb could be obtained by converting this to Cohen's w (use es_convert(Fei, fr="fei", to="cohenw", ex1=minExp/n))

Before, After and Alternatives

Before this you will need a chi-square value. From either: * ts_pearson_gof for Pearson Chi-Square Goodness-of-Fit Test * ts_freeman_tukey_gof for Freeman-Tukey Test of Goodness-of-Fit * ts_freeman_tukey_read for Freeman-Tukey-Read Test of Goodness-of-Fit * ts_g_gof for G (Likelihood Ratio) Goodness-of-Fit Test * ts_mod_log_likelihood_gof for Mod-Log Likelihood Test of Goodness-of-Fit * ts_neyman_gof for Neyman Test of Goodness-of-Fit * ts_powerdivergence_gof for Power Divergence GoF Test * ph_pairwise_gof for Pairwise Goodness-of-Fit Tests * ph_residual_gof_gof for Residuals Using Goodness-of-Fit Tests

After this you might want to use some rule-of-thumb for the interpretation by converting it to Cohen w: * es_convert to convert Fei to Cohen w (using fr="fei", to="cohenw", ex1=minExp/n) * th_cohen_w for various rules-of-thumb for Cohen w

Alternative effect sizes that use a chi-square value: * es_cramer_v_gof for Cramer's V for Goodness-of-Fit * es_cohen_w for Cohen's w * es_jbm_e for Johnston-Berry-Mielke E

References

Ben-Shachar, M. S., Patil, I., Thériault, R., Wiernik, B. M., & Lüdecke, D. (2023). Phi, fei, fo, fum: Effect sizes for categorical data that use the chi-squared statistic. Mathematics, 11(1982), 1–10. doi:10.3390/math11091982

Johnston, J. E., Berry, K. J., & Mielke, P. W. (2006). Measures of effect size for chi-squared and likelihood-ratio goodness-of-fit tests. Perceptual and Motor Skills, 103(2), 412–414. doi:10.2466/pms.103.2.412-414

Author

Made by P. Stikker

Companion website: https://PeterStatistics.com
YouTube channel: https://www.youtube.com/stikpet
Donations: https://www.patreon.com/bePatron?u=19398076

Example

>>> chi2 = 23.5
>>> n = 53
>>> minExp = 14
>>> es_fei(chi2=chi2, n=n, minExp=minExp)
0.39895848925547156
Expand source code
def es_fei(chi2, n, minExp):
    '''
    Fei
    -----------------------
     
    An effect size measure that could be used with a chi-square test of goodness-of-fit.

    Ben-Shachar et al. (2023) developed this effect size measure for goodness-of-fit tests. They divide the found chi-square test statistic by the maximum possible chi-square value, and then take the square root from this.
    
    The measure is therefor simply the square root from Johnston-Berry-Mielke E. Although Ben-Shachar et al. reference the article from Johnston et al (2006), in personal communication with them (pers. comm. 2024) they indicated that it was a case of independent discovery and only later found that similar attempts were made as theirs that were very close.
    
    Taking the square root makes sense, since as the name implies the chi-square is a squared value, and also other effect sizes use the square root, making Fei more aligned with those.

    This function is shown in this [YouTube video](https://youtu.be/A-XhADBqaj4) and the measure is also described at [PeterStatistics.com](https://peterstatistics.com/Terms/EffectSizes/Fei.html)
    
    Parameters
    ----------
    chi2 : float
        the chi-square test statistic
    n : int
        the sample size
    minExp: float
        the minimum expected count
        
    Returns
    -------
    f : float
        the value of Fei
   
    Notes
    -----
    The formula used (Ben-Shachar et al., 2023, p. 6):
    $$Fei = \\sqrt{\\frac{\\chi_{GoF}^2}{n\\times\\left(\\frac{1}{\\min\\left(p_E\\right)}-1\\right)}}$$
    
    *Symbols*
    
    * $\\chi_{GoF}^2$, the chi-square value of the goodness-of-fit chi-square test
    * $n$, the sample size
    * $p_E$, the expected proportions
    
    *Classification*
    
    A qualification rule-of-thumb could be obtained by converting this to Cohen's w (use **es_convert(Fei, fr="fei", to="cohenw", ex1=minExp/n)**)
    
    Before, After and Alternatives
    ------------------------------
    Before this you will need a chi-square value. From either:
    * [ts_pearson_gof](../tests/test_pearson_gof.html#ts_pearson_gof) for Pearson Chi-Square Goodness-of-Fit Test
    * [ts_freeman_tukey_gof](../tests/test_freeman_tukey_gof.html#ts_freeman_tukey_gof) for Freeman-Tukey Test of Goodness-of-Fit
    * [ts_freeman_tukey_read](../tests/test_freeman_tukey_read.html#ts_freeman_tukey_read) for Freeman-Tukey-Read Test of Goodness-of-Fit
    * [ts_g_gof](../tests/test_g_gof.html#ts_g_gof) for G (Likelihood Ratio) Goodness-of-Fit Test
    * [ts_mod_log_likelihood_gof](../tests/test_mod_log_likelihood_gof.html#ts_mod_log_likelihood_gof) for Mod-Log Likelihood Test of Goodness-of-Fit
    * [ts_neyman_gof](../tests/test_neyman_gof.html#ts_neyman_gof) for Neyman Test of Goodness-of-Fit
    * [ts_powerdivergence_gof](../tests/test_powerdivergence_gof.html#ts_powerdivergence_gof) for Power Divergence GoF Test
    * [ph_pairwise_gof](../other/poho_pairwise_gof.html#ph_pairwise_gof) for Pairwise Goodness-of-Fit Tests
    * [ph_residual_gof_gof](../other/poho_residual_gof_gof.html#ph_residual_gof_gof) for Residuals Using Goodness-of-Fit Tests

    After this you might want to use some rule-of-thumb for the interpretation by converting it to Cohen w:
    * [es_convert](../effect_sizes/convert_es.html#es_convert) to convert Fei to Cohen w (using fr="fei", to="cohenw", ex1=minExp/n)
    * [th_cohen_w](../other/thumb_cohen_w.html#th_cohen_w) for various rules-of-thumb for Cohen w

    Alternative effect sizes that use a chi-square value:
    * [es_cramer_v_gof](../effect_sizes/eff_size_cramer_v_gof.html#es_cramer_v_gof) for Cramer's V for Goodness-of-Fit
    * [es_cohen_w](../effect_sizes/eff_size_cohen_w.html#es_cohen_w) for Cohen's w
    * [es_jbm_e](../effect_sizes/eff_size_jbm_e.html#es_jbm_e) for Johnston-Berry-Mielke E
    
    References
    ----------
    Ben-Shachar, M. S., Patil, I., Thériault, R., Wiernik, B. M., & Lüdecke, D. (2023). Phi, fei, fo, fum: Effect sizes for categorical data that use the chi-squared statistic. *Mathematics, 11*(1982), 1–10. doi:10.3390/math11091982

    Johnston, J. E., Berry, K. J., & Mielke, P. W. (2006). Measures of effect size for chi-squared and likelihood-ratio goodness-of-fit tests. *Perceptual and Motor Skills, 103*(2), 412–414. doi:10.2466/pms.103.2.412-414
    
    Author
    ------
    Made by P. Stikker
    
    Companion website: https://PeterStatistics.com  
    YouTube channel: https://www.youtube.com/stikpet  
    Donations: https://www.patreon.com/bePatron?u=19398076

    Example
    --------
    >>> chi2 = 23.5
    >>> n = 53
    >>> minExp = 14
    >>> es_fei(chi2=chi2, n=n, minExp=minExp)
    0.39895848925547156
    
    '''
    pe = minExp/n
    f = (chi2/(n*(1/pe - 1)))**0.5
    return f