Convert Z-score (Z-value, standard score) to p-value for normal distribution in Python

后端 未结 7 1835
野趣味
野趣味 2020-12-12 18:19

How does one convert a Z-score from the Z-distribution (standard normal distribution, Gaussian distribution) to a p-value? I have yet to find the magical function in Scipy\'

7条回答
  •  生来不讨喜
    2020-12-12 18:31

    For Scipy lovers, Tough this is old question but relevant, and we can have not only normal but other distributions as well so here is solution for few more distributions:

    def get_p_value_normal(z_score: float) -> float:
        """get p value for normal(Gaussian) distribution 
    
        Args:
            z_score (float): z score
    
        Returns:
            float: p value
        """
        return round(norm.sf(z_score), decimal_limit)
    
    
    def get_p_value_t(z_score: float) -> float:
        """get p value for t distribution 
    
        Args:
            z_score (float): z score
    
        Returns:
            float: p value
        """
        return round(t.sf(z_score), decimal_limit)
    
    
    def get_p_value_chi2(z_score: float) -> float:
        """get p value for chi2 distribution 
    
        Args:
            z_score (float): z score
    
        Returns:
            float: p value
        """
        return round(chi2.ppf(z_score, df), decimal_limit)
    

提交回复
热议问题