[英]How to identify cutoff in a logit GLM
Produce some data for logistic GLM: 为物流GLM生成一些数据:
set.seed(123)
x1 = rnorm(2000)
z = 1 + 3*x1 + 3*exp(x1)
pr = 1/(1+exp(-z))
y = rbinom(2000,1,pr)
df = data.frame(y=y,x1=x1)
Running the model: 运行模型:
mod <- glm(y ~ x1,data=df,family=binomial(link=logit))
Logit plot: Logit图:
library(visreg)
library(ggplot2)
visreg(mod, 'x1', scale='response', rug=2, gg=TRUE)+
theme_bw(18)
I need to calculate the cutoff of x1 which defines a 50% probability of being y=1. 我需要计算x1的截止值,它定义了y = 1的50%概率。 I guess I need the
predict
function: 我想我需要
predict
函数:
pred <- predict(mod, type = "response")
EDIT 编辑
As suggested below I found the cutoff; 如下所示,我找到了截止值; however, I would like to perform a ROC analysis in order to verify its specificity and sensibility.
但是,我想进行ROC分析以验证其特异性和敏感性。 Is it sufficient to run this code?
运行此代码是否足够?
prob=predict(mod,type=c("response"))
df$prob=prob
library(pROC)
g <- roc(y ~ prob, data = df)
plot(g)
g
You can use dose.p
from MASS
. 你可以使用
MASS
dose.p
Try out: 试用:
library(MASS)
dose.p(mod, p = 0.5)
# Dose SE
#p = 0.5: -0.8457261 0.02039277
Using predict
, x1[as.numeric(names(pred[round(pred, 2) == 0.5]))]
provide points from x1
that are close (to the nearest hundredth) to the cutoff 使用
predict
, x1[as.numeric(names(pred[round(pred, 2) == 0.5]))]
提供x1
中与截止点(最近的百分之一)的点
[1] -0.8497043 -0.8490611 -0.8445834 -0.8468964 -0.8491746
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.