Working with experimental data — mixed effects models
 Schedule:
 t.b.a.
 Motivation
 Many, if not all of the students in our program will work with experiments. In most experiments we observe the same unit (participant in the experiment, matching group in the experiment) repeatedly. We say, the data is “grouped”. Mixedeffect models are a versatile tool to analyse grouped data.
 Topics:

 Introduction
 Revision: Linear models
 Linear fixed effects
 Balanced and unbalanced data
 Linear random effects
 Linear mixed effects
 Nonlinear mixed effects
 Nested factors
 Hypothesis tests
 Correlation structures
 Sample size estimation
 Handout
 If you want to prepare for the lecture (or revise), you can have look at the handout. You will find still a lot of mistakes but you might get the idea ;)
 Literature

 Jose C. Pinheiro and Douglas M. Bates, Mixed Effects Models in S and SPlus. Springer, 2002.
 Julian J. Faraway, Extending the Linear Model with R. Chapman & Hall, 2006.
 John K. Kruschke , Doing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan. Academic Press, 2nd Edition, 2014.<
 A. C. Davison, D. V. Hinkley, Bootstrap Methods and their Application, Cambridge University Press, 1997
 Bradley Efron and Robert J. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1994
 Software
 For our practical examples (during the entire course) we will use the software environment R. I think that it is helpful to coordinate on one environment. R is free, it is very powerful, and it is popular in the field.
 Documentation for R is provided throught the built in help. You also find support on the R Homepage.
You might find the following useful:
 The R Guide, Jason Owen (Easy to read, explains R with the help of examples from basic statistics)
 Simple R, John Verzani (Explains R with the help of examples from basic statistics)
 Einführung in R, Günther Sawitzki (In German. Rather compact introduction.)
 Econometrics in R, Grant V. Farnsworth (The introduction to R is rather compact and pragmatic.)
 An Introduction to R, W. N. Venables und D. M. Smith (The focus is more on R as a programming language)
 The R language definition (Concentrates only on R as a programming language.)
 On the JAGS Homepage you go to the files pages, then to Manuals, to find the JAGS user manual.
 You can download R from the homepage of the Rproject.
 Installing R with Microsoft Windows:
 Download and start the Installer. Install R on your local drive. Installing on a network drive or in the cloud (Dropbox, Onedrive,...) is possible but not recommended.
 Installing R with GNULinux:
 Follow the advice to install R for your distribution.
 Installing R with MacOS X:
 Here is a guide to install R with MacOS X.
 In the lecture we use RStudio as a front end.
 For the Bayesian parts we will use JAGS. It helps if you have installed R, RStudio, and JAGS on your computer when we start the course.
 We will use the following packages:
boot, car, Ecdat, ellipse, foreign, geepack, Hmisc, lattice, latticeExtra, lme4, lmtest, MASS, nlme, nnet, SASmixed, survival
.If, e.g., the command
library(Ecdat)
generates an error message (Error in library(Ecdat): There is no package called 'Ecdat'
), you have to install the package. Installing packages with Microsoft Windows:
 With RStudio: Use the tab “Install”. Otherwise: Start
Rgui.exe
and install packages from the menuPackages / Install Packages
).  Installing packages from GNULinux or MacOS X:
 From within R use the command
install.packages("Ecdat")
, e.g., to install the packageEcdat
 It will help if you can bring your own portable computer to the classes and exercises.
You should have an uptodate version of R already installed.
You should also have the following libraries already installed:
car, Ecdat, Hmisc, nlme, lme4
. You should have set up your computer such that you can work with R.  You might also find make and Emacs useful tools.
 Documentation for R is provided throught the built in help. You also find support on the R Homepage.
You might find the following useful:
 Handout + Exam
 I have put a preliminary version of the handout on the net.
The data we use for the examples is attached to the handout. Use
pdftk
or your PDF viewer to extract the data. If you use Adobe Acrobat and you have difficulties saving attachments from PDF files it might be that you (or your administrator) may prevent Adobe Acrobat from opening certain types of attachments.Please solve the exam between 15:00 on 14th August until 15:00 on 15th August. You will need the data in R format or in Stata format to solve the exam.
For those who are interested in the commands I used in today's exercise:
with(exe2,{ print(length(unique(player))) print(table(player,treatment)) print(table(treatment)) }) exe2 < within(exe2,t<as.factor(treatment)) lmer(y ~ t 1 + period + (1player),data=exe2)
And here are some commands that you could have used in the exam. Let us start with a colorful boxplot (not really part of the exam):with(exam,boxplot(effort ~ Treatment,col=levels(as.factor(Treatment))))
Here is the serious stuff:summary(lm (effort ~ Treatment  1,data=exam))
If we are interested in the red treatment, we would rather saysummary(lm (effort ~ (Treatment=="red"),data=exam))
In the lecture I forgot to mention thatgeeglm
needs ordered data (and since I gave you unordered data, in your estimates you got too many clusters):exam < exam[with(exam,order(matchingGroup,playerid)),] summary(r.cluster < geeglm (effort ~ Treatment  1, id=matchingGroup,data=exam)) (lmer.0 < lmer(effort ~ Treatment  1 + (1matchingGroup) + (1playerid),data=exam))
When I asked for a random effect also for treatments (and not only for the intercept) some of you then dropped the fixed effect forTreatment
entirely. That was not the idea. What I had in mind was the following:(lmer.T < lmer(effort ~ Treatment  1 + (1+TreatmentmatchingGroup) + (1+Treatmentplayerid),data=exam)) anova(lmer.T,lmer.0)
Here you could explain thatanova
is anticonservative and that one should better use a permutation test.hausman(lm(effort ~ Treatment*matchingGroup + Treatment*playerid,data=exam),lmer.T)