'How to get p values for odds ratios from an ordinal regression in r
I am trying to get the p values for my odds ratio from an ordinal regression using r.
I previously constructed my p values on the log odds like this
scm <- polr(finaloutcome ~ Size_no + Hegemony + Committee, data = data3, Hess = TRUE)
(ctable <- coef(summary(scm)))
Calculate and store p value
p <- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE) * 2
## combined table
(ctable <- cbind(ctable, "p value" = p))
I created by odds ratios like this:
ci <- confint.default(scm)
exp(coef(scm))
## OR and CI
exp(cbind(OR = coef(scm), ci))
However, I am now unsure how to create the p values for the odds ratio. Using the previous method I got:
(ctable1 <- exp(coef(scm)))
p1 <- pnorm(abs(ctable1[, "t value"]), lower.tail = FALSE) * 2
(ctable <- cbind(ctable, "p value" = p1))
However i get the error: Error in ctable1[, "t value"] : incorrect number of dimensions
Odds ratio output sample:
| Size | Hegem | Committee |
|---|---|---|
| 9.992240e-01 | 6.957805e-02 | 1.204437e-01 |
Data sample:
| finaloutcome | Size_no | Committee | Hegemony | |
|---|---|---|---|---|
| 1 | 3 | 54 | 2 | 0 |
| 2 | 2 | 127 | 3 | 0 |
| 3 | 2 | 127 | 3 | 0 |
| 4 | 2 | 22 | 1 | 1 |
| 5 | 2 | 193 | 4 | 1 |
| 6 | 2 | 54 | 2 | 0 |
| 7 | NA | 11 | 1 | 1 |
| 8 | 3 | 54 | 2 | 0 |
| 9 | 3 | 22 | 1 | 1 |
| 10 | 2 | 53 | 3 | 1 |
| 11 | 2 | 53 | 3 | 1 |
| 12 | 2 | 53 | 3 | 1 |
| 13 | 2 | 53 | 3 | 1 |
| 14 | 2 | 53 | 3 | 1 |
| 15 | 2 | 53 | 3 | 1 |
| 16 | 2 | 120 | 3 | 0 |
| 17 | 2 | 120 | 3 | 0 |
| 18 | 1 | 22 | 1 | 1 |
| 19 | 1 | 22 | 1 | 1 |
| 20 | 2 | 193 | 4 | 1 |
| 21 | 2 | 193 | 4 | 1 |
| 22 | 2 | 193 | 4 | 1 |
| 23 | 2 | 12 | 4 | 1 |
| 24 | 2 | 35 | 1 | 1 |
| 25 | 1 | 193 | 4 | 1 |
| 26 | 1 | 164 | 4 | 1 |
| 27 | 1 | 12 | 4 | 1 |
| 28 | 2 | 12 | 4 | 1 |
| 29 | 2 | 193 | 4 | 1 |
| 30 | 2 | 54 | 2 | 0 |
| 31 | 2 | 193 | 4 | 1 |
| 32 | 2 | 193 | 4 | 1 |
| 33 | 2 | 54 | 2 | 0 |
| 34 | 2 | 12 | 4 | 1 |
| 35 | 2 | 22 | 1 | 1 |
| 36 | 4 | 53 | 3 | 1 |
| 37 | 2 | 35 | 1 | 1 |
| 38 | 1 | 193 | 4 | 1 |
| 39 | 5 | 54 | 2 | 0 |
| 40 | 7 | 164 | 4 | 1 |
| 41 | 5 | 54 | 2 | 0 |
| 42 | 1 | 12 | 4 | 1 |
| 43 | 7 | 193 | 4 | 1 |
| 44 | 2 | 193 | 4 | 1 |
| 45 | 2 | 193 | 4 | 1 |
| 46 | 2 | 193 | 4 | 1 |
| 47 | 2 | 193 | 4 | 1 |
| 48 | 2 | 193 | 4 | 1 |
| 49 | 2 | 12 | 4 | 1 |
| 50 | 2 | 22 | 1 | 1 |
| 51 | 2 | 12 | 4 | 1 |
| 52 | 2 | 12 | 4 | 1 |
| 53 | 6 | 13 | 1 | 1 |
| 54 | 6 | 13 | 1 | 1 |
| 55 | 6 | 13 | 1 | 1 |
| 56 | 6 | 12 | 4 | 1 |
| 57 | 2 | 193 | 4 | 1 |
| 58 | 3 | 12 | 4 | 1 |
| 59 | 1 | 12 | 4 | 1 |
| 60 | 1 | 12 | 4 | 1 |
| 61 | 8 | 35 | 1 | 1 |
| 62 | 2 | 193 | 4 | 1 |
| 63 | 8 | 35 | 1 | 1 |
| 64 | 6 | 30 | 2 | 1 |
| 65 | 8 | 12 | 4 | 1 |
| 66 | 4 | 12 | 4 | 1 |
| 67 | 5 | 30 | 2 | 1 |
| 68 | 5 | 54 | 2 | 0 |
| 69 | 7 | 12 | 4 | 1 |
| 70 | 5 | 12 | 4 | 1 |
| 71 | 5 | 54 | 2 | 0 |
| 72 | 5 | 193 | 4 | 1 |
| 73 | 5 | 193 | 4 | 1 |
| 74 | 5 | 54 | 2 | 0 |
| 75 | 5 | 54 | 2 | 0 |
| 76 | 1 | 11 | 1 | 1 |
| 77 | 3 | 22 | 1 | 1 |
| 78 | 3 | 12 | 4 | 1 |
| 79 | 6 | 12 | 4 | 1 |
| 80 | 2 | 22 | 1 | 1 |
| 81 | 8 | 193 | 4 | 1 |
| 82 | 8 | 193 | 4 | 1 |
| 83 | 4 | 193 | 4 | 1 |
| 84 | 2 | 193 | 4 | 1 |
| 85 | 2 | 193 | 4 | 1 |
| 86 | 2 | 193 | 4 | 1 |
| 87 | 2 | 193 | 4 | 1 |
| 88 | 2 | 193 | 4 | 1 |
| 89 | 2 | 193 | 4 | 1 |
| 90 | 2 | 193 | 4 | 1 |
| 91 | 2 | 193 | 4 | 1 |
| 92 | 2 | 193 | 4 | 1 |
| 93 | 8 | 193 | 4 | 1 |
| 94 | 6 | 12 | 4 | 1 |
| 95 | 5 | 12 | 4 | 1 |
| 96 | 5 | 12 | 4 | 1 |
| 97 | 5 | 12 | 4 | 1 |
| 98 | 5 | 12 | 4 | 1 |
| 99 | 5 | 12 | 4 | 1 |
| 100 | 5 | 12 | 4 | 1 |
Solution 1:[1]
I usually use lm or glm to create my model (mdl <- lm(…) or mdl <- glm(…)). Then I use summary on the object to see these values. More than this, you can use the Yardstick and Broom. I recommend the book R for Data Science. There is a great explanation about modeling and using the Tidymodels packages.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gregory Oliveira |
