[R] Problem with contour(): typo
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Mon Sep 28 21:47:40 CEST 2020
You're doing a lot of manipulation of the z matrix; I haven't followed
all of it, but that's where I'd look for problems. Generally if you
keep your calculation of the z matrix very simple you are better off.
For example, once you have xs and ys in the form you want, calculate z as
z <- outer(x,y, function(x,y) ...)
and then plot it using contour(x, y, z, ...)
The only tricky issue here is that the function needs to be vectorized,
so if your power.TOST function doesn't accept vectors for CV and theta0,
you'll need to put it in a wrapper that does (perhaps using the
Vectorize function).
Duncan Murdoch
On 28/09/2020 3:08 p.m., Helmut Schütz wrote:
> Dear all,
>
> sorry, my last message contained a typo. Correct:
>
> library(PowerTOST)
> x <- 0.90
> y <- 0.35
> res <- as.numeric(sampleN.TOST(theta0 = x, CV = y, design = "2x2x4",
> method = "central", details = FALSE,
> print = FALSE)[7:8])
> mesh <- 28
> ys <- unique(sort(c(y, seq(y*.8, y*1.2, length.out = mesh))))
> xs <- unique(sort(c(x, seq(x*0.95, 1, length.out = mesh))))
> z <- matrix(nrow = length(ys), ncol = length(xs),
> dimnames = list(paste0("y.", signif(ys, 5)),
> paste0("x.", signif(xs, 5))))
> for (i in seq_along(ys)) {
> for (j in seq_along(xs)) {
> z[i, j] <- suppressMessages(
> power.TOST(CV = ys[i], theta0 = xs[j], design = "2x2x4",
> method = "central", n = res[1]))
> }
> }
> z <- z[nrow(z):1, ncol(z):1] # reverse rows & columns
> z[paste0("y.", y), paste0("x.", x)] == res[2] # should be TRUE
> contour(xs, ys, z, nlevels = 20, las = 1, labcex = 1,
> xlab = "x", ylab = "y", main = paste("n =", res[1]))
> abline(h = y, v = x, lty = 2)
> points(x, y, col = "red", cex = 1.5)
> text(x, y, labels = signif(z[paste0("y.", y), paste0("x.", x)], 6),
> col = "red", adj = c(-0.1, 1.5))
>
>
> Helmut
>
More information about the R-help
mailing list