从广义线性模型输出中找到方程

机器算法验证 r 物流 广义线性模型
2022-03-01 07:45:17

假设我根据某个因素生成结果的概率并绘制该结果的曲线。有没有办法从 R 中提取该曲线的方程?

> mod = glm(winner~our_bid, data=mydat, family=binomial(link="logit"))
> summary(mod)

Call:
glm(formula = winner ~ our_bid, family = binomial(link = "logit"), 
    data = mydat)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.7443  -0.6083  -0.5329  -0.4702   2.3518  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept) -9.781e-01  2.836e-02  -34.49   <2e-16 ***
our_bid     -2.050e-03  7.576e-05  -27.07   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 42850  on 49971  degrees of freedom
Residual deviance: 42094  on 49970  degrees of freedom
AIC: 42098

Number of Fisher Scoring iterations: 4

> all.x <- expand.grid(winner=unique(winner), our_bid=unique(our_bid))
> all.x
> won = subset(all.x, winner == 1)
> y.hat.new <- predict(mod, newdata=won, type="response")
> options(max.print=5000000)
> y.hat.new
> plot(our_bid<-000:1000, predict(mod, newdata=data.frame(our_bid<-c(000:1000)),
       type="response"))

在此处输入图像描述

如何从这条概率曲线转到 R 中的方程?我希望有类似的东西:

Probability = -0.08*bid3 + 0.0364*bid2 - 0.0281*bid + 4E-14
1个回答

这个广义线性模型假设结果与独立值相关联x具有二项分布,其对数几率(“logit”)随x. 输出提供了该线性关系的系数;即,截距估计为 -0.9781,斜率(“our_bid”)估计为 -0.002050。您可以在列中看到它们Estimate

              Estimate Std. Error z value Pr(>|z|)    
(Intercept) -9.781e-01  2.836e-02  -34.49   <2e-16 ***
our_bid     -2.050e-03  7.576e-05  -27.07   <2e-16 ***

您希望绘制的概率与对数几率有关

probability=11+exp(log odds).

R 将此称为“逆 logit”函数inv.logit

把这些放在一起给出了等式

probability=11+exp([0.97810.00205x]).

绘制它的 R 命令将是

plot(inv.logit(-0.9781 - 0.00205*(0:1000)))

绘图输出

通常,您应该使用命令提取这些系数,coefficients而不是转录它们(就像我在这里所做的那样,因为我无权访问您的数据)。