ize=(8, 8)) >>> for parameter_set in parameters_list: ... p, n, style = parameter_set ... nbdtrc_vals = nbdtrc(k, n, p) ... ax.plot(k, nbdtrc_vals, label=rf"$n={n},\, p={p}$", ... ls=style) >>> ax.legend() >>> ax.set_xlabel("$k$") >>> ax.set_title("Negative binomial distribution survival function") >>> plt.show() The negative binomial distribution is also available as `scipy.stats.nbinom`. Using `nbdtrc` directly can be much faster than calling the ``sf`` method of `scipy.stats.nbinom`, especially for small arrays or individual values. To get the same results one must use the following parametrization: ``nbinom(n, p).sf(k)=nbdtrc(k, n, p)``. >>> from scipy.stats import nbinom >>> k, n, p = 3, 5, 0.5 >>> nbdtr_res = nbdtrc(k, n, p) # this will often be faster than below >>> stats_res = nbinom(n, p).sf(k) >>> stats_res, nbdtr_res # test that results are equal (0.6367187499999999, 0.6367187499999999) `nbdtrc` can evaluate different parameter sets by providing arrays with shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute the function for three different `k` at four locations `p`, resulting in a 3x4 array. >>> k = np.array([[5], [10], [15]]) >>> p = np.array([0.3, 0.5, 0.7, 0.9]) >>> k.shape, p.shape ((3, 1), (4,)) >>> nbdtrc(k, 5, p) array([[8.49731667e-01, 3.76953125e-01, 4.73489874e-02, 1.46902600e-04], [5.15491059e-01, 5.92346191e-02, 6.72234070e-04, 9.29610100e-09], [2.37507779e-01, 5.90896606e-03, 5.55025308e-06, 3.26346760e-13]]) Ú