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 in tanks 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.

Another common example of nested variables occurs when data is taken from students but the students are at four different universities. Therefore the students are nested within the universities.


Challenge

Do an internet search to find an example of a study or experimental set up, that includes a nested design. You have 3 tasks:
* Type a simple description of the experiment
* Name the variables that are the response, the fixed effect, the random effects and what is nested in what.
* Write out an example of R code for a mixed model with this nested design.


Crossed random effects

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

Or in the student example, if they were measured while they were at one university and then again when they went to one other university, this would be a partial crossed design (though there’s the massive confounding variable of time here so it’s not the best example!).


Challenge

Do an internet search to find an example of a crossed (partial or fully) design. You have 3 tasks:
* Type a simple description of the experiment
* Name the variables that are the response, the fixed effect, the random effects and explain why it is crossed.
* Then write out an example of R code that would run a mixed model with crossed random effects.