R:找到给出一定输出范围的函数的输入范围
R: finding the range of inputs for a function that give a certain range of outputs
我正在使用 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)
有这样的功能吗?
你要找的好像是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
我正在使用 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)
有这样的功能吗?
你要找的好像是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