sig: Significance tests for a binary regression models fit with...

Description Usage Arguments Value Note See Also Examples

View source: R/sig.R

Description

Significance tests for a binary regression models fit with glm

Usage

1
2
3
4
sig(x, ...)

## S3 method for class 'glm'
sig(x, ..., test = c("var", "coef"))

Arguments

x

A regression model with class glm and x$family$family == "binomial".

...

Not used.

test

What to test.

  • If test="var" (the default), will test significance for each variable in the model.
    This includes the intercept, if present.
    This means factors are tested for all levels simultaneously.

  • If test="coef", will test significance for each coefficient in the model.
    This means the 'dummy variables' created from factors will be tested individually.

Value

A list of data.tables as follows:

Wald

The Wald test for each coefficient which is:

W = B / SE[B]

This should be normally distributed.

LR

The likelihood ratio test for each coefficient:

LR = -2 * log(likelihood without / likelihood with variable)

which is:

LR = -2 * SUM(y * log(P / y) + (1 - y) * log((1 - P) / (1 - y)))

When comparing a fitted model to a saturated model (i.e. P[i]=y[i] and likelihood =1), the LR is referred to as the model deviance, D.

score

The score test, also known as the Rao, Cochran-Armitage trend and the Lagrange multiplier test.
This removes a variable from the model, then assesses the change. For logistic regression this is based on:

ybar = (SUM y[i]) / n

and

xbar = (SUM x[i] * n[i]) / n

The statistic is:

ST = SUM x[i](y[i] - ybar) / (ybar(1 - ybar) SUM (x[i] - xbar)^2)^0.5

If the value of the coefficient is correct, the test should follow a standard normal distribution.

Note

The result has the class "sig.glm". The print method for this class shows only the model coefficients and p values.

See Also

?aod::wald.test
?statmod::glm.scoretest
For corrected score tests:
?mdscore::mdscore

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
data(ageChd)
## H&L 2nd ed. Table 1.3. Page 10.
summary(g1 <- glm(chd ~ age, data=ageChd, family=binomial))
sig(g1)
data(lbw)
## Table 2.2. Page 36.
summary(g2 <- glm(LOW ~ AGE + LWT + RACE + FTV,
                  data=lbw, family=binomial))
sig(g2)
## Table 2.3. Pages 38-39.
summary(g3 <- glm(LOW ~ LWT + RACE,
                  data=lbw, family=binomial))
sig(g3, test="coef")
## RACE is more significant when dropped as a factor
##
sig(g3, test="var")

Example output

Call:
glm(formula = chd ~ age, family = binomial, data = ageChd)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.9718  -0.8456  -0.4576   0.8253   2.2859  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -5.30945    1.13365  -4.683 2.82e-06 ***
age          0.11092    0.02406   4.610 4.02e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 136.66  on 99  degrees of freedom
Residual deviance: 107.35  on 98  degrees of freedom
AIC: 111.35

Number of Fisher Scoring iterations: 4

                  Wald    LR      score    
(Intercept) 2.8203e-06 0e+00 1.3187e-07 ***
age         4.0224e-06 1e-07 2.7770e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Call:
glm(formula = LOW ~ AGE + LWT + RACE + FTV, family = binomial, 
    data = lbw)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.4163  -0.8931  -0.7113   1.2454   2.0755  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept)  1.295366   1.071443   1.209   0.2267  
AGE         -0.023823   0.033730  -0.706   0.4800  
LWT         -0.014245   0.006541  -2.178   0.0294 *
RACEblack    1.003898   0.497859   2.016   0.0438 *
RACEother    0.433108   0.362240   1.196   0.2318  
FTV         -0.049308   0.167239  -0.295   0.7681  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 234.67  on 188  degrees of freedom
Residual deviance: 222.57  on 183  degrees of freedom
AIC: 234.57

Number of Fisher Scoring iterations: 4

                Wald       LR      score    
(Intercept) 0.226666 1.000000   0.086463 .  
AGE         0.480006 0.476916   0.479345    
LWT         0.029418 0.021061   0.026406 *  
RACE        0.110204 0.109411 2.7152e-05 ***
FTV         0.768118 0.767082   0.768040    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Call:
glm(formula = LOW ~ LWT + RACE, family = binomial, data = lbw)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.3491  -0.8919  -0.7196   1.2526   2.0993  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept)  0.805753   0.845167   0.953   0.3404  
LWT         -0.015223   0.006439  -2.364   0.0181 *
RACEblack    1.081066   0.488052   2.215   0.0268 *
RACEother    0.480603   0.356674   1.347   0.1778  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 234.67  on 188  degrees of freedom
Residual deviance: 223.26  on 185  degrees of freedom
AIC: 231.26

Number of Fisher Scoring iterations: 4

                Wald       LR    score  
(Intercept) 0.340404 0.332365 0.339299  
LWT         0.018075 0.011396 0.015448 *
RACEblack   0.026756 0.027777 0.023101 *
RACEother   0.177832 0.177812 0.176423  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
                Wald       LR    score    
(Intercept) 0.340404 1.000000 0.231828    
LWT         0.018075 0.011396 0.015448 *  
RACE        0.067125 0.066153  2.2e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

LogisticDx documentation built on May 2, 2019, 6:15 p.m.