-
Notifications
You must be signed in to change notification settings - Fork 7
Description
See output below. The culprit is in example confIntR. The error is due to a logical condition that has length > 1.
Package: userfriendlyscience 0.7.2
Flags: --as-cran
Check: examples, Result: ERROR
Running examples in 'userfriendlyscience-Ex.R' failed
The error most likely occurred in:
base::assign(".ptime", proc.time(), pos = "CheckExEnv")
Name: confIntR
Title: A function to compute a correlation's confidence interval
Aliases: confIntR
Keywords: htest
** Examples
To request confidence intervals for one correlation
confIntR(.3, 100);
lo hi
0.3 0.1100677 0.4687942
attr(,"r")
[1] 0.3
attr(,"N")
[1] 100
attr(,"conf.level")
[1] 0.95The lower bound of a single correlation
confIntR(.3, 100)[1];
[1] 0.1100677To request confidence intervals for multiple correlations:
confIntR(c(.1, .3, .5), 250);
----------- FAILURE REPORT --------------
--- failure: length > 1 in coercion to logical ---
--- srcref ---
:
--- package (from environment) ---
userfriendlyscience
--- call from context ---
confIntR(c(0.1, 0.3, 0.5), 250)
--- call from argument ---
(r < -1) || (r > 1)
--- R stacktrace ---
where 1: confIntR(c(0.1, 0.3, 0.5), 250)
--- value of length: 3 type: logical ---
[1] FALSE FALSE FALSE
--- function from context ---
function (r, N, conf.level = 0.95, plot = FALSE)
{
if ((r < -1) || (r > 1)) {
stop("The specified observed correlation (argument 'r') must be between -1 and 1.")
}
if ((conf.level < 1e-06) || (conf.level >= 1)) {
stop("The specified desired confidence level (argument 'conf.level') must be between .000001 and 1.")
}
if (any(N < 4)) {
stop("The specified sample size (argument 'N') must be at least 4.")
}
if ((length(r) > 1) && (length(N) > 1)) {
stop("Sorry, current implementation only vectorized over either r of N!")
}
Z <- qnorm(1 - (1 - conf.level)/2)
se <- sqrt(1/((N - 3)))
zr <- log((1 + r)/(1 - r))/2
LL0 <- zr - Z * se
UL0 <- zr + Z * se
LL <- (exp(2 * LL0) - 1)/(exp(2 * LL0) + 1)
UL <- (exp(2 * UL0) - 1)/(exp(2 * UL0) + 1)
CI2w <- UL - LL
res <- matrix(c(LL, UL), byrow = FALSE, ncol = 2)
rownames(res) <- ifelseObj(length(N) > 1, N, r)
colnames(res) <- c("lo", "hi")
attr(res, "r") <- r
attr(res, "N") <- N
attr(res, "conf.level") <- conf.level
if (plot) {
if ((length(r) > 1) || (length(N) > 1) || (length(conf.level) >
1)) {
warning("I can only produce a plot if you supply only one value for ",
"arguments r, N, and conf.level!")
}
else {
df <- data.frame(r = seq(-1, 1, 0.001))
wHandler <- function(w) {
myWarnings <<- c(myWarnings, list(w))
invokeRestart("muffleWarning")
}
myWarnings <- NULL
df$density <- withCallingHandlers(SuppDists::dPearson(df$r,
N = N, rho = r), warning = wHandler)
cilo <- min(res)
cihi <- max(res)
rValue <- r
plot <- ggplot(df, aes(x = r, y = density)) + theme_bw() +
theme(axis.title.x.top = element_blank()) + scale_x_continuous(sec.axis = dup_axis(breaks = c(cilo,
rValue, cihi), labels = round(c(cilo, rValue,
cihi), 2))) + geom_vline(aes(xintercept = cilo),
linetype = "dashed") + geom_vline(aes(xintercept = rValue),
linetype = "dashed") + geom_vline(aes(xintercept = cihi),
linetype = "dashed") + geom_ribbon(data = df[df$r >=
min(res) & df$r <= max(res), ], aes(ymin = 0,
ymax = density), fill = "#cadded") + geom_segment(x = min(res),
xend = min(res), y = 0, yend = SuppDists::dPearson(min(res),
N = N, rho = r), color = "#2a5581", size = 1.5) +
geom_segment(x = max(res), xend = max(res), y = 0,
yend = SuppDists::dPearson(max(res), N = N,
rho = r), color = "#2a5581", size = 1.5) +
geom_line(size = 1.5)
attr(res, "plot") <- plot
class(res) <- "confIntR"
}
}
return(res)
}
<bytecode: 0x55c9246414f8>
<environment: namespace:userfriendlyscience>
--- function search by body ---
Function confIntR in namespace userfriendlyscience has this body.
----------- END OF FAILURE REPORT --------------
Fatal error: length > 1 in coercion to logical