VPSPulse Mirrors

High-Performance Open-Source Archive

decompose.model

decompose.model

As described in detail in Schoon, Melamed, and Breiger (2024), regression inside out entails understanding cases’ contributions to the regression model space. Decomposing regression coefficients by cases or subsets and model visualization techniques are the key tools of regression inside out. decompose.model takes a regression model object and a numeric grouping vector for the cases, and returns the contributions to the regression coefficients and model variances by the grouping vector. Currently supported models include OLS, logistic regression, Poisson regression, and negative binomial regression. An example of each is provided below.

OLS regression:

library(rioplot)
data(Kenworthy99)
m1 <- lm(scale(dv) ~ scale(gdp) + scale(pov) + scale(tran) -1,data=Kenworthy99)
decompose.model(m1,group.by = c(rep(1,5),rep(2,5),rep(3,5)),include.int = "no")
## $decomp.coef
##                       1          2           3 Model Coefs
## scale(gdp)   0.06957621 -0.2377652 -0.01424928  -0.1824382
## scale(pov)   0.09040885  0.4168041  0.27542047   0.7826334
## scale(tran) -0.06549782 -0.3406868 -0.03767758  -0.4438622
## 
## $decomp.var
##                       1          2           3 Model Variances
## scale(gdp)  0.007805959 0.01254747 0.003479965      0.02383339
## scale(pov)  0.007215453 0.01159828 0.003216712      0.02203044
## scale(tran) 0.006942633 0.01115974 0.003095086      0.02119746

Logistic regression:

data("Hilbe")
Hilbe <- data.frame(Hilbe,binAffairs=ifelse(Hilbe$naffairs>0,1,0)) 
m2<-glm(binAffairs ~ avgmarr + hapavg + vryhap + smerel + vryrel + yrsmarr4 + 
          yrsmarr5 + yrsmarr6,data=Hilbe, family=binomial())
decompose.model(m2,group.by = c(rep(1,201),rep(2,200),rep(3,200)),
                model.type = "logit")
## $decomp.coef
##                     1          2           3 Model Coefs
## Intercept  0.05971787 -0.1273528 -0.10348046  -0.1711154
## avgmarr   -0.24968851 -0.3694616 -0.16264481  -0.7817949
## hapavg    -0.38716522 -0.3343743 -0.31712921  -1.0386688
## vryhap    -0.49279971 -0.5384404 -0.51360407  -1.5448441
## smerel    -0.09356562 -0.4037141 -0.32915986  -0.8264395
## vryrel    -0.33019003 -0.1025715 -0.33405582  -0.7668174
## yrsmarr4   0.16396384  0.3400305 -0.08552834   0.4184660
## yrsmarr5   0.04293827  0.4087135  0.26864221   0.7202940
## yrsmarr6   0.06312812  0.1722334  0.37648895   0.6118505
## 
## $decomp.var
##                    1          2          3 Model Variances
## Intercept 0.03630495 0.02235802 0.02469380      0.08335666
## avgmarr   0.04672728 0.02877650 0.03178283      0.10728653
## hapavg    0.03553109 0.02188145 0.02416744      0.08157993
## vryhap    0.04038689 0.02487184 0.02747024      0.09272876
## smerel    0.02470405 0.01521373 0.01680313      0.05672073
## vryrel    0.05277061 0.03249822 0.03589336      0.12116191
## yrsmarr4  0.04469174 0.02752293 0.03039830      0.10261274
## yrsmarr5  0.04644890 0.02860507 0.03159349      0.10664724
## yrsmarr6  0.02737290 0.01685731 0.01861842      0.06284849

Poisson regression:

m3<-glm(naffairs~avgmarr + hapavg + vryhap + smerel + vryrel + yrsmarr4 + 
          yrsmarr5 + yrsmarr6,data=Hilbe,family=poisson(link="log"))
decompose.model(m3,group.by = c(rep(1,201),rep(2,200),rep(3,200)),
                model.type="poisson")
## $decomp.coef
##                     1          2          3 Model Coefs
## Intercept  0.36961499  0.3344646  0.1896101   0.8936896
## avgmarr   -0.29605739 -0.2439847 -0.3046603  -0.8447024
## hapavg    -0.25561998 -0.4450145 -0.2758378  -0.9764722
## vryhap    -0.51444273 -0.5858584 -0.2268714  -1.3271725
## smerel    -0.03922081 -0.3953424 -0.4299400  -0.8645032
## vryrel    -0.13793948 -0.3946393 -0.3580721  -0.8906509
## yrsmarr4   0.02940394  0.3116065  0.2160086   0.5570191
## yrsmarr5   0.30313205  0.4027702  0.2315718   0.9374741
## yrsmarr6   0.09839040  0.3084983  0.5403358   0.9472245
## 
## $decomp.var
##                     1           2           3 Model Variances
## Intercept 0.003187445 0.001623947 0.004293614     0.009105005
## avgmarr   0.003821151 0.001946809 0.005147240     0.010915199
## hapavg    0.002540005 0.001294088 0.003421487     0.007255580
## vryhap    0.003546249 0.001806751 0.004776937     0.010129937
## smerel    0.002773807 0.001413206 0.003736427     0.007923439
## vryrel    0.006389824 0.003255502 0.008607344     0.018252669
## yrsmarr4  0.004858560 0.002475350 0.006544671     0.013878581
## yrsmarr5  0.004682337 0.002385568 0.006307292     0.013375197
## yrsmarr6  0.003082791 0.001570627 0.004152640     0.008806058

Negative binomial regression:

library(MASS)
m4<-glm.nb(naffairs~avgmarr + hapavg + vryhap + smerel + vryrel + yrsmarr4 + 
             yrsmarr5 + yrsmarr6,data=Hilbe)
decompose.model(m4,group.by = c(rep(1,201),rep(2,200),rep(3,200)),model.type="nb")
## $decomp.coef
##                    1          2          3 Model Coefs
## Intercept  0.4080631  0.3140500  0.1863346   0.9084476
## avgmarr   -0.3472504 -0.3204935 -0.3209343  -0.9886782
## hapavg    -0.3044775 -0.4181657 -0.2766478  -0.9992911
## vryhap    -0.5437135 -0.6060801 -0.2307394  -1.3805330
## smerel    -0.2252334 -0.4726392 -0.4903277  -1.1882004
## vryrel    -0.4713079 -0.3008507 -0.5009572  -1.2731158
## yrsmarr4   0.1433029  0.4351759  0.4599113   1.0383903
## yrsmarr5   0.2768647  0.3583896  0.2660988   0.9013532
## yrsmarr6   0.2551637  0.3540654  0.5454519   1.1546810
## 
## $decomp.var
##                    1          2          3 Model Variances
## Intercept 0.04960029 0.02359640 0.05814853      0.13134523
## avgmarr   0.06706241 0.03190368 0.07862011      0.17758620
## hapavg    0.05016872 0.02386682 0.05881492      0.13285046
## vryhap    0.05169347 0.02459219 0.06060244      0.13688811
## smerel    0.02777333 0.01321264 0.03255985      0.07354583
## vryrel    0.06021224 0.02864484 0.07058936      0.15944643
## yrsmarr4  0.05223215 0.02484846 0.06123396      0.13831458
## yrsmarr5  0.05813023 0.02765436 0.06814853      0.15393312
## yrsmarr6  0.03252648 0.01547386 0.03813217      0.08613251

Need mirroring services?
Contact our team at info@vpspulse.com.

Mirror powered by VPSpulse

Infrastructure sponsored by VPSPulse & Secure Payments by ArionPay.