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: (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.race i.elixsum i.cancer_type i.year hospitalvolume teachinghospital cancerprogram FTE_bed SVI 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?


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:

Thank you!

  • Savionf Savionf

    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?

    • Savionf Savionf

      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.

Join Matchmaticians Affiliate Marketing Program to earn up to a 50% commission on every question that your affiliated users ask or answer.