Calculating True Prevalence (when apparent prevalence estimates are too low or too high) – avoiding negative values in CIs or values >100%

huangapple go评论59阅读模式
英文:

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 &lt;- c(142, 149, 6)
v2 &lt;- c(742, 742, 742)

mapply(function(x, n) {
  truePrev(x = x, n = n, SE = 0.90, SP = 0.90)
}, v1, v2)

huangapple
  • 本文由 发表于 2023年7月27日 22:18:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780671.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定