Beispiel #1
0
def RunResampleTest(firsts, others):
    """Tests differences in means by resampling.

    firsts: DataFrame
    others: DataFrame
    """
    data = firsts.prglngth.values, others.prglngth.values
    ht = DiffMeansResample(data)
    p_value = ht.PValue(iters=10000)
    print('\nmeans permute preglength')
    print('p-value =', p_value)
    print('actual =', ht.actual)
    print('ts max =', ht.MaxTestStat())

    data = (firsts.totalwgt_lb.dropna().values,
            others.totalwgt_lb.dropna().values)
    ht = hypothesis.DiffMeansPermute(data)
    p_value = ht.PValue(iters=10000)
    print('\nmeans permute birthweight')
    print('p-value =', p_value)
    print('actual =', ht.actual)
    print('ts max =', ht.MaxTestStat())
Beispiel #2
0
plt.hist(est_L, bins=max(est_L) - min(est_L) + 1)
plt.axvline(x=est_90ci[0], linewidth=2, color='r', label="90% CI")
plt.axvline(x=est_90ci[1], linewidth=2, color='r')
plt.suptitle("Simulated sample distribution of estimated L (lambda)")
plt.title("time interval distribution=exponential; lambda=" + str(lam) +
          "; simulation size=10000",
          fontsize=9)
plt.xlabel("Estimated L (lambda)")
plt.ylabel("Frequency")
plt.legend()
# ci_str = "90% CI ["+str(round(est_90ci[0], 2))+","+str(round(est_90ci[1], 2))+"]"
# plt.text(0, 10, "mean error "+str(round(meanError, 4))+"\nRMSE "+str(round(RMSE, 4))+"\n"+ci_str+"\nSE "+str(round(np.array(est_L).std(), 4)))
plt.show()

# Q11. Think Stats Chapter 9 Exercise 2 (resampling)
first_len = live.loc[preg["birthord"] == 1, "prglngth"]
other_len = live.loc[preg["birthord"] != 1, "prglngth"]
data = first_len, other_len
ht_perm = h0.DiffMeansPermute(data)
pvalue_perm = ht_perm.PValue()
ht_resamp = DiffMeansResample(data)
pvalue_resamp = ht_resamp.PValue()

first_wt = live.loc[preg["birthord"] == 1, "totalwgt_lb"]
other_wt = live.loc[preg["birthord"] != 1, "totalwgt_lb"]
data = first_wt, other_wt
ht_perm = h0.DiffMeansPermute(data)
pvalue_perm = ht_perm.PValue()
ht_resamp = DiffMeansResample(data)
pvalue_resamp = ht_resamp.PValue()