25
Mixed models in R using the lme4 package Part 3: Inference based on profiled deviance Douglas Bates 8 th International Amsterdam Conference on Multilevel Analysis <[email protected]> 2011-03-16 Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 1 / 20

Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Embed Size (px)

Citation preview

Page 1: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Mixed models in R using the lme4 packagePart 3: Inference based on profiled deviance

Douglas Bates

8th International Amsterdam Conferenceon Multilevel Analysis

<[email protected]>

2011-03-16

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 1 / 20

Page 2: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 3: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 4: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 5: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 6: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 7: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Outline

1 Profiling the deviance

2 Plotting the profiled deviance

3 Density plots

4 Profile pairs

5 Profiling models with fixed-effects for covariates

6 Summary

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 2 / 20

Page 8: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Likelihood ratio tests and deviance

In section 2 we described the use of likelihood ratio tests (LRTs) tocompare a reduced model (say, one that omits a random-effects term)to the full model.

The test statistic in a LRT is the change in the deviance, which isnegative twice the log-likelihood.

We always use maximum likelihood fits (i.e. REML=FALSE) to evaluatethe deviance.

In general we calculate p-values for a LRT from a χ2 distribution withdegrees of freedom equal to the difference in the number ofparameters in the models.

The important thing to note is that a likelihood ratio test is based onfitting the model under each set of conditions.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 3 / 20

Page 9: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profiling the deviance versus one parameter

There is a close relationship between confidence intervals andhypothesis tests on a single parameter. When, e.g. H0 : β1 = β1,0versus Ha : β1 6= β1,0 is not rejected at level α then β1,0 is in a 1− αconfidence interval on the parameter β1.

For linear fixed-effects models it is possible to determine the changein the deviance from fitting the full model only. For mixed-effectsmodels we need to fit the full model and all the reduced models toperform the LRTs.

In practice we fit some of them and use interpolation. The profile

function evaluates such a “profile” of the change in the devianceversus each of the parameters in the model.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 4 / 20

Page 10: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Transforming the LRT statistic

The LRT statistic for a test of a fixed value of a single parameterwould have a χ2

1 distribution, which is the square of a standardnormal.

If a symmetric confidence interval were appropriate for the parameter,the LRT statistic would be quadratic with respect to the parameter.

We plot the square root of the LRT statistic because it is easier toassess whether the plot looks like a straight line than it is to assess ifit looks like a quadratic.

To accentuate the straight line behavior we use the signed square roottransformation which returns the negative square root to the left ofthe estimate and the positive square root to the right.

This quantity can be compared to a standard normal. We write it as ζ

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 5 / 20

Page 11: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Evaluating and plotting the profile

> pr1 <- profile(fm1M <- lmer(Yield ~ 1+(1| Batch), Dyestuff , REML=FALSE))

> xyplot(pr1 , aspect =1.3)ζ

−2

−1

0

1

2

0 20 40 60 80 100

σ1

3.6 3.8 4.0 4.2

log(σ)

1500 1550

(Intercept)

The parameters are σb , log(σ) (σ is the residual standard deviation)and µ. The vertical lines delimit 50%, 80%, 90%, 95% and 99%confidence intervals.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 6 / 20

Page 12: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Alternative profile plot

> xyplot(pr1 , aspect =0.7, absVal=TRUE)

|ζ|

0.0

0.5

1.0

1.5

2.0

2.5

0 20 40 60 80 100

σ 1

3.6 3.8 4.0 4.2lo

g(σ)

1500 1550

(Int

erce

pt)

Numerical values of the confidence interval limits are obtained from themethod for the confint generic

> confint(pr1)

2.5 % 97.5 %

.sig01 12.201753 84.06289

.lsig 3.643622 4.21446

(Intercept) 1486.451500 1568.54849Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 7 / 20

Page 13: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Changing the confidence level

As for other methods for the confint generic, we use level=α to obtaina confidence level other than the default of 0.95.

> confint(pr1 , level =0.99)

0.5 % 99.5 %

.sig01 NA 113.692643

.lsig 3.571293 4.326347

(Intercept) 1465.874011 1589.126022

Note that the lower 99% confidence limit for σ1 is undefined.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 8 / 20

Page 14: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Interpreting the univariate plots

A univariate profile ζ plot is read like a normal probability plotI a sigmoidal (elongated “S”-shaped) pattern like that for the

(Intercept) parameter indicates overdispersion relative to the normaldistribution.

I a bending pattern, usually flattening to the right of the estimate,indicates skewness of the estimator and warns us that the confidenceintervals will be asymmetric

I a straight line indicates that the confidence intervals based on thequantiles of the standard normal distribution are suitable

Note that the only parameter providing a more-or-less straight line isσ and this plot is on the scale of log(σ) not σ or, even worse, σ2.

We should expect confidence intervals on σ2 to be asymmetric. In thesimplest case of a variance estimate from an i.i.d. normal sample theconfidence interval is derived from quantiles of a χ2 distribution whichis quite asymmetric (although many software packages providestandard errors of variance component estimates as if they weremeaningful).

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 9 / 20

Page 15: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile ζ plots for log(σ),σ and σ2

ζ

−2

−1

0

1

2

3.6 3.8 4.0 4.2

log(σ)

40 50 60 70

σ

2000 3000 4000 5000

σ2

We can see moderate asymmetry on the scale of σ and strongerasymmetry on the scale of σ2.

The issue of which of the ML or REML estimates of σ2 are closer tobeing unbiased is a red herring. σ2 is not a sensible scale on which toevaluate the expected value of an estimator.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 10 / 20

Page 16: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile ζ plots for log(σ1),σ1 and σ21

ζ

−2

−1

0

1

2

2 3 4

log(σ1)

0 20 40 60 80 100

σ1

0 5000 10000

σ12

For σ1 the situation is more complicated because 0 is within the rangeof reasonable values. The profile flattens as σ → 0 which means thatintervals on log(σ) are unbounded.Obviously the estimator of σ21 is terribly skewed yet most softwareignores this and provides standard errors on variance componentestimates.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 11 / 20

Page 17: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Converting profile ζ to a density

We speak of a profile ζ plot as showing skewness, especially forparameters such as σ1 and σ.

Often it is easier to envision symmetry or skewness in terms of adensity plot.

If ζ is compared to a standard Gaussian distribution then thecorresponding cumulative distribution function is Φ(ζ), from which wecan derive a density function.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 12 / 20

Page 18: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile-based densities for fm1de

nsity

0.00

00.

010

0.02

0

0 50 100 150

σ 1

0.0

0.5

1.0

1.5

2.0

2.5

3.6 3.8 4.0 4.2 4.4

log(

σ)0.

000

0.01

00.

020

1450 1500 1550 1600

(Int

erce

pt)

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 13 / 20

Page 19: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile pairs plots

The information from the profile can be used to produce pairwiseprojections of likelihood contours. These correspond to pairwise jointconfidence regions.

Such a plot (next slide) can be somewhat confusing at first glance.

Concentrate initially on the panels above the diagonal where the axesare the parameters in the scale shown in the diagonal panels. Thecontours correspond to 50%, 80%, 90%, 95% and 99% pairwiseconfidence regions.

The two lines in each panel are “profile traces”, which are theconditional estimate of one parameter given a value of the other.

The actual interpolation of the contours is performed on the ζ scalewhich is shown in the panels below the diagonal.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 14 / 20

Page 20: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile pairs for model fm1

> splom(pr1)

Scatter Plot Matrix

.sig01

0 50 100 150

−3

−2

−1

0

.lsig

3.6

3.8

4.0

4.2

4.4 4.0 4.2 4.4

0 1 2 3

(Intercept)

1450

1500

1550

1600

0 1 2 3

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 15 / 20

Page 21: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

About those p-values

Statisticians have been far too successful in propagating concepts ofhypothesis testing and p-values, to the extent that quoting p-values isessentially a requirement for publication in some disciplines.

When models were being fit by hand calculation it was important touse any trick we could come up with to simplify the calculation.Often the results were presented in terms of the simplified calculationwithout reference to the original idea of comparing models.

We often still present model comparisons as properties of “terms” inthe model without being explicit about the underlying comparison ofmodels with the term and without the term.

The approach I recommend for assessing the importance of particularterms in the fixed-effects part of the model is to fit with and withoutthen use a likelihood ratio test (the anova function).

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 16 / 20

Page 22: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Hypothesis tests versus confidence intervals

As mentioned earlier, hypothesis tests and confidence intervals aretwo sides of the same coin.For a categorical covariate, it often makes sense to ask “Is there asignficant effect for this factor?” which we could answer with ap-value. We may, in addition, want to know how large the effect isand how precisely we have estimated it, i.e. a confidence interval.For a continuous covariate we generally want to know the coefficientestimate and its precision (i.e. a confidence interval) in preference toa p-value for a hypothesis test.When we have many observations and only a moderate number offixed and random effects, the distribution of the fixed-effectscoefficients’ estimators is well-approximated by a multivariate normalderived from the estimates, their standard errors and correlations.With comparatively few observations it is worthwhile using profiling tocheck on the sensistivity of the fit to the values of the coefficients.As we have seen, estimates of variance components can be poorlybehaved and it is worthwhile using profiling to check their precision.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 17 / 20

Page 23: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profiling a model for the classroom data

> pr8 <- profile(fm8 <- lmer(mathgain ~ mathkind + minority +

+ ses + (1| classid) + (1| schoolid), classroom , REML=FALSE))|ζ

|

0.00.51.01.52.02.5

4 6 8 10 12

σ 1

4 6 8 10 12

σ 2

3.24 3.28 3.32 3.36

log(

σ)

260 280 300

(Int

erce

pt)

−0.52 −0.48 −0.44

mat

hkin

d

−14 −10 −6 −4 −2

min

ority

Y

2 4 6 8

0.00.51.01.52.02.5

ses

The fixed-effects coefficient estimates (top row) have good normalapproximations (i.e. a 95% confidence intervals will be closelyapproximated by estimate ± 1.96 × standard error).The estimators of σ1, σ2 and log(σ) are also well approximated by anormal. If anything, the estimators of σ1 and σ2 are skewed to theleft rather than skewed to the right.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 18 / 20

Page 24: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Profile pairs for many parameters

Scatter Plot Matrix

.sig014 6 810 14

−3−2−1

0

.sig02

4681012 8 10

0 1 2 3

.lsig

3.25

3.30

3.353.30

0 1 2 3

(Intercept)

250260270280290300310

280 310

0 1 2 3

mathkind

−0.54−0.52−0.50−0.48−0.46−0.44−0.42−0.40

−0.46

0 1 2 3

minorityY

−15

−10

−5−10 −5

0 1 2 3

ses

2468

0 1 2 3

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 19 / 20

Page 25: Mixed models in R using the lme4 package Part 3: Inference ...lme4.r-forge.r-project.org/slides/2011-03-16-Amsterdam/3Profiling.pdf · Mixed models in R using the lme4 package Part

Summary

Profile of the deviance with respect to the parameters in the modelallow us to assess the variability in the parameters in terms of howwell the model can be fit.

We apply the signed square root transformation to the change in thedeviance to produce ζ. When the Gaussian approximation to thedistribution of the parameter estimate is appropriate, this function willbe close to a straight line.

Profile zeta plots and profile pairs plots provide visual assessment ofthe precision of parameter estimates.

Typically the distribution of variance component estimates is highlyskewed to the right and poorly approximated by a Gaussian, implyingthat standard errors of such estimates are of little value.

Douglas Bates (Multilevel Conf.) Profiling 2011-03-16 20 / 20