Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 r 脚本中,我确实执行了一个 nls 来获得一个合适的值:
fit <- nls(...)
然后在那之后,我通过这样做来测试 nls 是否成功:
if(is.na(fit)) { print("succeeded") }
但我收到警告:
the condition has length > 1 and only the first element will be used
我做错了吗?如果是这样,我该怎么办?如果没有,我该如何删除警告?谢谢!
nls如果拟合失败,则会引发错误。所以,is.nullaftertry(nls(...))是正确的方法。
nls
is.null
try(nls(...))
这是我在对不确定数据使用nls拟合时使用的一段代码:
fit <- NULL while (TRUE) { start <- list(...) # try somewhat randomized initial parameter try(fit <- nls(..., start = start)) # performe nls if (!is.null(fit)) break; }