# Linear Mixed Effects Models data structure, identical response variable data

I am investigating how sea temperature affects the total length of a species, which has a one year life span, presents sexual dimorphism, and migrates over a considerable area from north to south.

I have length data (response variable) from the southern end of the migration, for one month, over a 20 year period, essentially this sums up to 20 data points (mean length of one per year), per sex, where we know the relative stage of development of the animals would be towards the end of their growth i.e. we get them at the end of their growth, few months before they spawn and die.

I have temperature data, which covers the presumed migration route, consisting of 24 location boxes, and covering 12 months, for the span of 20 years.

Data Structure is as follows, might make more sense in a diagram:

I used this data to run 240 basic linear models of mean Length vs mean Temperature, the models were ran per location box, per month, per sex.

I am now looking to extend my analysis by using a mixed effects model, which attempts to account for the temporal (months) and spatial (location boxes) autocorrelation in the dataset. I intend to fit the location boxes and months as random effects. Currently, this is how the dataset is organised:

Year Month Box meanT Sex meanL
1999  01   1B  10.89  F  25.51
1999  02   1F  15.36  F  25.51
2000  01   1B  11.32  F  27.34
2000  02   1F  17.38  F  27.34
2001  01   1B  20.53  F  23.32
2001  02   1F  19.33  F  23.32


meanT - mean Temperature

meanL - mean Length (response variable)

Where the 20 mean length data points are repeated for each location box, and each month. To be more specific, these are all the same length measurements, they are not samples from each location box or each month.

My question is, I assume that I cannot run a mixed effects model on the data like this, but I am unsure how to structure the data, do I need to remove some of the location boxes?

In a nutshell, I have 20 data points for my length variable, and 9600 data points for my temperature variable. Is it at all possible for me to apply a mixed effects model to this type of data? P.S. It is not possible for me to obtain data for the animals in each location box, duting the migration, nor is it possible for me to have data for each month from the same location, as their development straddles the year and I have chosen the time where we consistently have data for 20 years.

Mixed effects models are used to account for correlations in grouped/clustered data. As far as I can see, in your experiment measurements on the same box could be expected to be correlated. In this case you could include random effects for the Box grouping factor. If you happen to work in R, then with package lme4 you could use something like the following:

lmer(meanL ~ meanT + Sex + (1 | Box), data = <your_data>)


This would postulate the measurements in the same Box are correlated, but the correlations for any possible pair of measurements over the year will be the exactly equal.

If you would instead like to postulate that measurements from the same Year within a the same Box are correlated, then you could use the syntax:

lmer(meanL ~ meanT + Sex + (1 | Box / Year), data = <your_data>)


If you would like to assume that correlations in meanL decay with increasing time lag between the measurements, then you could include a random slopes terms, e.g.,

lmer(meanL ~ meanT + Sex + (Year | Box), data = <your_data>)

• Thank you, however, does 'Month' matter in this case as there would be seasonality there? Also I do not have length measurements specific to the location of the temperature measurements? That isn't an issue? As it stands I have 20 length measurements and 9,600 temperature measurements? Jan 2, 2020 at 18:09
• @watermineporcupine yes, along the same lines you could add Month as a nested grouping factor or as random slopes. Jan 2, 2020 at 21:08
• Ah great, thank you, however I'm still concerned about the discrepency of my data? At the moment the 20 length measurements are identical per each location box, month and sex, as I ran the linear models individually, now I'm not sure how to organise the data? Jan 3, 2020 at 11:25