<jupyter_start><jupyter_text>Examples from Albert's *Bayesian Computation in R*<jupyter_code>%matplotlib inline
import math
import matplotlib.pyplot as plt
import numpy as np
import numpy.random as random
import scipy.stats as stats
def tstat(x, y):
    m, n = len(x), len(y)
    
    # pooled standard deviation
    sp = np.sqrt(((m-1)*np.std(x)**2 + (n-1)*np.std(y)**2)/(m+n-2))
    return (np.mean(x) - np.mean(y)) / (sp * np.sqrt(1./m + 1./n))
x = stats.norm.rvs(loc=50,scale=10,size=10000)
y = stats.norm.rvs(loc=50,scale=100,size=10000)
x = random.randn(100000)*1 + 50
y = random.randn(100000)*1 + 50

print(tstat(x,y))

# scipy's version, using Welch, which does not assume equal variance
print(stats.ttest_ind(x, y, equal_var=False)[0])
print(stats.ttest_rel(x, y)[0])
np.std(x)
stats.ttest_ind(x, y, equal_var=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17309941520467836, 'fraction_numerical': 0.05380116959064327, 'mean_word_length': 5.028169014084507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '575502', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 386, 'n_tokens_neox': 351, 'n_words': 75, 'path': 'Albert-Bayesian_Computation.ipynb', 'repo_name': 'ngocfam/Bayses-tutorials', 'size': '855'}