英文:
Calculating True Prevalence (when apparent prevalence estimates are too low or too high) - avoiding negative values in CIs or values >100%
问题
truePrev() 函数来自 prevalence 包,在提供单个 x 和 n 值时运行良好,但在提供数字向量时会失败。如何计算长度大于 1 的向量的真实患病率估计呢?
例如,这个代码运行良好:
library(prevalence)
truePrev(x = 142, n = 742, SE = 0.949, SP = 0.994)
但当我将数字向量分配给 x 和 n 时,会返回错误:
truePrev(x = c(142, 149, 06), n = c(742, 742, 742), SE = 0.90, SP = 0.90)
> "Error in if (!binom & sum(x) != n) stop('x does not sum to n') :
the condition has length > 1"
英文:
The truePrev () function from the prevalence package works well when supplied with single values of x and n; but fails when supplied with numeric vectors. How can i possibly compute true prevalence estimates for vectors of length >1 .
eg: this works well
library(prevalence)
truePrev(x = 142, n = 742, SE = 0.949, SP = 0.994)
but when I assign numeric vectors to x and n, it returns an error:
truePrev(x = c(142,149, 06), n = c(742,742,742), SE = 0.90, SP = 0.90)
> "Error in if (!binom & sum(x) != n) stop("'x' does not sum to 'n'") :
the condition has length > 1"
答案1
得分: 4
错误提示说明您正在使用的函数不是矢量化的。因此,您将不得不遍历值并针对每组值运行该函数,即:
v1 <- c(142, 149, 6)
v2 <- c(742, 742, 742)
mapply(function(x, n) {
truePrev(x = x, n = n, SE = 0.90, SP = 0.90)
}, v1, v2)
英文:
The error says that the function you are using is not vectorized. So you will have to loop over the values and run the function for each set of values, i.e.
v1 <- c(142, 149, 6)
v2 <- c(742, 742, 742)
mapply(function(x, n) {
truePrev(x = x, n = n, SE = 0.90, SP = 0.90)
}, v1, v2)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论