0

我正在使用 R 中的累积概率分布函数 pbeta() 来查找输入值 (p) 从 0-1 的概率。我只对那些给出概率在 0.025 和 0.975 之间的输入值的子集感兴趣(这是我的数据的置信区间)。

我最初的方法是列出 0 到 1 之间的 99 个值并在它们上运行 pbeta(),然后提取那些输出在正确范围内的值:

alpha <- 50 # Set values for the other two pbeta() parameters.
beta <- 100

p <- c(seq(from=0.01, to=0.99, by=0.01)) # Inputs must be between 0.01 and 0.99 inclusive, so evaluate 99 points in that range.
pbeta_outputs <- c(rep(0,99)) # A vector to hold the pbeta() output.

for (i in seq(1:length(p)) ) { # Fill pbeta_outputs using pbeta().
  pbeta_outputs[i] <- pbeta(p[i], shape1=alpha, shape2=beta)
}

probabilities <- data.frame(p, pbeta_outputs) # Arrange inputs and outputs in a data frame.
probabilities_keep <- subset(probabilities, pbeta_outputs>=0.025 & pbeta_outputs<=0.975)  # Subset to keep only inputs with outputs in the right range.

但是,这是不精确的。相反,我想直接计算将在正确范围内产生 pbeta() 输出的输入值范围。

就像是:

successful_inputs <- find_input_range(pbeta(x, shape1=alpha, shape2=beta), 0.025:0.975)

有这样的功能吗?

4

1 回答 1

0

看来你要找的是qbeta什么?

alpha <- 50
beta <- 100

# get lower bound 
(lb <- qbeta(0.025, shape1 = alpha, shape2 = beta))
# [1] 0.2603782

# get upper bound
(ub <- qbeta(0.975, shape1 = alpha, shape2 = beta))
# [1] 0.4104985

pbeta(ub, shape1 = alpha, shape2 = beta) - pbeta(lb, shape1 = alpha, shape2 = beta)
# [1] 0.95
于 2021-01-11T12:52:40.943 回答