def cdf(self, val): return stdtr(self.df, (val - self.mu) / self.scale)
avar = float(40)**2 * (na / adof) nb = float(100) bdof = nb - 1 bbar = float(190) bvar = float(20)**2 * (nb / bdof) # Use scipy.stats.ttest_ind_from_stats. t2, p2 = ttest_ind_from_stats(abar, sqrt(avar), na, bbar, sqrt(bvar), nb, equal_var=False) print("ttest_ind_from_stats: t = %g p = %g" % (t2, p2)) # Use the formulas directly. tf = (abar - bbar - 7) / sqrt(avar / na + bvar / nb) dof = (avar / na + bvar / nb)**2 / (avar**2 / (na**2 * adof) + bvar**2 / (nb**2 * bdof)) #calculating p value of P(T > tf) pval = stdtr(dof, abs(tf)) print 't = %f p = %f dof = %f' % (tf, pval, dof) if pval < significance: print('It is unlikely to except null hypothesis!') else: print('Null hypothesis cannot be rejected!')