我正在尝试使用我之前多次使用过的脚本使用copula,但突然因为函数safeUroot而出现错误。它表示找不到该功能,即使它似乎是定义的。任何人都可以帮助解释我为什么会遇到这个错误以及如何克服这个错误。这只适用于安装Frank copula时 - 其他copula似乎有效。
> FrankFit = fitCopula(archmCopula("frank"), pseudo)
Error in FUN(X[[i]], ...) : could not find function "safeUroot"
> safeUroot
function (f, interval, ..., lower = min(interval), upper = max(interval),
f.lower = f(lower, ...), f.upper = f(upper, ...), Sig = NULL,
check.conv = FALSE, tol = .Machine$double.eps^0.25, maxiter = 1000,
trace = 0)
{
if (is.null(Sig) && f.lower * f.upper > 0 || is.numeric(Sig) &&
(Sig * f.lower > 0 || Sig * f.upper < 0)) {
if (trace)
cat(sprintf("search in [%g,%g]%s", lower, upper,
if (trace >= 2)
"\n"
else " ... "))
Delta <- function(u) 0.01 * pmax(1e-07, abs(u))
if (is.null(Sig)) {
delta <- Delta(c(lower, upper))
while (isTRUE(f.lower * f.upper > 0) && any(iF <- is.finite(c(lower,
upper)))) {
if (iF[1])
f.lower <- f(lower <- lower - delta[1])
if (iF[2])
f.upper <- f(upper <- upper + delta[2])
if (trace >= 2)
cat(sprintf(" .. modified lower,upper: (%15g,%15g)\n",
lower, upper))
delta <- 2 * delta
}
}
else {
delta <- Delta(lower)
while (isTRUE(Sig * f.lower > 0)) {
f.lower <- f(lower <- lower - delta)
if (trace)
cat(sprintf(" .. modified lower: %g\n", lower))
delta <- 2 * delta
}
delta <- Delta(upper)
while (isTRUE(Sig * f.upper < 0)) {
f.upper <- f(upper <- upper + delta)
if (trace)
cat(sprintf(" .. modified upper: %g\n", upper))
delta <- 2 * delta
}
}
if (trace && trace < 2)
cat(sprintf("extended to [%g, %g]\n", lower, upper))
}
if (!isTRUE(f.lower * f.upper <= 0))
stop("did not succeed extending the interval endpoints for f(lower) * f(upper) <= 0")
if (check.conv) {
r <- tryCatch(uniroot(f, ..., lower = lower, upper = upper,
f.lower = f.lower, f.upper = f.upper, tol = tol,
maxiter = maxiter), warning = function(w) w)
if (inherits(r, "warning"))
stop("convergence problem in zero finding: ", r$message)
else r
}
else uniroot(f, ..., lower = lower, upper = upper, f.lower = f.lower,
f.upper = f.upper, tol = tol, maxiter = maxiter)
}
<bytecode: 0x000000004464ff18>
<environment: namespace:copula>
>
如上所述,此前已多次使用,但今天已停止工作。