Skip to content

Commit

Permalink
Output error messages when computing values during plot generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jansim authored and boutinb committed Dec 18, 2023
1 parent edd1468 commit 529e782
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 49 deletions.
9 changes: 9 additions & 0 deletions R/commonPower.R
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,12 @@
alternative = alternative, method = METHOD
), class = "power.htest"))
}

.errorMessageUnsolvable <- function (errorObject) {
return(paste(
gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"),
gettext("Error Message:"),
errorObject,
sep = "\n"
))
}
12 changes: 6 additions & 6 deletions R/pwr_1p.R
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@
alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand Down Expand Up @@ -633,15 +633,15 @@
.pwrPTest(n = nn, p0 = p0, p = p, sig.level = alpha, alternative = alt)$power
}))
if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

z.delta <- try(sapply(nn, function(N) {
abs(2 * (asin(sqrt(.pwrPTest(n = N, p0 = p0, sig.level = alpha, power = power, alternative = alt)$p)) - asin(sqrt(p0))))
}))
if (jaspBase::isTryError(z.delta)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -719,7 +719,7 @@

y <- try(.pwrPTest(n = n, p0 = p0, p = pp, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
if (power < 0.999) {
Expand Down Expand Up @@ -798,7 +798,7 @@
alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n >= maxn && n >= ps$maxn) {
maxn <- ceiling(n * ps$max.scale)
Expand All @@ -815,7 +815,7 @@

y <- try(.pwrPTest(n = nn, p0 = p0, p = p1, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
16 changes: 9 additions & 7 deletions R/pwr_1var.R
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
rho = d, power = max(0.99, power), sig.level = alpha, alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand Down Expand Up @@ -644,16 +644,18 @@
z.pwr <- try(sapply(dd, function(delta) {
.pwrVarTest(n = nn, rho = delta, sig.level = alpha, alternative = alt)$power
}))

if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

z.delta <- try(sapply(nn, function(N) {
.pwrVarTest(n = N, sig.level = alpha, power = power, alternative = alt)$rho
}))
if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))

if (jaspBase::isTryError(z.delta)) {
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -734,7 +736,7 @@

y <- try(.pwrVarTest(n = n, rho = dd, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
cols <- ps$pal(ps$pow.n.levels)
Expand Down Expand Up @@ -790,7 +792,7 @@
)$n))

if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n >= maxn && n >= ps$maxn) {
maxn <- ceiling(n * ps$max.scale)
Expand All @@ -808,7 +810,7 @@

y <- try(.pwrVarTest(n = nn, rho = d, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
13 changes: 7 additions & 6 deletions R/pwr_2p.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand Down Expand Up @@ -421,8 +421,9 @@
alternative = alt
)$power
}))

if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

Expand All @@ -434,7 +435,7 @@
)$p1)) - asin(sqrt(p0))))
}))
if (jaspBase::isTryError(z.delta)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -537,7 +538,7 @@

y <- try(.pwr2P2NTest(n = n1, n.ratio = n_ratio, p0 = p0, p1 = pp, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
if (power < 0.999) {
Expand Down Expand Up @@ -684,7 +685,7 @@
)$n))

if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n1 >= maxn && n1 >= ps$maxn) {
maxn <- ceiling(n1 * ps$max.scale)
Expand All @@ -705,7 +706,7 @@
p0 = p0, p1 = p1, sig.level = alpha, alternative = alt
)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
13 changes: 7 additions & 6 deletions R/pwr_2var.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand Down Expand Up @@ -426,8 +426,9 @@
alternative = alt
)$power
}))

if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

Expand All @@ -441,7 +442,7 @@
)$rho
}))
if (jaspBase::isTryError(z.delta)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -548,7 +549,7 @@

y <- try(.pwr2Var2NTest(n = n1, n.ratio = n_ratio, rho = dd, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
cols <- ps$pal(ps$pow.n.levels)
Expand Down Expand Up @@ -696,7 +697,7 @@
alternative = alt
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n1 >= maxn && n1 >= ps$maxn) {
maxn <- ceiling(n1 * ps$max.scale)
Expand All @@ -718,7 +719,7 @@
rho = d, sig.level = alpha, alternative = alt
)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
13 changes: 7 additions & 6 deletions R/pwr_ttestis.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
alternative = alt
))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand Down Expand Up @@ -393,8 +393,9 @@
alternative = alt
)$power
}))

if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

Expand All @@ -408,7 +409,7 @@
)$d
}))
if (jaspBase::isTryError(z.delta)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -500,7 +501,7 @@

y <- try(.pwrT2NTest(n1 = n1, n2 = n2, d = dd, sig.level = alpha, alternative = alt)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
cols <- ps$pal(ps$pow.n.levels)
Expand Down Expand Up @@ -623,7 +624,7 @@
))

if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n1 >= maxn && n1 >= ps$maxn) {
maxn <- ceiling(n1 * ps$max.scale)
Expand All @@ -642,7 +643,7 @@
d = d, sig.level = alpha, alternative = alt
)$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
12 changes: 6 additions & 6 deletions R/pwr_ttestos.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
type = "one.sample"
)$n))
if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
}

Expand All @@ -568,15 +568,15 @@
pwr::pwr.t.test(n = nn, d = delta, sig.level = alpha, alternative = alt, type = "one.sample")$power
}))
if (jaspBase::isTryError(z.pwr)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.pwr))
return()
}

z.delta <- try(sapply(nn, function(N) {
pwr::pwr.t.test(n = N, sig.level = alpha, power = power, alternative = alt, type = "one.sample")$d
}))
if (jaspBase::isTryError(z.delta)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the Power Contour plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(z.delta))
return()
}

Expand Down Expand Up @@ -641,7 +641,7 @@

y <- try(pwr::pwr.t.test(n = n, d = dd, sig.level = alpha, alternative = alt, type = "one.sample")$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the power curve. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}
cols <- ps$pal(ps$pow.n.levels)
Expand Down Expand Up @@ -698,7 +698,7 @@
)$n))

if (jaspBase::isTryError(maxn)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(maxn))
return()
} else if (n >= maxn && n >= ps$maxn) {
maxn <- ceiling(n * ps$max.scale)
Expand All @@ -710,7 +710,7 @@

y <- try(pwr::pwr.t.test(n = nn, d = d, sig.level = alpha, alternative = alt, type = "one.sample")$power)
if (jaspBase::isTryError(y)) {
image$setError(gettext("The specified design leads to (an) unsolvable equation(s) while constructing the 'Power Curve by N' plot. Try to enter less extreme values for the parameters"))
image$setError(.errorMessageUnsolvable(y))
return()
}

Expand Down
Loading

0 comments on commit 529e782

Please sign in to comment.