Mixed Models 2

Some studies might need a generalised mixed model. Others might have random effects that are crossed or nested.

Understanding these concepts will mean you will be aware when they apply to your own studies.


Generalised mixed models

Sometimes the response (dependent) variable is not continuous but a categorical variable. Just as you can use alternative generalized models instead of lm such as logistic or poisson, you can use other generalised mixed models.

For example, imagine each of our dragons was scored as passing or failing the intelligence test making the response passFail binary. Then you would use a binary logistic mixed model.

Dragons again


Challenge part 1

Find the function and the code for a binominal mixed model. Adapt the code to run an analysis on this binomial dragon data where the response variable passFail is if the dragon passed (1) or failed (0) the IQ test. The fixed effect is bodyLength and random effect is mountainRange.


Challenge part 2

Once you have run the analysis and interpreted the results, write out in your script how you would report this in words.


Challenge part 3

Decide what a suitable graph would be and create one making sure it’s formatted.


Lizards eating

Imagine an experiment where lizards in individual tanks are observed everyday for 14 days to see if they eat or not (lizards$eat). Some are in a control group with dead prey and some are in a treatment group with live prey. There are males and females. lizard data

lizards <- read.csv(file = "data/lizard.csv")
head(lizards)
  lizard day   group    sex eat
1      1   1 control female   0
2      1   2 control female   0
3      1   3 control female   1
4      1   4 control female   0
5      1   5 control female   0
6      1   6 control female   0

Identify why this needs a mixed model and therefore what the random variable is.

Answer We need to control for the differences among individual animals because we have repeated measures. In other words the measurements are not independent because some of them come from the same individual lizard. Therefore, lizard is the random variable.


Challenge part 1

Run a model for this and using the coefficients report the data. Remember they will be log odds.



Challenge part 2

Report the analysis in words as clearly as you can. Include a graph. Ask someone else if they can understand the results from what you have written.



Nested design

Some experiments have what’s called a nested design. For example the lizard experiment would be nested if the lizards had been housed in groups of 10 lizards to a tank rather than having a tank to themselves. There may be some differences among the tanks and therefore you would have to add tank into the model. Since not every individual is in every tank ie each one is only in one tank, lizard is nested within tank.

lizards <- read.csv(file = "data/lizard_nested.csv")
head(lizards)
  tank lizard day   group    sex eat
1    1      1   1 control female   0
2    1      1   2 control female   0
3    1      1   3 control female   1
4    1      1   4 control female   0
5    1      1   5 control female   0
6    1      1   6 control female   0
table(lizards$tank)

  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 
 21  22  23  24  25 
140 140 140 140 140 


Challenge part 1

Find and run the code for this nested mixed model.


Challenge part 2

Report the analysis. Include a graph.


Challenge part 3

Decide if including the tank in the model changed the results?


Crossed random effects

Using the lizard examples again, a crossed design would be if the different lizards had experienced the different tanks (the researcher would have had to keep moving them around tanks). It would be a partially crossed design if each lizard had been measured in only some of the tanks and a fully crossed design if each lizard had been measured in all of the tanks.


Challenge

For each experiment below decide if it is a mixed model, nested, partially crossed or fully crossed design.

  1. Students are measured for statistics ability repeatedly in tests. The effects of gender and prior education are fixed effects. Students study different programmes.

  2. Researchers test how light intensity (high vs low) and nutrient availability (high vs low) affect plant biomass across multiple forest sites. At each site, plots are divided into subplots that receive all combinations of light and nutrient treatments, creating a 2×2 factorial design.

  3. Researchers want to test how soil type (sandy vs clay) influences plant biomass across different forest sites. They select 6 sites, and within each site, they identify 3 plots. In each plot, they measure biomass of 10 individual plants growing in the same soil type.