tomas - 2 months ago 21
R Question

# Extracting significance score from AER coeftest results in R

Calling

``````coeftest(m)
``````

returns
z test of coefficients:

``````         Estimate Std. Error  z value  Pr(>|z|)
lenDelta  0.26592    0.13038   2.0397   0.04138 *
-2|-1    -2.59586    0.24090 -10.7758 < 2.2e-16 ***
-1|0     -0.81155    0.13558  -5.9860 2.150e-09 ***
0|1       0.73271    0.13394   5.4706 4.486e-08 ***
1|2       1.98097    0.19182  10.3271 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
``````

I know I can access the individual numerical values with

``````coeftest(m)[1,4]
``````

From this I can get the significance code in a straightforward way.

However, how do I access the significance code string "*" associated with lenDelta?

The structure of the object is as follows

``````str(coeftest(m))
``````

returns the following output

`````` coeftest [1:5, 1:4] 0.266 -2.596 -0.812 0.733 1.981 ...
- attr(*, "dimnames")=List of 2
..\$ : chr [1:5] "lenDelta" "-2|-1" "-1|0" "0|1" ...
..\$ : chr [1:4] "Estimate" "Std. Error" "z value" "Pr(>|z|)"
- attr(*, "method")= chr "z test of coefficients"
``````

Complete reproducible example (sourced from here)

``````## data
library("foreign")
## model
library("MASS")
m <- polr(apply ~ pared + public + gpa, data = dat, Hess = TRUE)
## coefficient test
library("AER")
coeftest(m)
``````

Thanks

The `print` method for `coeftest` objects internally calls `printCoefmat` (just like the `summary` method for `lm` or `glm` objects). And this leverages the function `symnum`, by default using the cutpoints shown in the legend of coefficient tests/summaries.

To call this by hand you can do the following. (I'm using a simpler model here because I had problems accessing the data at the UCLA site.)

Fit a model:

``````m <- lm(dist ~ speed, data = cars)
``````

Extract the p-values from coeftest:

``````pv <- coeftest(m)[,4]
``````

Cut the p-values into significance groups:

``````symnum(pv, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " ")
)
## (Intercept)       speed
##           *         ***
## attr(,"legend")
## [1] 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
``````