0

I'm trying to fit a mixed linear model as below.

modelF <- lmer(Gini ~ Years +(Years|Country),data1, 
        REML=TRUE,na.action=na.omit,control = lmerControl(optimizer = "optimx", 
        calc.derivs = FALSE,optCtrl = list(method = "nlminb", starttests = FALSE, kkt = FALSE)))

The output is : for each Country an intercept and coefficient (so if I have 100 countries, I get a model of B0 and B1 for each country).

they can be displayed using coef(modelF)

however, I wish to display the R-squared for each country.

How can I do that?

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
  • Does this answer your question? [R-Squared of lmer model fit](https://stackoverflow.com/questions/45327217/r-squared-of-lmer-model-fit) – Basti Sep 02 '21 at 12:56
  • No i already checked that article. it returns conditional and marginal R^2 for the whole model. What i'm asking is if I can get an R^2 for each model separately (i.e R^2 for Country 1, R^2 for Country 2...) – Jinane Jouni Sep 02 '21 at 13:05
  • 1
    Hi there. You are more likely to get a good answer, if you share a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a small example of your data used. – Martin Gal Sep 02 '21 at 13:09
  • You would need a separate model per country if you want to calc R^2 per country b/c R^2 is a *model* metric – Nate Sep 02 '21 at 13:10
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 02 '21 at 13:40
  • Okay so by running the above code, i'm using a linear fixed model with random effects of Years and Country. The output is similar to the output of a simple linear regression, I get a B0 and B1, and an r.squared. However, when i execute the coefficients of the model, I get the following: For each country, I get a different intercept and B1 coefficient. What I want is to see the R^2 for each country. I tried to run a linear model for each country , but it doesn't give the same coef as the above model. – Jinane Jouni Sep 05 '21 at 15:04

0 Answers0