This document compares GLM and VGLM using simulated data with multiple predictors and Poisson-distributed responses, evaluating residuals and coefficients.
1 Comparative Analysis of GLM and VGLM Using Simulated Data
This document presents a comparative analysis of Generalized Linear Models (GLM) and Vector Generalized Linear Models (VGLM) using simulated data. I generate sample data with multiple predictor variables and response variables following a Poisson distribution. The analysis includes fitting GLM models separately for each response variable and fitting a VGLM model for all response variables simultaneously. Residuals and coefficient estimates are calculated and visualized for both models to evaluate their performance and differences.
Code
# Install and load VGAM package# install.packages("VGAM")library(VGAM)
Warning: package 'VGAM' was built under R version 4.3.1
# GLM Poisson regressionglm_model_y1 <-glm(y1 ~ x1 + x2 + x3 + x4 + x5, family = poisson, data = data)glm_model_y2 <-glm(y2 ~ x1 + x2 + x3 + x4 + x5, family = poisson, data = data)glm_model_y3 <-glm(y3 ~ x1 + x2 + x3 + x4 + x5, family = poisson, data = data)# Display summaries of each modelsummary(glm_model_y1)
Call:
glm(formula = y1 ~ x1 + x2 + x3 + x4 + x5, family = poisson,
data = data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.38517 0.08854 4.350 1.36e-05 ***
x1 0.43631 0.08834 4.939 7.86e-07 ***
x2 0.33736 0.07935 4.251 2.12e-05 ***
x3 0.08839 0.08044 1.099 0.272
x4 -0.01082 0.07788 -0.139 0.889
x5 -0.02852 0.07367 -0.387 0.699
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 136.120 on 99 degrees of freedom
Residual deviance: 93.069 on 94 degrees of freedom
AIC: 306.15
Number of Fisher Scoring iterations: 5
Code
summary(glm_model_y2)
Call:
glm(formula = y2 ~ x1 + x2 + x3 + x4 + x5, family = poisson,
data = data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.070123 0.109203 0.642 0.521
x1 0.663334 0.094500 7.019 2.23e-12 ***
x2 0.004192 0.095817 0.044 0.965
x3 -0.080928 0.092684 -0.873 0.383
x4 0.111971 0.082933 1.350 0.177
x5 0.517226 0.088189 5.865 4.49e-09 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 163.58 on 99 degrees of freedom
Residual deviance: 88.37 on 94 degrees of freedom
AIC: 283.95
Number of Fisher Scoring iterations: 5
Code
summary(glm_model_y3)
Call:
glm(formula = y3 ~ x1 + x2 + x3 + x4 + x5, family = poisson,
data = data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.176741 0.100730 1.755 0.07933 .
x1 0.008668 0.097943 0.089 0.92948
x2 0.641678 0.068253 9.401 < 2e-16 ***
x3 0.215410 0.081309 2.649 0.00807 **
x4 0.449104 0.085294 5.265 1.4e-07 ***
x5 -0.100219 0.076188 -1.315 0.18837
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 289.16 on 99 degrees of freedom
Residual deviance: 114.90 on 94 degrees of freedom
AIC: 290.69
Number of Fisher Scoring iterations: 5
Code
# Calculate residuals for each modelglm_residuals_y1 <-residuals(glm_model_y1, type ="deviance")glm_residuals_y2 <-residuals(glm_model_y2, type ="deviance")glm_residuals_y3 <-residuals(glm_model_y3, type ="deviance")# VGLM Poisson regressionvglm_model <-vglm(cbind(y1, y2, y3) ~ x1 + x2 + x3 + x4 + x5, family = poissonff, data = data)# Display summary of the VGLM modelsummary(vglm_model)