Skip to content

Analysis for a vector of values fails #28

@mattansb

Description

@mattansb

I'm trying to compute a power curve, and came across this rather off behavior - when providing d as a vector, the function fails, but supplying each element of d separately does not:

library(pwr)

d <- seq(0.05, 1.2, length.out = 25)
pwr.t.test(d = d, power = 0.8)$n
#> Warning in if (is.na(f.lower)) stop("f.lower = f(lower) is NA"): the condition
#> has length > 1 and only the first element will be used
#> Warning in if (is.na(f.upper)) stop("f.upper = f(upper) is NA"): the condition
#> has length > 1 and only the first element will be used
#> Error in uniroot(function(n) eval(p.body) - power, c(2 + 1e-10, 1e+09)): f() values at end points not of opposite sign

sapply(d, function(.d) pwr.t.test(d = .d, power = 0.8)$n)
#>  [1] 6280.04894 1638.24246  739.07484  419.13283  269.74754  188.15814
#>  [7]  138.77956  106.64471   84.56849   68.75267   57.03626   48.11621
#> [13]   41.16893   35.65311   31.20120   27.55646   24.53518   22.00310
#> [19]   19.86028   18.03104   16.45725   15.09369   13.90466   12.86180
#> [25]   11.94226

Created on 2020-11-22 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions