Skip to content

Instantly share code, notes, and snippets.

@wulingyun
Created June 19, 2016 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wulingyun/e48c95bf6fdf4c6831c304fb91fd6c04 to your computer and use it in GitHub Desktop.
Save wulingyun/e48c95bf6fdf4c6831c304fb91fd6c04 to your computer and use it in GitHub Desktop.
Calculate P-value
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