Created
June 19, 2016 12:37
-
-
Save wulingyun/e48c95bf6fdf4c6831c304fb91fd6c04 to your computer and use it in GitHub Desktop.
Calculate P-value
This file contains 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
p_value <- function(cdf, z, params=numeric(0), side=0) | |
{ | |
n <- length(params) | |
p <- switch(n+1, | |
cdf(z), | |
cdf(z, params), | |
cdf(z, params[1], params[2]), | |
cdf(z, params[1], params[2], params[3]) | |
) | |
if (side < 0) p | |
else if (side > 0) 1-p | |
else if (p < 1/2) 2*p | |
else 2*(1-p) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment