Created
March 30, 2026 08:34
-
-
Save Choumingzhao/58870c7519503234c3bc95f971f68a4d to your computer and use it in GitHub Desktop.
Calculate the critical value of Pearson's r for a given alpha and sample size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scipy.stats | |
| from math import sqrt | |
| def get_critical_r(alpha, n, two_tailed=True): | |
| """Calculate the critical value of Pearson's r for a given alpha and sample size. | |
| Args: | |
| alpha: The significance level. | |
| n: The sample size. | |
| two_tailed: Whether to return a two-tailed critical value. | |
| Returns: | |
| The critical value of Pearson's r. | |
| """ | |
| df = n - 2 | |
| if two_tailed: | |
| t = scipy.stats.t.ppf(1-alpha/2, df) | |
| else: | |
| t = scipy.stats.t.ppf(1-alpha, df) | |
| return t / sqrt(t**2 + df) | |
| get_critical_r(0.01, 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment