Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Module « scipy.stats »

Fonction ttest_1samp - module scipy.stats

Signature de la fonction ttest_1samp

def ttest_1samp(a, popmean, axis=0, nan_policy='propagate', alternative='two-sided') 

Description

ttest_1samp.__doc__

Calculate the T-test for the mean of ONE group of scores.

    This is a two-sided test for the null hypothesis that the expected value
    (mean) of a sample of independent observations `a` is equal to the given
    population mean, `popmean`.

    Parameters
    ----------
    a : array_like
        Sample observation.
    popmean : float or array_like
        Expected value in null hypothesis. If array_like, then it must have the
        same shape as `a` excluding the axis dimension.
    axis : int or None, optional
        Axis along which to compute test; default is 0. If None, compute over
        the whole array `a`.
    nan_policy : {'propagate', 'raise', 'omit'}, optional
        Defines how to handle when input contains nan.
        The following options are available (default is 'propagate'):

          * 'propagate': returns nan
          * 'raise': throws an error
          * 'omit': performs the calculations ignoring nan values
    alternative : {'two-sided', 'less', 'greater'}, optional
        Defines the alternative hypothesis.
        The following options are available (default is 'two-sided'):

          * 'two-sided'
          * 'less': one-sided
          * 'greater': one-sided

        .. versionadded:: 1.6.0

    Returns
    -------
    statistic : float or array
        t-statistic.
    pvalue : float or array
        Two-sided p-value.

    Examples
    --------
    >>> from scipy import stats
    >>> rng = np.random.default_rng()
    >>> rvs = stats.norm.rvs(loc=5, scale=10, size=(50, 2), random_state=rng)

    Test if mean of random sample is equal to true mean, and different mean.
    We reject the null hypothesis in the second case and don't reject it in
    the first case.

    >>> stats.ttest_1samp(rvs, 5.0)
    Ttest_1sampResult(statistic=array([-2.09794637, -1.75977004]), pvalue=array([0.04108952, 0.08468867]))
    >>> stats.ttest_1samp(rvs, 0.0)
    Ttest_1sampResult(statistic=array([1.64495065, 1.62095307]), pvalue=array([0.10638103, 0.11144602]))

    Examples using axis and non-scalar dimension for population mean.

    >>> result = stats.ttest_1samp(rvs, [5.0, 0.0])
    >>> result.statistic
    array([-2.09794637,  1.62095307])
    >>> result.pvalue
    array([0.04108952, 0.11144602])

    >>> result = stats.ttest_1samp(rvs.T, [5.0, 0.0], axis=1)
    >>> result.statistic
    array([-2.09794637,  1.62095307])
    >>> result.pvalue
    array([0.04108952, 0.11144602])

    >>> result = stats.ttest_1samp(rvs, [[5.0], [0.0]])
    >>> result.statistic
    array([[-2.09794637, -1.75977004],
           [ 1.64495065,  1.62095307]])
    >>> result.pvalue
    array([[0.04108952, 0.08468867],
           [0.10638103, 0.11144602]])