def summary(self, yname=None, xname=None, title=None, alpha=0.05): df = pd.DataFrame() df["Type"] = (["Mean"] * self.k_exog + ["Scale"] * self.k_scale + ["Smooth"] * self.k_smooth + ["SD"] * self.k_noise) df["coef"] = self.params try: df["std err"] = np.sqrt(np.diag(self.cov_params())) except Exception: df["std err"] = np.nan from scipy.stats.distributions import norm df["tvalues"] = df.coef / df["std err"] df["P>|t|"] = 2 * norm.sf(np.abs(df.tvalues)) f = norm.ppf(1 - alpha / 2) df["[%.3f" % (alpha / 2)] = df.coef - f * df["std err"] df["%.3f]" % (1 - alpha / 2)] = df.coef + f * df["std err"] df.index = self.model.data.param_names summ = summary2.Summary() if title is None: title = "Gaussian process regression results" summ.add_title(title) summ.add_df(df) return summ
def mannwhitneyu(x, y, use_continuity=True): """ Computes the Mann-Whitney rank test on samples x and y. Parameters ---------- x, y : array_like Array of samples, should be one-dimensional. use_continuity : bool, optional Whether a continuity correction (1/2.) should be taken into account. Default is True. Returns ------- u : float The Mann-Whitney statistics. prob : float One-sided p-value assuming a asymptotic normal distribution. Notes ----- Use only when the number of observation in each sample is > 20 and you have 2 independent samples of ranks. Mann-Whitney U is significant if the u-obtained is LESS THAN or equal to the critical value of U. This test corrects for ties and by default uses a continuity correction. The reported p-value is for a one-sided hypothesis, to get the two-sided p-value multiply the returned p-value by 2. """ x = np.asarray(x) y = np.asarray(y) n1 = len(x) n2 = len(y) ranked = rankdata(np.concatenate((x,y))) rankx = ranked[0:n1] # get the x-ranks #ranky = ranked[n1:] # the rest are y-ranks u1 = n1*n2 + (n1*(n1+1))/2.0 - np.sum(rankx,axis=0) # calc U for x u2 = n1*n2 - u1 # remainder is U for y bigu = max(u1,u2) smallu = min(u1,u2) #T = np.sqrt(tiecorrect(ranked)) # correction factor for tied scores T = tiecorrect(ranked) if T == 0: raise ValueError('All numbers are identical in amannwhitneyu') sd = np.sqrt(T*n1*n2*(n1+n2+1)/12.0) if use_continuity: # normal approximation for prob calc with continuity correction z = (bigu-0.5-n1*n2/2.0) / sd else: z = (bigu-n1*n2/2.0) / sd # normal approximation for prob calc z *= int(u1<u2)-int(u1>u2) return z, norm.sf(abs(z)) #(1.0 - zprob(z))
def mannwhitneyu(self, x, y, use_continuity=True): x = asarray(x) y = asarray(y) n1 = len(x) n2 = len(y) ranked = rankdata(np.concatenate((x, y))) rankx = ranked[0:n1] # get the x-ranks u1 = n1 * n2 + (n1 * (n1 + 1)) / 2.0 - np.sum(rankx, axis=0) # calc U for x u2 = n1 * n2 - u1 # remainder is U for y bigu = max(u1, u2) smallu = min(u1, u2) T = tiecorrect(ranked) sd = np.sqrt(T * n1 * n2 * (n1 + n2 + 1) / 12.0) if use_continuity: # normal approximation for prob calc with continuity correction z = abs((bigu - 0.5 - n1 * n2 / 2.0) / sd) else: z = abs((bigu - n1 * n2 / 2.0) / sd) # normal approximation for prob calc p = norm.sf(z) return smallu, bigu, z, p