Skip to content

Instantly share code, notes, and snippets.

View shandou's full-sized avatar

Shan Dou shandou

  • Vancouver, Canada
View GitHub Profile
@shandou
shandou / pearson_r_CI2
Last active May 30, 2018 06:23
pearson_r_CI2
import numpy as np
r = - 0.654 # Pearson's r from sampled data
z_prime = 0.5 * np.log((1 + r) / (1 - r))
n = 34 # Sample size
se = 1 / np.sqrt(n - 3) # Sample standard error
CI_lower = z_prime - z_critical * se
CI_upper = z_prime + z_critical * se
@shandou
shandou / pearson_r_CI.py
Created May 30, 2018 05:58
pearson_r_confidence_interval
import scipy.stats
import numpy as np
alpha = 0.05 / 2 # Two-tail test
z_critical = scipy.stats.norm.ppf(1 - alpha)
@shandou
shandou / pearson_r_t_test.py
Last active May 30, 2018 05:25
hypothesis test for population Pearson's r
import scipy.stats
n = 25 # Number of samples n
df = n - 2 # Degrees of freedom
alpha = 0.05 # Significant level
# Non-direction tests for computing t-critical value
t_critical = scipy.stats.t.ppf(1 - alpha / 2, df)