如何从GLM输出中获取概率 [英] How to get probability from GLM output

查看:192
本文介绍了如何从GLM输出中获取概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我正非常困惑,因为我试图找出如何从R中的glm输出中计算出概率.我知道数据非常微不足道,但我非常希望能向您展示如何获取这样的输出的概率.我当时想尝试inv.logit(),但不知道将哪些变量放在方括号中.

I'm extremely stuck at the moment as I am trying to figure out how to calculate the probability from my glm output in R. I know the data is very insignificant but I would really love to be shown how to get the probability from an output like this. I was thinking of trying inv.logit() but didn't know what variables to put within the brackets.

数据来自入住率研究.我正在评估一种发夹方法相对于相机陷阱在检测3种物种(红松鼠,松貂和侵入性灰松鼠)方面的成功.我想看看是什么影响了各种物种的检测(或未检测到).一种假设是在该地点发现另一种重点物种会影响红松鼠的可探测性.鉴于松貂是红松鼠的天敌,而灰松鼠是竞争者,那么这两个物种在某个地点的存在可能会影响红松鼠的可探测性.

The data is from occupancy study. I'm assessing the success of a hair trap method versus a camera trap in detecting 3 species (red squirrel, pine marten and invasive grey squirrel). I wanted to see what affected detection (or non detection) of the various species. One hypotheses was the detection of another focal species at the site would affect the detectability of red squirrel. Given that pine marten is a predator of the red squirrel and that the grey squirrel is a competitor, the presence of those two species at a site might affect the detectability of the red squirrel.

这表明概率吗? inv.logit(-1.14 - 0.1322 * nonRS events)

 glm(formula = RS_sticky ~ NonRSevents_before1stRS, family = binomial(link = "logit"), data = data)
Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.7432  -0.7432  -0.7222  -0.3739   2.0361  
Coefficients:
                    Estimate Std. Error z value Pr(>|z|)  
(Intercept)              -1.1455     0.4677  -2.449   0.0143 *
NonRSevents_before1stRS  -0.1322     0.1658  -0.797   0.4255  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
   (Dispersion parameter for binomial family taken to be 1)
Null deviance: 34.575  on 33  degrees of freedom
   Residual deviance: 33.736  on 32  degrees of freedom
  (1 observation deleted due to missingness)
   AIC: 37.736
  Number of Fisher Scoring iterations: 5*

推荐答案

如果您要预测预测变量的指定值集合的响应概率,请执行以下操作:

If you want to predict the probability of response for a specified set of values of the predictor variable:

pframe <- data.frame(NonRSevents_before1stRS=4)
predict(fitted_model, newdata=pframe, type="response")

其中,fitted_modelglm()拟合的结果,该结果存储在变量中.您可能不熟悉R统计分析方法,即将拟合模型存储为对象/变量,然后对其应用不同的方法(summary()plot()predict()residuals() ,...)

where fitted_model is the result of your glm() fit, which you stored in a variable. You may not be familiar with the R approach to statistical analysis, which is to store the fitted model as an object/in a variable, then apply different methods to it (summary(), plot(), predict(), residuals(), ...)

  • 这显然只是一个虚构的示例:我不知道4是否是NonRSevents_before1stRS变量的合理值)
  • 您可以指定更多不同的值以同时进行预测(data.frame(NonRSevents_before1stRS=c(4,5,6,7,8)))
  • 如果您有多个预测变量,则必须为每个预测的每个预测变量指定一些值,例如data.frame(x=4:8,y=mean(orig_data$y), ...)
  • This is obviously only a made-up example: I don't know if 4 is a reasonable value for the NonRSevents_before1stRS variable)
  • you can specify more different values to do predictions for at the same time (data.frame(NonRSevents_before1stRS=c(4,5,6,7,8)))
  • if you have multiple predictors, you have to specify some value for every predictor for every prediction, e.g. data.frame(x=4:8,y=mean(orig_data$y), ...)

如果您想要原始数据集中观测值的预测概率,只需predict(fitted_model, type="response")

If you want the predicted probabilities for the observations in your original data set, just predict(fitted_model, type="response")

您是正确的,inv.logit()(来自一堆不同的软件包,不知道您使用的是哪个软件包)或plogis()(来自基数R,本质上是相同的)将从logit或log-转换为赔率标度是概率标度,所以

You're correct that inv.logit() (from a bunch of different packages, don't know which you're using) or plogis() (from base R, essentially the same) will translate from the logit or log-odds scale to the probability scale, so

plogis(predict(fitted_model))

也将起作用(predict默认提供链接功能[在这种情况下为logit/log-odds]比例的预测).

would also work (predict provides predictions on the link-function [in this case logit/log-odds] scale by default).

这篇关于如何从GLM输出中获取概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆