# Coding and Visualizing Repeated Measures and Mixed-Effects Models

#### birdnerd

##### New Member
I am doing a study analyzing trends in changing bird diversity over the past 40 years. Surveys have been taken at 20 locations each year. The survey locations are the random effect and repeated each year. This is the code and output I used in the lme4 library:

rmaModel<-lmer(DIVERSITY~YEAR+(1|CIRCLE),data=data)
anova(rmaModel)

Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
YEAR 4.4674 4.4674 1 672.72 31.328 3.174e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I'm just not sure if this is what I should be doing, if there might be a better way and how to interpret my results correctly. Also, what is the best way to visualize this in R (aka graphs)?

#### trinker

##### ggplot2orBust
For visualization maybe something like (this makes assumptions about what your data looks like; e.g. [I know your data is slightly different but if you make your problems reproducible you'll get better responses; e.g., see that I provide a fake data set?]):

Code:
library(ggplot2)

data <- data.frame(
YEAR = rep(1990:2010, 10),
DIVERSITY = rnorm(10*length(1990:2010), 50, 10),
CIRCLE = rep(LETTERS[1:10], each =  length(1990:2010))
)

ggplot(data, aes(x = YEAR, y = DIVERSITY, color = CIRCLE)) +
geom_point() +
geom_path(aes(group = CIRCLE)) +
facet_wrap(. ~ CIRCLE, ncol = 2) +
scale_x_continuous(breaks = 1990:2010, labels = function(x) substring(x, 3, 4))