[R] Problem with contour(): typo

Helmut Schütz he|mut@@chuetz @end|ng |rom beb@c@@t
Tue Sep 29 12:43:29 CEST 2020


Dear Duncan,

Duncan Murdoch wrote on 2020-09-29 11:57:
> On 29/09/2020 5:37 a.m., Helmut Schütz wrote:
>> Here I'm lost. power.TOST(theta0, CV, ...) vectorizes properly for
>> theta0 _or_ CV but no _both_. Hence
>> library(PowerTOST)
>> power.TOST(theta0 = c(0.9, 0.95, 1), CV = 0.25, n = 28)
>> and
>> power.TOST(theta0 = 0.95, CV = c(0.2, 0.25, 0.3), n = 28)
>> work, whereas
>> power.TOST(theta0 = c(0.9, 0.95, 1), 0.95, CV = c(0.2, 0.25, 0.3), n 
>> = 28)
>> not. Of note, we will throw an error in the next release if both
>> arguments are vectors.
>
> I wouldn't do that, because it doesn't fit the usual R style. It's 
> very common for functions to allow vector inputs in several arguments, 
> and match up corresponding values to form a vector result.

I see. Here it would require to give the result as a matrix, 
data.frame,... Substantial change in the code though doable.

> If you want to use Vectorize, the command would be
>
>   power.TOST.vectorized <- Vectorize(power.TOST, c("theta0", "CV"))

library(PowerTOST)
theta0 <- unique(sort(c(0.95, seq(0.95*0.95, 1, length.out = 10))))
CV     <- unique(sort(c(0.25, seq(0.25*0.8, 0.25*1.2, length.out = 10))))
power.TOST.vectorized <- Vectorize(power.TOST, c("theta0", "CV", "n"))
and
power.TOST.vectorized(theta0 = theta0, CV = CV, n = 28)
gives the diagonal elements of the desired 11*11 matrix:
z <- matrix(ncol = length(theta0), nrow = length(CV))
for (i in seq_along(CV)) {
   z[i, ] <- power.TOST(theta0 = theta0, CV = CV[i], n = 28)
}

Helmut

-- 
Ing. Helmut Schütz
BEBAC – Consultancy Services for
Bioequivalence and Bioavailability Studies
Neubaugasse 36/11
1070 Vienna, Austria
E helmut.schuetz using bebac.at
W https://bebac.at/
F https://forum.bebac.at/



More information about the R-help mailing list