← all packages

pwr

no native code · R: 15 definitions, 1 typed strict, 4 gradual, prelude debt 12 · fuzzing: 1 definitions, 0 unsound, 0 accept calls outside their domain · tyr dc7f1a7 · Rsem 7bcb45f · NativeSem 770a1eb · rstt 2b2696f unpinned

R definitions

named top-level definitions
15 / 15 (100.0%)
not blocked by an unbound native symbol
15 / 15 (100.0%)
typed, gradual
4 / 15 (26.7%)
typed, strict
1 / 15 (6.7%)
12 of the strict failures are a name missing from the prelude.
mode
15 / 15

R definitions 15

R/ES.h.R

ES.h untypeabletyped

unbound variable (line 4)
unbound: sqrt — a name the prelude does not declare
error detail
name: sqrt
gradual mode: typed
((p1: any, p2: any) -> any)<>
timing: 0.016 s
source
"ES.h" <-
function (p1, p2) 
{
    2 * asin(sqrt(p1)) - 2 * asin(sqrt(p2))
}
R/ES.h.R:1
R/ES.w1.R

ES.w1 untypeabletyped

unbound variable (line 3)
unbound: sqrt — a name the prelude does not declare
error detail
name: sqrt
gradual mode: typed
((P0: dbl<~@"/", ...>, P1: dbl<~@"-", ~@"/", ...>) -> any)<>
timing: 2.97 s
source
"ES.w1" <-
function(P0,P1){
sqrt(sum((P1-P0)^2/P0))
}
R/ES.w1.R:1
R/ES.w2.R

ES.w2 untypeabletyped

unbound variable (line 3)
unbound: apply — a name the prelude does not declare
error detail
name: apply
gradual mode: typed
((P: any) -> any)<>
timing: 0.027 s
source
"ES.w2" <-
function(P){
pi<-apply(P,1,sum)
pj<-apply(P,2,sum)
P0<-pi%*%t(pj)
sqrt(sum((P-P0)^2/P0))
}
R/ES.w2.R:1
R/cohen.ES.R

cohen.ES typed fuzz ok

((test: (vec | null)?, size: (vec | null)?) -> { (CHR1<> | DBL1<>) | null })<>
timing: 0.402 s
fuzzing: 7 inside (1 ok, 6 error pkg) · 8 outside (8 rejected)

Other calls inside the domain

callverdicterror
cohen.ES("test" = NA, "size" = NULL)error_pkgbase::match.arg: 'arg' must be NULL or a character vector
cohen.ES("NA", 0L)error_pkgbase::match.arg: 'arg' should be one of “p”, “t”, “r”, “anov”, “chisq”, “f2”
cohen.ES("size" = c("x y", "é", "", NA_character_, "x y"))error_pkgbase::match.arg: 'arg' must be of length 1
cohen.ES(2, logical(0))error_pkgbase::match.arg: 'arg' must be NULL or a character vector
cohen.ES(integer(0), c(NA_complex_, complex(real = 1, imaginary = -2)))error_pkgbase::match.arg: 'arg' must be NULL or a character vector
cohen.ES(NULL, "x y")error_pkgbase::match.arg: 'arg' should be one of “small”, “medium”, “large”
source
"cohen.ES" <-
function(test=c("p","t","r","anov","chisq","f2"),size=c("small","medium","large")){
test <- match.arg(test)
size <- match.arg(size)
ntest <- switch(test, p = 1, t = 2,r=3,anov=4,chisq=5,f2=6)
if(ntest==1){
ES<-switch(size,small=0.2,medium=0.5,large=0.8)
}
if(ntest==2){
ES<-switch(size,small=0.2,medium=0.5,large=0.8)
}
if(ntest==3){
ES<-switch(size,small=0.1,medium=0.3,large=0.5)
}
if(ntest==4){
ES<-switch(size,small=0.1,medium=0.25,large=0.4)
}
if(ntest==5){
ES<-switch(size,small=0.1,medium=0.3,large=0.5)
}
if(ntest==6){
ES<-switch(size,small=0.02,medium=0.15,large=0.35)
}

METHOD <- "Conventional effect size from Cohen (1982)"
structure(list(test = test,size=size,effect.size=ES,
method = METHOD), class = "power.htest")
}
R/cohen.ES.R:1
R/pwr.2p.test.R

pwr.2p.test untypeable

unbound variable (line 14)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 2.18 s
source
"pwr.2p.test" <-
function (h = NULL, n = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided","less","greater"))
{
    if (sum(sapply(list(h, n, power, sig.level), is.null)) !=
        1)
        stop("exactly one of h, n, power, and sig.level must be NULL")
    if (!is.null(h) && is.character(h))
        h <- cohen.ES(test="p",size=h)$effect.size
    if (!is.null(n) && any(n < 1))
        stop("number of observations in each group must be at least 1")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    alternative <- match.arg(alternative)
    tside <- switch(alternative, less = 1, two.sided = 2, greater=3)
    if (tside == 2 && !is.null(h))
        h <- abs(h)
    if (tside == 3) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = FALSE) - h * sqrt(n/2),
                lower = FALSE)
        })
    }
    if (tside == 2) {
        p.body <- quote({
            pnorm(qnorm(sig.level/2, lower = FALSE) - h * sqrt(n/2),
                lower = FALSE) + pnorm(qnorm(sig.level/2, lower = TRUE) -
                h * sqrt(n/2), lower = TRUE)
        })
    }
    if (tside ==1) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = TRUE) - h * sqrt(n/2),
                lower = TRUE)
        })
    }

    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(h)){
        if(tside==2)
            h <- uniroot(function(h) eval(p.body) - power, c(1e-10,10))$root
        if(tside==1)
            h <- uniroot(function(h) eval(p.body) - power, c(-10,5))$root
        if(tside==3)
            h <- uniroot(function(h) eval(p.body) - power, c(-5,10))$root
    }
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power,
            c(2 + 1e-10, 1e+09))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    NOTE <- "same sample sizes"
    METHOD <- "Difference of proportion power calculation for binomial distribution (arcsine transformation)"
    structure(list(h = h, n = n, sig.level = sig.level, power = power,
        alternative = alternative, method = METHOD, note = NOTE),
        class = "power.htest")
}
R/pwr.2p.test.R:1
R/pwr.2p2n.test.R

pwr.2p2n.test untypeable

unbound variable (line 16)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 2.61 s
source
"pwr.2p2n.test" <-
function (h = NULL, n1 = NULL, n2 = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided", "less","greater"))
{
    if (sum(sapply(list(h, n1, n2, power, sig.level), is.null)) !=
        1)
        stop("exactly one of h, n1, n2, power, and sig.level must be NULL")
    if (!is.null(h) && is.character(h))
        h <- cohen.ES(test="p",size=h)$effect.size
    if (!is.null(n1) && any(n1 < 2))
        stop("number of observations in the first group must be at least 2")
    if (!is.null(n2) && any(n2 < 2))
        stop("number of observations in the second group must be at least 2")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    alternative <- match.arg(alternative)
    tside <- switch(alternative, less = 1, two.sided = 2,greater=3)
    if (tside == 2 && !is.null(h))
        h <- abs(h)
    if (tside == 3) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = FALSE) - h * sqrt((n1 *
                n2)/(n1 + n2)), lower = FALSE)
        })
    }
    if (tside == 1) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = TRUE) - h * sqrt((n1 *
                n2)/(n1 + n2)), lower = TRUE)
        })
    }

     if (tside == 2)  {
        p.body <- quote({
            pnorm(qnorm(sig.level/2, lower = FALSE) - h * sqrt((n1 *
                n2)/(n1 + n2)), lower = FALSE) + pnorm(qnorm(sig.level/2,
                lower = TRUE) - h * sqrt((n1 * n2)/(n1 + n2)),
                lower = TRUE)
        })
    }
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(h)){
        if(tside==2)
            h <- uniroot(function(h) eval(p.body) - power, c(1e-10,10))$root
        if(tside==1)
            h <- uniroot(function(h) eval(p.body) - power, c(-10,5))$root
        if(tside==3)
            h <- uniroot(function(h) eval(p.body) - power, c(-5,10))$root
    }
    else if (is.null(n1))
        n1 <- uniroot(function(n1) eval(p.body) - power,
            c(2 + 1e-10, 1e+09))$root
    else if (is.null(n2))
        n2 <- uniroot(function(n2) eval(p.body) - power,
            c(2 + 1e-10, 1e+09))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    NOTE <- "different sample sizes"
    METHOD <- "difference of proportion power calculation for binomial distribution (arcsine transformation)"
    structure(list(h = h, n1 = n1, n2 = n2, sig.level = sig.level,
        power = power, alternative = alternative, method = METHOD,
        note = NOTE), class = "power.htest")
}
R/pwr.2p2n.test.R:1
R/pwr.anova.test.R

pwr.anova.test untypeable

unbound variable (line 19)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 2.06 s
source
"pwr.anova.test" <-
function (k = NULL, n = NULL, f = NULL, sig.level = 0.05, power = NULL)
{
    if (sum(sapply(list(k, n, f, power, sig.level), is.null)) !=
        1)
        stop("exactly one of k, n, f, power, and sig.level must be NULL")
    if (!is.null(f)){
        if (is.character(f))
            f <- cohen.ES(test="anov",size=f)$effect.size
        if (any(f < 0))
            stop("f must be positive")
    }
    if (!is.null(k) && any(k < 2))
        stop("number of groups must be at least 2")
    if (!is.null(n) && any(n < 2))
        stop("number of observations in each group must be at least 2")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    p.body <- quote({
        lambda <- k * n * f^2
        pf(qf(sig.level, k - 1, (n - 1) * k, lower = FALSE),
            k - 1, (n - 1) * k, lambda, lower = FALSE)
    })
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(k))
        k <- uniroot(function(k) eval(p.body) - power, c(2 + 1e-10, 100))$root
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power, c(2 + 1e-10, 1e+09))$root
    else if (is.null(f))
        f <- uniroot(function(f) eval(p.body) - power, c(1e-07, 1e+07))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    NOTE <- "n is number in each group"
    METHOD <- "Balanced one-way analysis of variance power calculation"
    structure(list(k = k, n = n, f = f, sig.level = sig.level,
        power = power, note = NOTE, method = METHOD), class = "power.htest")
}
R/pwr.anova.test.R:1
R/pwr.chisq.test.R

pwr.chisq.test untypeable

unbound variable (line 17)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 1.84 s
source
"pwr.chisq.test" <-
function (w = NULL, N = NULL, df = NULL, sig.level = 0.05, power = NULL)
{
    if (sum(sapply(list(w, N, df, power, sig.level), is.null)) !=
        1)
        stop("exactly one of w, N, df, power, and sig.level must be NULL")
    if (!is.null(w)){
        if (is.character(w))
            w <- cohen.ES(test="chisq",size=w)$effect.size
        if (any(w < 0))
            stop("w must be positive")
    }
    if (!is.null(N) && any(N < 1))
        stop("number of observations must be at least 1")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    p.body <- quote({
        k <- qchisq(sig.level, df = df, lower = FALSE)
        pchisq(k, df = df, ncp = N * w^2, lower = FALSE)
    })
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(w))
        w <- uniroot(function(w) eval(p.body) - power, c(1e-10, 1e+09))$root
    else if (is.null(N))
        N <- uniroot(function(N) eval(p.body) - power, c(1 + 1e-10, 1e+09))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    METHOD <- "Chi squared power calculation"
    NOTE <- "N is the number of observations"
    structure(list(w = w, N = N, df = df, sig.level = sig.level,
        power = power, method = METHOD, note = NOTE), class = "power.htest")
}
R/pwr.chisq.test.R:1
R/pwr.norm.test.R

pwr.norm.test untypeable

unbound variable (line 14)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 1.95 s
source
"pwr.norm.test" <-
function (d = NULL, n = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided","less","greater"))
{
    if (sum(sapply(list(d, n, power, sig.level), is.null)) !=
        1)
        stop("exactly one of d, n, power, and sig.level must be NULL")
    if (!is.null(d) && is.character(d))
        d <- cohen.ES(test="t",size=d)$effect.size
    if (!is.null(n) && any(n < 1))
        stop("number of observations in each group must be at least 1")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    alternative <- match.arg(alternative)
    tside <- switch(alternative, less = 1, two.sided = 2, greater=3)
    if (tside == 2 && !is.null(d))
        d <- abs(d)
    if (tside == 2) {
        p.body <- quote({
            pnorm(qnorm(sig.level/2, lower = FALSE) - d * sqrt(n),
                lower = FALSE) + pnorm(qnorm(sig.level/2, lower = TRUE) -
                d * sqrt(n), lower = TRUE)
        })
    }
    if (tside==1) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = TRUE) - d * sqrt(n),
                lower = TRUE)
        })
    }

    if (tside==3) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = FALSE) - d * sqrt(n),
                lower = FALSE)
        })
    }

    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(d)) {
    	if (tside == 2)
            d <- uniroot(function(d) eval(p.body) - power, c(1e-10, 10))$root
        if (tside == 1)
            d <- uniroot(function(d) eval(p.body) - power, c(-10, 5))$root
        if (tside == 3)
            d <- uniroot(function(d) eval(p.body) - power, c(-5, 10))$root
	}
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power, c(1 + 1e-10, 1e+09))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
					c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    METHOD <- "Mean power calculation for normal distribution with known variance"
    structure(list(d = d, n = n, sig.level = sig.level, power = power,
        alternative = alternative, method = METHOD), class = "power.htest")
}
R/pwr.norm.test.R:1
R/pwr.p.test.R

pwr.p.test untypeable

unbound variable (line 14)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 1.92 s
source
"pwr.p.test" <-
function (h = NULL, n = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided","less","greater"))
{
    if (sum(sapply(list(h, n, power, sig.level), is.null)) !=
        1)
        stop("exactly one of h, n, power, and sig.level must be NULL")
    if (!is.null(h) && is.character(h))
        h <- cohen.ES(test="p",size=h)$effect.size
    if (!is.null(n) && any(n < 1))
        stop("number of observations in each group must be at least 1")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    alternative <- match.arg(alternative)
    tside <- switch(alternative, less = 1, two.sided = 2, greater=3)
    if (tside == 2 && !is.null(h))
        h <- abs(h)
    if (tside == 2) {
        p.body <- quote({
            pnorm(qnorm(sig.level/2, lower = FALSE) - h * sqrt(n),
                lower = FALSE) + pnorm(qnorm(sig.level/2, lower = TRUE) -
                h * sqrt(n), lower = TRUE)
        })
    }
    if (tside == 3) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = FALSE) - h * sqrt(n),
                lower = FALSE)
        })
    }
    if (tside == 1) {
        p.body <- quote({
            pnorm(qnorm(sig.level, lower = TRUE) - h * sqrt(n),
                lower = TRUE)
        })
    }
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(h)){
        if(tside==2)
            h <- uniroot(function(h) eval(p.body) - power, c(1e-10,10))$root
        if(tside==1)
            h <- uniroot(function(h) eval(p.body) - power, c(-10,5))$root
        if(tside==3)
            h <- uniroot(function(h) eval(p.body) - power, c(-5,10))$root
    }
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power, c(2 + 1e-10, 1e+09))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    METHOD <- "proportion power calculation for binomial distribution (arcsine transformation)"
    structure(list(h = h, n = n, sig.level = sig.level, power = power,
        alternative = alternative, method = METHOD), class = "power.htest")
}
R/pwr.p.test.R:1
R/pwr.r.test.R

pwr.r.test untypeable

unbound variable (line 12)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 1.95 s
source
"pwr.r.test" <-
function (n = NULL, r = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided", "less","greater"))
{
    if (sum(sapply(list(n, r, power, sig.level), is.null)) !=
        1)
        stop("exactly one of n, r, power, and sig.level must be NULL")
    if (!is.null(r) && is.character(r))
        r <- cohen.ES(test="r",size=r)$effect.size
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    if (!is.null(n) && any(n < 4))
        stop("number of observations must be at least 4")
    alternative <- match.arg(alternative)
    tside <- switch(alternative, less = 1, two.sided = 2,greater=3)
    if (tside == 2 && !is.null(r))
        r <- abs(r)
    if (tside == 3) {
        p.body <- quote({
            ttt <- qt(sig.level, df = n - 2, lower = FALSE)
            rc <- sqrt(ttt^2/(ttt^2 + n - 2))
            zr <- atanh(r) + r/(2 * (n - 1))
            zrc <- atanh(rc) # + rc/(2 * (n - 1))
            pnorm((zr - zrc) * sqrt(n - 3))
        })
    }
    if (tside == 1) {
        p.body <- quote({
            r<--r
            ttt <- qt(sig.level, df = n - 2, lower = FALSE)
            rc <- sqrt(ttt^2/(ttt^2 + n - 2))
            zr <- atanh(r) + r/(2 * (n - 1))
            zrc <- atanh(rc) # + rc/(2 * (n - 1))
            pnorm((zr - zrc) * sqrt(n - 3))
        })
    }

    if (tside == 2) {
        p.body <- quote({
            ttt <- qt(sig.level/2, df = n - 2, lower = FALSE)
            rc <- sqrt(ttt^2/(ttt^2 + n - 2))
            zr <- atanh(r) + r/(2 * (n - 1))
            zrc <- atanh(rc) # + rc/(2 * (n - 1))
            pnorm((zr - zrc) * sqrt(n - 3)) + pnorm((-zr - zrc) *
                sqrt(n - 3))
        })
    }
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power, c(4 +
            1e-10, 1e+09))$root
    else if (is.null(r)){
        if(tside==2)
            r <- uniroot(function(r) eval(p.body) - power,
                c(1e-10,1 - 1e-10))$root
        else
            r <- uniroot(function(r) eval(p.body) - power,
                c(-1+1e-10, 1 - 1e-10))$root
    }
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    METHOD <- "approximate correlation power calculation (arctangh transformation)"
    structure(list(n = n, r = r, sig.level = sig.level, power = power,
        alternative = alternative, method = METHOD), class = "power.htest")
}
R/pwr.r.test.R:1
R/pwr.t.test.R

pwr.t.test skipped

error detail
Failure("Unsupported positional argument after a named one.")
timing: 0.005 s
source
"pwr.t.test" <-
function (n = NULL, d = NULL, sig.level = 0.05, power = NULL,
    type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided",
        "less","greater"))
{
    if (sum(sapply(list(n, d, power, sig.level), is.null)) !=
        1)
        stop("exactly one of n, d, power, and sig.level must be NULL")
    if (!is.null(d) && is.character(d))
        d <- cohen.ES(test="t",size=d)$effect.size
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    type <- match.arg(type)
    alternative <- match.arg(alternative)
    tsample <- switch(type, one.sample = 1, two.sample = 2, paired = 1)
    ttside<-switch(alternative, less = 1, two.sided = 2, greater=3)
    tside <- switch(alternative, less = 1, two.sided = 2, greater =1)
    if (tside == 2 && !is.null(d))
        d <- abs(d)
    if (ttside == 1) {
        p.body <- quote({
            nu <- (n - 1) * tsample
            pt(qt(sig.level/tside, nu, lower = TRUE), nu,
                ncp = sqrt(n/tsample) * d, lower = TRUE)
        })
    }
    if (ttside == 2)  {
        p.body <- quote({
            nu <- (n - 1) * tsample
            qu <- qt(sig.level/tside, nu, lower = FALSE)
            pt(qu, nu, ncp = sqrt(n/tsample) * d, lower = FALSE) +
                pt(-qu, nu, ncp = sqrt(n/tsample) * d, lower = TRUE)
        })
    }
	if (ttside == 3) {
        p.body <- quote({
            nu <- (n - 1) * tsample
            pt(qt(sig.level/tside, nu, lower = FALSE), nu,
                ncp = sqrt(n/tsample) * d, lower = FALSE)
        })
    }

    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(n))
        n <- uniroot(function(n) eval(p.body) - power, c(2 +
            1e-10, 1e+09))$root
    else if (is.null(d)) {
        if(ttside==2)
            d <- uniroot(function(d) eval(p.body) - power, c(1e-07, 10))$root
        if(ttside==1)
            d <- uniroot(function(d) eval(p.body) - power, c(-10, 5))$root
        if(ttside==3)
            d <- uniroot(function(d) eval(p.body) - power, c(-5, 10))$root
    }
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
					c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    NOTE <- switch(type, paired = "n is number of *pairs*", two.sample = "n is number in *each* group",
        NULL)
    METHOD <- paste(switch(type, one.sample = "One-sample", two.sample = "Two-sample",
        paired = "Paired"), "t test power calculation")
    structure(list(n = n, d = d, sig.level = sig.level, power = power,
        alternative = alternative, note = NOTE, method = METHOD),
        class = "power.htest")
}
R/pwr.t.test.R:1
R/pwr.t2n.test.R

pwr.t2n.test untypeable

unbound variable (line 13)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 2.46 s
source
"pwr.t2n.test" <-
function (n1 = NULL, n2= NULL, d = NULL, sig.level = 0.05, power = NULL,
 alternative = c("two.sided",
        "less","greater"))
{
    if (sum(sapply(list(n1,n2, d, power, sig.level), is.null)) !=
        1)
        stop("exactly one of n1, n2, d, power, and sig.level must be NULL")
    if (!is.null(d) && is.character(d))
        d <- cohen.ES(test="t",size=d)$effect.size
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
   if (!is.null(n1) && any(n1 < 2))
        stop("number of observations in the first group must be at least 2")
     if (!is.null(n2) && any(n2 < 2))
        stop("number of observations in the second group must be at least 2")

    alternative <- match.arg(alternative)
    tsample <-2
    ttside<-switch(alternative, less = 1, two.sided = 2, greater=3)
    tside <- switch(alternative, less = 1, two.sided = 2, greater =1)
    if (tside==2 &&  !is.null(d))
        d <- abs(d)
    if (ttside == 1) {
        p.body <- quote({
            nu <- n1+n2-2
            pt(qt(sig.level/tside, nu, lower = TRUE), nu,
                ncp = d*(1/sqrt(1/n1+1/n2)), lower = TRUE)
        })
    }
    if (ttside == 2)  {
        p.body <- quote({
           nu <- n1+n2-2
            qu <- qt(sig.level/tside, nu, lower = FALSE)
            pt(qu, nu, ncp = d*(1/sqrt(1/n1+1/n2)), lower = FALSE) +
                pt(-qu, nu,ncp = d*(1/sqrt(1/n1+1/n2)), lower = TRUE)
        })
    }
	if (ttside == 3) {
        p.body <- quote({
           nu <- n1+n2-2
            pt(qt(sig.level/tside, nu, lower = FALSE), nu,
                ncp = d*(1/sqrt(1/n1+1/n2)), lower = FALSE)
        })
    }

    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(n1))
        n1 <- uniroot(function(n1) eval(p.body) - power,
            c(2 + 1e-10, 1e+09))$root
    else if (is.null(n2))
        n2 <- uniroot(function(n2) eval(p.body) - power,
            c(2 + 1e-10, 1e+09))$root
    else if (is.null(d)) {
        if(ttside==2)
            d <- uniroot(function(d) eval(p.body) - power, c(1e-07, 10))$root
        if(ttside==1)
            d <- uniroot(function(d) eval(p.body) - power, c(-10, 5))$root
        if(ttside==3)
            d <- uniroot(function(d) eval(p.body) - power, c(-5, 10))$root
    }
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
      METHOD <- c("t test power calculation")
    structure(list(n1 = n1,n2=n2, d = d, sig.level = sig.level, power = power,
        alternative = alternative,method = METHOD),
        class = "power.htest")
}
R/pwr.t2n.test.R:1
R/plot.power.htest.R

plot.power.htest skipped

error detail
Failure("Unsupported positional argument after a named one.")
timing: 0.019 s
source
plot.power.htest <- function (x, ...){
  # initial checks
  if (class(x) != 
      "power.htest") 
    stop("argument must be of class power.htest")
  pwr.methods <- c("One-sample t test power calculation", "Two-sample t test power calculation", "Paired t test power calculation", "t test power calculation", "Difference of proportion power calculation for binomial distribution (arcsine transformation)", "difference of proportion power calculation for binomial distribution (arcsine transformation)", "Balanced one-way analysis of variance power calculation", "Chi squared power calculation", "Mean power calculation for normal distribution with known variance", "proportion power calculation for binomial distribution (arcsine transformation)", "approximate correlation power calculation (arctangh transformation)")
  if(!(x$method %in% pwr.methods))
    stop(paste("the method ", x$method, " is not supported. Supported methods include:", paste(pwr.methods, collapse = "; ")))
  
  # settings
  breaks <- 20
  
  # case: One-sample, Two-sample or Paired t test
  if(x$method == "One-sample t test power calculation" || x$method == "Two-sample t test power calculation" || x$method == "Paired t test power calculation")
  {
    if(x$method == "One-sample t test power calculation"){x$type = "one.sample"}
    if(x$method == "Two-sample t test power calculation"){x$type = "two.sample"}
    if(x$method == "Paired t test power calculation"){x$type = "paired"}
    n <- x$n
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.t.test(n=ss, d=x$d, sig.level = x$sig.level, type=x$type, alternative = x$alternative)$power)
    }, simplify = TRUE)
    
    # create labels
    title_string <- x$method
    legend_string <- paste("tails =", x$alternative, "\neffect size d =", x$d, "\nalpha =", x$sig.level
    )
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", ceiling(n), "\n", x$note, sep = "")
  }
  
  # case: Two-sample t test with n1 and n2
  else if(x$method == "t test power calculation")
  {
    n <- x$n1 + x$n2
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    n_rel <- x$n1 / n # relative sample size; will be kept constant in claculations
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      n1 <- ceiling(ss*n_rel)
      n2 <- ss - n1
      if(n1 <2 || n2 <2){
        return(NA)
      }else{
        return(pwr.t2n.test(n1=n1, n2=n2, d=x$d, sig.level = x$sig.level, alternative = x$alternative)$power)
      }
    }, simplify = TRUE)
    
    # create labels
    title_string <- x$method
    legend_string <- paste("tails =", x$alternative, "\neffect size d =", x$d, "\nalpha =", x$sig.level, "\nn1/n2 = ", round(n_rel, 2))
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", x$n1, " + ", x$n2, " = ", n, sep = "")
  }
  
  # case: Difference of proportion (same sample size)
  else if(x$method == "Difference of proportion power calculation for binomial distribution (arcsine transformation)")
  {
    n <- x$n
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.2p.test(n=ss, h=x$h, sig.level = x$sig.level, alternative = x$alternative)$power)
    }, simplify = TRUE)
    
    # create labels
    title_string <- "Difference of proportion power calculation\nfor binomial distribution (arcsine transformation)"  
    
    legend_string <- paste("tails =", x$alternative, "\neffect size h =", x$h, "\nalpha =", x$sig.level
    )
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", ceiling(n), "\n", x$note, sep = "")
  }
  
  # case: difference of proportion (different sample size)
  else if(x$method == "difference of proportion power calculation for binomial distribution (arcsine transformation)")
  {
    n <- x$n1 + x$n2
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    n_rel <- x$n1 / n # relative sample size; will be kept constant in claculations
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      n1 <- ceiling(ss*n_rel)
      n2 <- ss - n1
      if(n1 <2 || n2 <2){
        return(NA)
      }else{
        return(pwr.2p2n.test(n1=n1, n2=n2, h=x$h, sig.level = x$sig.level, alternative = x$alternative)$power)
      }
    }, simplify = TRUE)
    
    # create labels
    title_string <- "Difference of proportion power calculation\nfor binomial distribution (arcsine transformation)"
    legend_string <- paste("tails =", x$alternative, "\neffect size h =", x$h, "\nalpha =", x$sig.level, "\nn1/n2 = ", round(n_rel, 2))
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", x$n1, " + ", x$n2, " = ", n, sep = "")
    
  }
  
  
  # case: ANOVA
  else if(x$method == "Balanced one-way analysis of variance power calculation")
  {
    n <- x$n
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.anova.test(n=ss, k=x$k, f=x$f, sig.level = x$sig.level)$power)
    }, simplify = TRUE)
    
    # create labels
    title_string <- "Balanced one-way analysis of variance \npower calculation"
    legend_string <- paste("groups k =", x$k, "\neffect size f =", x$f, "\nalpha =", x$sig.level
    )
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", ceiling(n), "\n", x$note, sep = "")
    
  }
  
  # case: Chi Squared
  else if(x$method == "Chi squared power calculation")
  {
    n <- x$N
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.chisq.test(N=ss, w=x$w, sig.level = x$sig.level, df=x$df)$power)
    }, simplify = TRUE)
    
    # create labels
    title_string <- x$method
    legend_string <- paste("effect size w =", x$w, "\ndf =", x$df, "\nalpha =", x$sig.level)
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nN = ", ceiling(n), "\n", x$note, sep = "")
    
  }
  
  
  # case: Normal distribution
  else if(x$method == "Mean power calculation for normal distribution with known variance")
  {
    n <- x$n
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.norm.test(n=ss, d=x$d, sig.level = x$sig.level, alternative = x$alternative)$power)
    }, simplify = TRUE)
    
    # create labels
    title_string <- "Mean power calculation for normal distribution\nwith known variance"
    legend_string <- paste("tails =", x$alternative, "\neffect size d =", x$d, "\nalpha =", x$sig.level
    )
    xlab_string <- "sample size"
    ylab_string <- expression(paste("test power = 1 - ", beta))
    optimal_string <- paste("optimal sample size \nn = ", ceiling(n), "\n", x$note, sep = "")
    
  }
  
  
  
  # case: proportion
  else if(x$method == "proportion power calculation for binomial distribution (arcsine transformation)")
  {
    n <- x$n
    n_upper <- max(n*1.5, n+30) # upper at least 30 above n
    
    # generate data
    sample_sizes <- seq.int(from=10, to=n_upper, by=(n_upper - 10)/breaks)
    data <- data.frame(sample_sizes)
    data$power <- sapply(sample_sizes, FUN = function(ss) {
      return(pwr.p.test(n=ss, h=x$h, sig.level = x$sig.level, alternative = x$alternative)$power)
    }, simplify = TRUE)
R/plot.power.htest.R:1
R/pwr.f2.test.R

pwr.f2.test untypeable

unbound variable (line 19)
unbound: sQuote — a name the prelude does not declare
error detail
name: sQuote
timing: 2.07 s
source
"pwr.f2.test" <-
function (u = NULL, v = NULL, f2 = NULL, sig.level = 0.05, power = NULL)
{
    if (sum(sapply(list(u,v, f2, power, sig.level), is.null)) !=
        1)
        stop("exactly one of u, v, f2, power, and sig.level must be NULL")
    if (!is.null(f2)){
        if (is.character(f2))
            f2 <- cohen.ES(test="f2",size=f2)$effect.size
        if (any(f2 < 0))
            stop("f2 must be positive")
    }
    if (!is.null(u) && any(u < 1))
        stop("degree of freedom u for numerator must be at least 1")
    if (!is.null(v) && any(v < 1))
        stop("degree of freedom v for denominator must be at least 1")
    if (!is.null(sig.level) && !is.numeric(sig.level) || any(0 >
        sig.level | sig.level > 1))
        stop(sQuote("sig.level"), " must be numeric in [0, 1]")
    if (!is.null(power) && !is.numeric(power) || any(0 > power |
        power > 1))
        stop(sQuote("power"), " must be numeric in [0, 1]")
    p.body <- quote({
        lambda <- f2*(u+v+1)
        pf(qf(sig.level, u, v, lower = FALSE),
            u, v, lambda, lower = FALSE)
    })
    if (is.null(power))
        power <- eval(p.body)
    else if (is.null(u))
        u <- uniroot(function(u) eval(p.body) - power, c(1 + 1e-10, 100))$root
    else if (is.null(v))
        v <- uniroot(function(v) eval(p.body) - power, c(1 + 1e-10, 1e+09))$root
    else if (is.null(f2))
        f2 <- uniroot(function(f2) eval(p.body) - power, c(1e-07, 1e+07))$root
    else if (is.null(sig.level))
        sig.level <- uniroot(function(sig.level) eval(p.body) - power,
            c(1e-10, 1 - 1e-10))$root
    else stop("internal error")
    METHOD <- "Multiple regression power calculation"
    structure(list(u = u, v = v, f2 = f2, sig.level = sig.level,
        power = power, method = METHOD), class = "power.htest")
}
R/pwr.f2.test.R:1