gpt4 book ai didi

r - 'predict' 函数的反函数

转载 作者:行者123 更新时间:2023-12-04 03:40:57 25 4
gpt4 key购买 nike

使用 predict()对于给定模型的自变量 ( y ) 的某个值,可以获得因变量 ( x ) 的预测值。是否有任何函数可以预测 x对于给定的 y ?

例如:

kalythos <- data.frame(x = c(20,35,45,55,70), 
n = rep(50,5), y = c(6,17,26,37,44))
kalythos$Ymat <- cbind(kalythos$y, kalythos$n - kalythos$y)
model <- glm(Ymat ~ x, family = binomial, data = kalythos)

如果我们想知道模型对 x=50 的预测值:
predict(model, data.frame(x=50), type = "response")

我想知道哪个 x使 y=30 , 例如。

最佳答案

看到之前的回答被删了。在您的情况下,假设 n=50 并且模型是二项式的,您将使用以下方法计算给定 y 的 x:

f <- function (y,m) {
(logit(y/50) - coef(m)[["(Intercept)"]]) / coef(m)[["x"]]
}
> f(30,model)
[1] 48.59833

但是这样做时,您最好咨询统计学家,向您展示如何计算逆预测区间。并且请考虑 VitoshKa 的考虑。

关于r - 'predict' 函数的反函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com