Convert between estimates, z-values, p-values, and confidence intervals

ci2se(lower, upper, conf.level = 0.95, ratio = FALSE)

ci2estimate(lower, upper, ratio = FALSE, antilog = FALSE)

ci2z(lower, upper, conf.level = 0.95, ratio = FALSE)

ci2p(lower, upper, conf.level = 0.95, ratio = FALSE, alternative = "two.sided")

z2p(z, alternative = "two.sided")

p2z(p, alternative = "two.sided")

Arguments

lower

Numeric vector of lower confidence interval bounds.

upper

Numeric vector of upper confidence interval bounds.

conf.level

The confidence level of the confidence intervals. Default is 0.95.

ratio

Indicates whether the confidence interval is for a ratio, e.g. an odds ratio, relative risk or hazard ratio. If TRUE, the standard error of the log ratio is computed. Defaults to FALSE.

antilog

Indicates whether the estimate is reported on the ratio scale. Only applies if ratio = TRUE. Defaults to FALSE.

alternative

Direction of the alternative of the p-value. Either "two.sided" (default), "one.sided", "less", or "greater". If "one.sided" or "two.sided" is specified, the z-value is assumed to be positive.

z

Numeric vector of z-values.

p

Numeric vector of p-values.

Value

ci2se returns a numeric vector of standard errors.

ci2estimate returns a numeric vector of parameter estimates.

ci2z returns a numeric vector of z-values.

ci2p returns a numeric vector of p-values.

z2p returns a numeric vector of p-values. The dimension of the output depends on the input. In general, the output will be an array of dimension c(nrow(z), ncol(z), length(alternative)). If any of these dimensions is 1, it will be dropped.

p2z returns a numeric vector of z-values. The dimension of the output depends on the input. In general, the output will be an array of dimension c(nrow(p), ncol(p), length(alternative)). If any of these dimensions is 1, it will be dropped.

Details

z2p is vectorized over all arguments.

p2z is vectorized over all arguments.

Examples

ci2se(lower = 1, upper = 3)
#> [1] 0.5102135
ci2se(lower = 1, upper = 3, ratio = TRUE)
#> [1] 0.2802634
ci2se(lower = 1, upper = 3, conf.level = 0.9)
#> [1] 0.6079568

ci2estimate(lower = 1, upper = 3)
#> [1] 2
ci2estimate(lower = 1, upper = 3, ratio = TRUE)
#> [1] 0.5493061
ci2estimate(lower = 1, upper = 3, ratio = TRUE, antilog = TRUE)
#> [1] 1.732051

ci2z(lower = 1, upper = 3)
#> [1] 3.919928
ci2z(lower = 1, upper = 3, ratio = TRUE)
#> [1] 1.959964
ci2z(lower = 1, upper = 3, conf.level = 0.9)
#> [1] 3.289707

ci2p(lower = 1, upper = 3)
#> [1] 8.857544e-05
ci2p(lower = 1, upper = 3, alternative = "one.sided")
#> [1] 4.428772e-05

z2p(z = c(1, 2, 5))
#> [1] 3.173105e-01 4.550026e-02 5.733031e-07
z2p(z = c(1, 2, 5), alternative = "less")
#> [1] 0.8413447 0.9772499 0.9999997
z2p(z = c(1, 2, 5), alternative = "greater")
#> [1] 1.586553e-01 2.275013e-02 2.866516e-07
z <- seq(-3, 3, by = 0.01)
plot(z, z2p(z), type = "l", xlab = "z", ylab = "p", ylim = c(0, 1))
lines(z, z2p(z, alternative = "greater"), lty = 2)
legend("topright", c("two-sided", "greater"), lty = c(1, 2), bty = "n")


p2z(p = c(0.005, 0.01, 0.05))
#> [1] 2.807034 2.575829 1.959964
p2z(p = c(0.005, 0.01, 0.05), alternative = "greater")
#> [1] 2.575829 2.326348 1.644854
p2z(p = c(0.005, 0.01, 0.05), alternative = "less")
#> [1] -2.575829 -2.326348 -1.644854
p <- seq(0.001, 0.05, 0.0001)
plot(p, p2z(p), type = "l", ylim = c(0, 3.5), ylab = "z")
lines(p, p2z(p, alternative = "greater"), lty = 2)
legend("bottomleft", c("two-sided", "greater"), lty = c(1, 2), bty = "n")