R : Finding x value (predictor) for a particular y value (outcome)中的回归(物流)

标签 r regression linear-regression logistic-regression predict

我已经安装了逻辑回归模型,该模型可以根据vs(mpg数据集)预测二进制结果mtcars。该图如下所示。如何确定任何特定mpg值的vs值?例如,当mpg的概率为0.50时,我有兴趣找出vs的值是多少。感谢任何人都能提供的帮助!

model <- glm(vs ~ mpg, data = mtcars, family = binomial)

ggplot(mtcars, aes(mpg, vs)) + 
    geom_point() + 
    stat_smooth(method = "glm", method.args = list(family = "binomial"), se = FALSE)

enter image description here

最佳答案

从模型计算预测值的最简单方法是使用predict()函数。然后,您可以使用数值求解器查找特定的截距。例如

findInt <- function(model, value) {
    function(x) {
        predict(model, data.frame(mpg=x), type="response") - value
     }
}

uniroot(findInt(model, .5), range(mtcars$mpg))$root
# [1] 20.52229

在这里,findInt仅获取模型和特定目标值,并返回uniroot可以将其求解为0的函数以找到您的解决方案。

关于R : Finding x value (predictor) for a particular y value (outcome)中的回归(物流),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32040504/

相关文章:

python-3.x - CSV 文件无法上传

r - 为什么线性拟合的结果在 R 和 Excel(Gnumeric Spreadsheet 和 WPS)中具有相同的小数据?

r - R_LIBS_USER 路径的争议

python - SKlearn 线性回归系数等于 0

matlab - 如何保存从 fitlm MATLAB 获得的估计系数

python-3.x - TensorFlow:实现均方误差

r - 应用函数来组合列

r - Slice_min 和 Slice_max 关系说明

r - 使用效果包自定义绘图

java - 多维多项式回归(最好是 C/C++、Java 或 Scala)