Skip to contents

Exam5.1 is used to show polynomial multiple regression with binomial response

References

  1. Stroup, W. W. (2012). Generalized Linear Mixed Models: Modern Concepts, Methods and Applications. CRC Press.

See also

Author

  1. Muhammad Yaseen (myaseen208@gmail.com)

  2. Adeela Munawar (adeela.uaf@gmail.com)

Examples


##---Sequential Fit of the logit Model
Exam5.1.glm.1 <-
  glm(
      formula    =  F/N~ X
    , family     =  quasibinomial(link = "logit")
    , data       =  DataSet5.1
    )
summary(Exam5.1.glm.1)
#> 
#> Call:
#> glm(formula = F/N ~ X, family = quasibinomial(link = "logit"), 
#>     data = DataSet5.1)
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)  0.24519    0.33246   0.738    0.475
#> X            0.04325    0.04178   1.035    0.321
#> 
#> (Dispersion parameter for quasibinomial family taken to be 0.1700061)
#> 
#>     Null deviance: 2.2947  on 13  degrees of freedom
#> Residual deviance: 2.1078  on 12  degrees of freedom
#> AIC: NA
#> 
#> Number of Fisher Scoring iterations: 3
#> 
library(parameters)
model_parameters(Exam5.1.glm.1)
#> Parameter   | Log-Odds |   SE |        95% CI | t(12) |     p
#> -------------------------------------------------------------
#> (Intercept) |     0.25 | 0.33 | [-0.40, 0.91] |  0.74 | 0.461
#> X           |     0.04 | 0.04 | [-0.04, 0.13] |  1.04 | 0.301
#> 
#> Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
#>   computed using a Wald t-distribution approximation.

## confint.default()   produce Wald Confidence interval as SAS produces
##---Likelihood Ratio test for Model 1
anova(object = Exam5.1.glm.1, test = "Chisq")
#> Analysis of Deviance Table
#> 
#> Model: quasibinomial, link: logit
#> 
#> Response: F/N
#> 
#> Terms added sequentially (first to last)
#> 
#> 
#>      Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL                    13     2.2947         
#> X     1  0.18694        12     2.1078   0.2944

library(aod)
#> 
#> Attaching package: ‘aod’
#> The following object is masked from ‘package:survival’:
#> 
#>     rats
WaldExam5.1.glm.1 <-
  wald.test(
      Sigma   = vcov(object = Exam5.1.glm.1)
    , b       = coef(object = Exam5.1.glm.1)
    , Terms   = 2
    , L       = NULL
    , H0      = NULL
    , df      = NULL
    , verbose = FALSE
  )

##---Sequential Fit of the logit Model quadratic terms involved
Exam5.1.glm.2 <-
  glm(
      formula    =  F/N~ X + I(X^2)
    , family     =  quasibinomial(link = "logit")
    , data       =  DataSet5.1
    )
summary( Exam5.1.glm.2 )
#> 
#> Call:
#> glm(formula = F/N ~ X + I(X^2), family = quasibinomial(link = "logit"), 
#>     data = DataSet5.1)
#> 
#> Coefficients:
#>              Estimate Std. Error t value Pr(>|t|)    
#> (Intercept) -0.490760   0.259704  -1.890 0.085427 .  
#> X            0.511312   0.107904   4.739 0.000611 ***
#> I(X^2)      -0.029975   0.006617  -4.530 0.000858 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for quasibinomial family taken to be 0.06293754)
#> 
#>     Null deviance: 2.29474  on 13  degrees of freedom
#> Residual deviance: 0.69489  on 11  degrees of freedom
#> AIC: NA
#> 
#> Number of Fisher Scoring iterations: 4
#> 
model_parameters( Exam5.1.glm.2 )
#> Parameter   | Log-Odds |       SE |         95% CI | t(11) |      p
#> -------------------------------------------------------------------
#> (Intercept) |    -0.49 |     0.26 | [-1.01,  0.01] | -1.89 | 0.059 
#> X           |     0.51 |     0.11 | [ 0.31,  0.73] |  4.74 | < .001
#> X^2         |    -0.03 | 6.62e-03 | [-0.04, -0.02] | -4.53 | < .001
#> 
#> Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
#>   computed using a Wald t-distribution approximation.

##---Likelihood Ratio test for Model Exam5.1.glm.2
anova(object = Exam5.1.glm.2, test = "Chisq")
#> Analysis of Deviance Table
#> 
#> Model: quasibinomial, link: logit
#> 
#> Response: F/N
#> 
#> Terms added sequentially (first to last)
#> 
#> 
#>        Df Deviance Resid. Df Resid. Dev  Pr(>Chi)    
#> NULL                      13    2.29474              
#> X       1  0.18694        12    2.10780   0.08481 .  
#> I(X^2)  1  1.41292        11    0.69489 2.157e-06 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

WaldExam5.1.glm.2 <-
  wald.test(
      Sigma   = vcov(object = Exam5.1.glm.2)
    , b       = coef(object = Exam5.1.glm.2)
    , Terms   = 3
    , L       = NULL
    , H0      = NULL
    , df      = NULL
    , verbose = FALSE
  )

##---Sequential Fit of the logit Model 5th power terms involved
Exam5.1.glm.3 <-
  glm(
      formula    =  F/N~ X + I(X^2) + I(X^3) + I(X^4) + I(X^5)
    , family     =  quasibinomial(link = "logit")
    , data       =  DataSet5.1
    )
summary(Exam5.1.glm.3)
#> 
#> Call:
#> glm(formula = F/N ~ X + I(X^2) + I(X^3) + I(X^4) + I(X^5), family = quasibinomial(link = "logit"), 
#>     data = DataSet5.1)
#> 
#> Coefficients:
#>               Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -0.2986616  0.3875977  -0.771    0.463
#> X            0.2081471  0.7703070   0.270    0.794
#> I(X^2)       0.0603239  0.4225246   0.143    0.890
#> I(X^3)      -0.0120650  0.0821621  -0.147    0.887
#> I(X^4)       0.0008276  0.0064076   0.129    0.900
#> I(X^5)      -0.0000223  0.0001714  -0.130    0.900
#> 
#> (Dispersion parameter for quasibinomial family taken to be 0.07609603)
#> 
#>     Null deviance: 2.29474  on 13  degrees of freedom
#> Residual deviance: 0.62181  on  8  degrees of freedom
#> AIC: NA
#> 
#> Number of Fisher Scoring iterations: 4
#> 
model_parameters(Exam5.1.glm.3)
#> Parameter   |  Log-Odds |       SE |        95% CI |  t(8) |     p
#> ------------------------------------------------------------------
#> (Intercept) |     -0.30 |     0.39 | [-1.08, 0.46] | -0.77 | 0.441
#> X           |      0.21 |     0.77 | [-1.30, 1.73] |  0.27 | 0.787
#> X^2         |      0.06 |     0.42 | [-0.76, 0.90] |  0.14 | 0.886
#> X^3         |     -0.01 |     0.08 | [-0.18, 0.15] | -0.15 | 0.883
#> X^4         |  8.28e-04 | 6.41e-03 | [-0.01, 0.01] |  0.13 | 0.897
#> X^5         | -2.23e-05 | 1.71e-04 | [ 0.00, 0.00] | -0.13 | 0.897
#> 
#> Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
#>   computed using a Wald t-distribution approximation.

## confint.default()   produce Wald Confidence interval as SAS produces
##---Likelihood Ratio test for Model 1
anova(object =  Exam5.1.glm.3, test = "Chisq")
#> Analysis of Deviance Table
#> 
#> Model: quasibinomial, link: logit
#> 
#> Response: F/N
#> 
#> Terms added sequentially (first to last)
#> 
#> 
#>        Df Deviance Resid. Df Resid. Dev Pr(>Chi)    
#> NULL                      13    2.29474             
#> X       1  0.18694        12    2.10780   0.1170    
#> I(X^2)  1  1.41292        11    0.69489 1.64e-05 ***
#> I(X^3)  1  0.07179        10    0.62310   0.3314    
#> I(X^4)  1  0.00000         9    0.62310   0.9952    
#> I(X^5)  1  0.00129         8    0.62181   0.8965    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

WaldExam5.1.glm.3 <-
  wald.test(
      Sigma   = vcov(object = Exam5.1.glm.3)
    , b       = coef(object = Exam5.1.glm.3)
    , Terms   = 6
    , L       = NULL
    , H0      = NULL
    , df      = NULL
    , verbose = FALSE
  )