# Attributable % variability or Proportion of Variance Explained

Hi, I am trying to find the attributable percentage variability or the proportion of the variance explained by the multilevel logistic regression model. My outcome is in-hospital mortality, and I have both patient and hospital level predictor variables.

I should probably start by saying I am just a plain MD and not that stat-savvy. I also understand this is not as easy as it is in a multilevel linear regression model with R2.

The following article: https://onlinelibrary.wiley.com/doi/10.1002/sim.7336#sim7336-bib-0001 (Section 4.8), as well as the measure by Snijders and Bosker (2012) seems to be on-track with what I am looking for.

My current model is as follows:

melogit mortality age i.sex i.race i.elixsum i.cancer_type i.year hospitalvolume teachinghospital cancerprogram FTE_bed SVI i.insurance totaltime || hospital id:

The method in section 4.8 requires me to calculate the following:

A - sample variance of the fixed effects linear predictor

B - variance of the random intercept from the fitted multilevel logistic regression model

and also know that the level-one residual variance is fixed at π2/3

Then it says the R2 binary = A / A+B+π2/3.

I would highly appreciate if anyone knows what would be the code to calculate this.

Right now, I am assuming that B is the var(_cons) from the model under the random effects portion, and that to calculate A, I need to first do predict x, xb and then sum x, detail and manually look at the variance from there. Finally, I should then manually calculate using the formula.

Is this the correct way to do this?

Alternartively,

https://web.pdx.edu/~newsomj/mlrclass/ho_r2.pdf

This article by Newson states the best method citing same folks: Snijders and Bosker (1999) is to

use σ2 as the within-group variance and τ2 as the between group (or intercept) variance.

And then divide the sum of both for the full model from the null model, followed by subtracting answer from 1 to get the R2 for the predictor variables at level one. For level 2 variance, the σ2 in both full and null models needs to first be divided by B which is the average cluster size in the notation used by Roberts and colleagues. Then its same steps.

I am intensely confused on how to calculate any of this, and what the correct Stata code would be.

The end-goal is to get the various contributions of different groups of predictors for in-hospital mortality similar to this study: https://pubmed.ncbi.nlm.nih.gov/36994756/.

Thank you!

- unanswered
- 218 views
- Pro Bono

### Related Questions

- real analysis
- Finding a unique structure of the domain of a function that gives a unique intuitive average?
- Describing Bayes Theorem succinctly in words
- Generalization of the Banach fixed point theorem
- Measure Theory and the Hahn Decomposition Theorem
- Times series Analys
- The derivation of the formula for variance for a Pareto Distribution
- Why is the t-test for two independent samples $\ t^* = \frac{(\bar{x}_1 - \bar{x}_2)}{\sqrt{\frac{S_1^2}{n_1} + \frac{S_2^2}{n_2}}}$?

Questions at this level should come with a good bounty to give users motivation to spend time on it, otherwise you may not get a response.

Hi, this is my first time posting on this site. What would be a reasonable bounty for this?

Think about how much time one needs to spend to answer your questions, and what a fair hourly rate for such individual would be. It will give you a pretty good idea.