0

Suppose we have negative binomial regression model in R:

m <- glm.nb(y ~ x)

What is the command in R to find probabilities of y that range from 0 to 1, not y themselves?

When I use the command like this:

probability <- predict(m, type="response"), I get predicted y and not probabilities.

My question is quite similar to How to calculate the predicted probability of negative binomial regression model? But when I run the following commands:

pred.h<-predict(m,type="response")
dnbinom(792534,mu=pred.h,size=m$theta)

where 792534 is the first observation of dependent variable, I get probabilities for every observation of outcome variable

         1            2            3            4            5            6 
4.763196e-07 5.409430e-08 3.999267e-07 8.672610e-10 4.481641e-07 1.548581e-31 
           7            8            9           10           11           12 
3.098259e-07 2.911153e-07 1.731375e-09 2.400651e-07 4.392602e-08 2.199327e-09 
          13           14           15           16           17           18 
4.437677e-07 2.678018e-07 1.646381e-08 4.654534e-07 3.938709e-07 2.572744e-07 
          19           20           21           22           23           24 
4.295230e-07 3.471489e-07 2.534392e-09 9.193697e-08 3.734329e-07 5.906320e-09 
          25           26           27           28           29           30 
2.368572e-13 2.292800e-07 8.435525e-10 1.778143e-08 3.030395e-09 2.293454e-08 
          31           32           33           34           35           36 
4.656017e-07 8.053810e-08 3.768163e-07 1.884933e-09 4.654242e-07 1.768920e-29 
          37           38           39           40           41           42 
3.490976e-07 3.311783e-07 3.546619e-09 2.805352e-07 6.255972e-08 4.368247e-09 
          43           44           45           46           47           48 
4.630512e-07 3.033308e-07 2.524674e-08 4.530362e-07 4.220339e-07 2.406259e-07 
          49           50           51           52           53           54 
4.142676e-07 3.291634e-07 4.631608e-09 1.189092e-07 3.533991e-07 9.897595e-09 
          55           56           57           58           59           60 
1.108722e-12 2.690367e-07 1.633476e-09 2.690585e-08 5.303436e-09 3.338780e-08 
          61           62           63           64           65           66 
4.552991e-07 1.018253e-07 3.600328e-07 3.597844e-09 4.752712e-07 2.894009e-27 
          67           68           69           70           71           72 
3.782297e-07 3.619943e-07 6.331445e-09 3.148322e-07 8.472062e-08 7.673905e-09 
          73           74           75           76           77           78 
4.733339e-07 3.394596e-07 3.839896e-08 4.387887e-07 4.427396e-07 2.227789e-07 
          79           80           81           82           83           84 
3.945887e-07 3.081428e-07 8.440563e-09 1.508400e-07 3.337452e-07 1.674021e-08 
          85           86           87           88           89           90 
4.250431e-12 3.041795e-07 3.399963e-09 4.078206e-08 9.686920e-09 4.982663e-08 
          91           92           93           94           95           96 
4.616535e-07 8.265986e-08 3.715144e-07 4.039028e-09 4.743495e-07 1.207058e-25 
          97           98           99          100          101          102

and so on...

Is it correct?

Community
  • 1
  • 1
Sandra
  • 1
  • 1
  • @ Jota thank you so much but can you check my commands because I have doubts about their correctness? – Sandra Nov 03 '15 at 16:41
  • `pred.h` gives predicted means for the entire vector of data. `dnbinom(792534,mu=pred.h[1],size=m$theta)` gives the probability under the fitted model that the first observation is equal to its observed value (which will be tiny) – Ben Bolker Nov 03 '15 at 16:55
  • @Ben Bolker thanks a lot! But how to get probabilities for every observation of outcome variable? I´m a bit confused that I need every time include in command value of each observation like `792534`. I have 900 observations. – Sandra Nov 03 '15 at 19:15

0 Answers0