Presentation is loading. Please wait.

Presentation is loading. Please wait.

Statistics 3: mixed effect models Install R library lme4 to your computer: 1.R -> Packages -> Install packages 2.Choose mirror 3.Choose lme4 4.Open the.

Similar presentations


Presentation on theme: "Statistics 3: mixed effect models Install R library lme4 to your computer: 1.R -> Packages -> Install packages 2.Choose mirror 3.Choose lme4 4.Open the."— Presentation transcript:

1 Statistics 3: mixed effect models Install R library lme4 to your computer: 1.R -> Packages -> Install packages 2.Choose mirror 3.Choose lme4 4.Open the library by the command library(lme4)

2 General and generalized linear models assume that error terms are independent. Y ~ a + b*X + ε This assumption can often be violated: -year effect -site/block effect -repeated measures from the same measurement unit, i.e. individual

3 Regression line: Height ~ Diameter Tree height and diameter measured in two forest plots Residuals not independent nor normally distributed.

4 Correlation within groups can be accounted by random effects Y = a + b 1 x 1 + … + b n x n + η + ε Normally distributed residuals Random effects account for potential associations/correlations within groups of observations. Linear mixed effect model:

5 Distinction between fixed and random effects Random effect is a source of uncontrollable variation among groups –Treatment or exposure level is controllable –Site or year effect is uncontrollable –Also if data is collected by several scientist, differences (‘human error’) can be accounted by random effects Fixed effects are those we want to do inference about and predict Random effects are those we just want to ‘take care of’ –Random effects organize random noise in an appropriate manner –Random effects account for the internal correlations structure of the data If experiment was replicated, fixed effects would be the same but random effects would be different

6 Fixed or random? Does one variety of barley grow faster than the other? –Variety of barley –Field Do fish swim faster in high temperature? –Temperature –Fish ID Do migratory birds return earlier if mean winter temperature is higher? –Temperature –Year Sometimes making the distinction can be difficult

7 R syntax for random effect Linear mixed effect model can be fitted through library(nlme) lme(y~x+z,random=~1|’random variable’,data) library(lme4) lmer(y~x+z+(1|’random varible’),data) Generalized linear mixed effect models can be fitted using library(MASS) glmmPQL(y~x+z,random=~1|’random variable’,data,family) library(lme4) glmer(y~x+z+(1|’random varible’),data,family) DEMO 1

8 Nested random effects Random effects are sometimes nested –Different error terms for different levels in the design Example: Plant growth measured in an experiment that conducted in three glasshouses, both containing six growth plates –Plate nested in glasshouse: Glasshouse 2Glasshouse 3Glasshouse 1 1 45 23 6 1 45 23 6 1 45 23 6

9 More R syntax Simple random effects: random = ~1 -> each group have its own intercept e.g. ~1|ID Nested random effects: random = ~1| y / x -> random intercept for x nested in y e.g. ~1|glasshouse/plate Glasshouse effect Plate effect within glasshouse effect Exercises


Download ppt "Statistics 3: mixed effect models Install R library lme4 to your computer: 1.R -> Packages -> Install packages 2.Choose mirror 3.Choose lme4 4.Open the."

Similar presentations


Ads by Google