The student t distribution is also available as scipy.stats.t.
Calling stdtr directly can improve performance compared to the
cdf method of scipy.stats.t (see last example below).
The function is computed using the Boost Math library [1], which
relies on the incomplete beta function.
Array API Standard Support
stdtr has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
Plot the function for three different degrees of freedom.
>>> x=np.linspace(-10,10,1000)>>> fig,ax=plt.subplots()>>> parameters=[(1,"solid"),(3,"dashed"),(10,"dotted")]>>> for(df,linestyle)inparameters:... ax.plot(x,stdtr(df,x),ls=linestyle,label=f"$df={df}$")>>> ax.legend()>>> ax.set_title("Student t distribution cumulative distribution function")>>> plt.show()
../../_images/scipy-special-stdtr-1_00_00.png
The function can be computed for several degrees of freedom at the same
time by providing a NumPy array or list for df:
It is possible to calculate the function at several points for several
different degrees of freedom simultaneously by providing arrays for df
and t with shapes compatible for broadcasting. Compute stdtr at
4 points for 3 degrees of freedom resulting in an array of shape 3x4.
The t distribution is also available as scipy.stats.t. Calling stdtr
directly can be much faster than calling the cdf method of
scipy.stats.t. To get the same results, one must use the following
parametrization: scipy.stats.t(df).cdf(x)=stdtr(df,x).
>>> fromscipy.statsimportt>>> df,x=3,1>>> stdtr_result=stdtr(df,x)# this can be faster than below>>> stats_result=t(df).cdf(x)>>> stats_result==stdtr_result# test that results are equalTrue