Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested random effects and related fixed effects

I have cross-national panel data and I'd like to know the impact of IV on a binary student-level outcome DV

I'd like to include a nested random effect that takes into account that which school the student is in will affect the outcome, and that schools are meaningfully different across countries: (1|country/school). So the model I started with is:

model = glmer(DV ~ IV + (1|country/school), data=data, family = 'binomial')

I'd also like to take into account temporal trends. At first I thought I should do year fixed effects, but the political developments of these countries vary significantly over time and I wanted to capture that while 1991 may have left schools in country A in turmoil, 1991 may have been a great year for educational funding in country B. I thus thought that I should possibly include a country-year fixed effect, as shown below:

model = glmer(DV ~ IV + (1|country/school) + as.factor(country_year),
                data=data, family = 'binomial')

The random effects for the model are:

Random effects:
 Groups          Name        Variance  Std.Dev. 
 school:country (Intercept) 5.703e-02 2.388e-01
 country         (Intercept) 4.118e-15 6.417e-08
Number of obs: 627, groups:  school:country, 51; country, 22

Is it incorrect to include country-year fixed effects, when there is already a country random effect included in the model?

An alternative way of asking the question: How should I probably deal with the fact that school is a subset of country, and country_year is a subset of country, but neither school or country_year are subsets of each other?

like image 547
thecomebackkid Avatar asked Nov 07 '22 21:11

thecomebackkid


1 Answers

From what I can see, you have 22 countries. It is not clear what country_year is, but assuming that it is simply a dummy for country:year, then it may not be a a good idea to include this as a fixed effect (as a factor), since there will be too many levels to interpret usefully.

Since you are interested in the temporal trends, it makes sense to include year as a fixed effect:

DV ~ IV + (1|country/school) + as.factor(year)

If there are many years you may find it better include year as numeric

DV ~ IV + (1|country/school) + as.numeric(year)

..as this will estimate a single (linear) trend for year, whereas if it is a factor then it will compute an estimate however many years there are (minus 1), which will not be easy to interpret when there are many levels. However, when coded as a factor the estimates can indicate whether there is a non-linear trend, and then you could switch to as.numeric and introduce non-linear terms.

The last paragraph of the OP is a little confusing. If country_year is really nested within country, then we would have:

DV ~ IV + (1|country/school) + (1|country:country_year)

..which is the same as:

DV ~ IV + (1|country) + (1/school:country) + (1|school:country_year)

...however this will not estimate any temporal trend. If you want to estimate a trend then you need to include year (or country_year) as a fixed effect as mentioned above - and you could allow this to differ between schools (and/or countries) by including it as a random slope, for example:

DV ~ IV + year + (1|country) + (year|school:country)
like image 127
Robert Long Avatar answered Nov 15 '22 11:11

Robert Long