Example: barber

Using lme4: Mixed-Effects Modeling in R

SimpleLongitudinalInteractionsTheoryGLMM Item ResponseNLMMU sing lme4 : Mixed-Effects Modeling in RDouglas BatesUniversity of Wisconsin - Madisonand R Development Core 11, 2008 SimpleLongitudinalInteractionsTheoryGLMM Item ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the

most R model- tting functions, this is the rst argument. The model formula consists of two expressions separated by the ˘symbol. The expression on the left, typically the name of a variable, is evaluated as the response. The right-hand side consists of one or more terms separated by ‘+’ symbols.

Tags:

  Using, Mixed, Tting, Using lme4, Lme4

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Using lme4: Mixed-Effects Modeling in R

1 SimpleLongitudinalInteractionsTheoryGLMM Item ResponseNLMMU sing lme4 : Mixed-Effects Modeling in RDouglas BatesUniversity of Wisconsin - Madisonand R Development Core 11, 2008 SimpleLongitudinalInteractionsTheoryGLMM Item ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data.

2 Simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO utlineOrganizing and plotting data.

3 Simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMWeb sites associated with the bates/UseR2008 Materials for the Main web site for the R Comprehensive R Archive Network primary Main mirror for R-Forge, development site for many public Rpackages. This is also the URL of the repository forinstalling the development versions of thelme4andMatrixpackages, if you are so development site for thelme4packageSimpleLongitudinalInteract ionsTheoryGLMMItem ResponseNLMMO utlineOrganizing and plotting data; simple, scalar random effectsModels for longitudinal dataInteractions of grouping factors and other covariatesEvaluating the log-likelihoodGeneralized Linear mixed ModelsItem Response Models as GLMMsNonlinear mixed ModelsSimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMO rganizing data in R Standard rectangular data sets (columns are variables, rowsare observations) are stored inRasdata frames.

4 The columns can benumericvariables ( measurements orcounts) orfactorvariables (categorical data) ororderedfactorvariables. These types are called theclassof the variable. Thestrfunction provides a concise description of thestructure of a data set (or any other class of object in R). Thesummaryfunction summarizes each variable according to itsclass. Both are highly recommended for routine use. Entering just the name of the data frame causes it to beprinted. For large data frames use theheadandtailfunctions to view the first few or last few ResponseNLMMR packages Packages incorporate functions, data and documentation. You can produce packages for private or in-house use or youcan contribute your package to the Comprehensive R ArchiveNetwork (CRAN), We will be Using thelme4package from CRAN.

5 Install it fromthePackagesmenu item or with> (" lme4 ") You only need to install a package once. If a new versionbecomes available you can update (see the menu item). To use a package in an R session you attach it Using > require( lme4 )or> library( lme4 )(This usage causes widespread confusion of the terms package and library .)SimpleLongitudinalInteractionsTheoryGL MMItem ResponseNLMMA ccessing documentation To be added to CRAN, a package must pass a series of qualitycontrol checks. In particular, all functions and data sets mustbe documented. Examples and tests can also be included. Thedatafunction provides names and brief descriptions ofthe data sets in a package.> data(package = " lme4 ")Data sets in package lme4 :Dyestuff Yield of dyestuff by batchDyestuff2 Yield of dyestuff by batchPastes Paste strength by batch and caskPenicillin Variation in penicillin testingcake Breakage angle of chocolate cakescbpp Contagious bovine pleuropneumoniasleepstudy Reaction times in a sleep deprivation study Use?

6 Followed by the name of a function or data set to viewits documentation. If the documentation contains an examplesection, you can execute it with ResponseNLMML attice graphics One of the strengths of R is its graphics capabilities. There are several styles of graphics in R. The style inDeepayan Sarkar slatticepackage is well-suited to the type ofdata we will be discussing. I will not show every piece of code used to produce the datagraphics. The code is available in the script files for the slides(and sometimes in the example sections of the data set sdocumentation). Deepayan s book,Lattice: Multivariate Data Visualizationwith R(Springer, 2008) provides in-depth documentation andexplanations of lattice graphics.

7 I also recommend Phil Spector s book,Data Manipulationwith R(Springer, 2008).SimpleLongitudinalInteractionsTheo ryGLMMItem ResponseNLMMThe Dyestuff data set TheDyestuff,PenicillinandPastesdata sets all comefrom the classic bookStatistical Methods in Research andProduction, edited by Davies and first published in 1947. TheDyestuffdata are a balanced one-way classification oftheYieldof dyestuff from samples produced from sixBatchesof an intermediate product. See?Dyestuff.> str(Dyestuff) : 30 obs. of 2 variables:$ Batch: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 2 2 2 2 2 ..$ Yield: num 1545 1440 1440 1520 1580 ..> summary(Dyestuff)Batch YieldA:5 Min. :1440B:5 1st Qu.

8 :1469C:5 Median :1530D:5 Mean :1528E:5 3rd Qu.:1575F:5 Max. :1635 SimpleLongitudinalInteractionsTheoryGLMM Item ResponseNLMMThe effect of the batches To emphasize thatBatchis categorical, we use letters insteadof numbers to designate the levels. Because there is no inherent ordering of the levels ofBatch,we will reorder the levels if, say, doing so can make a plotmore informative. The particular batches observed are just a selection of thepossible batches and are entirely used up during the course ofthe experiment. It is not particularly important to estimate and compare yieldsfrom these batches. Instead we wish to estimate thevariability in yields due to batch-to-batch variability.

9 TheBatchfactor will be used inrandom-effectsterms inmodels that we ResponseNLMMD yestuff data plotYield of dyestuff (grams of standard color)BatchFDABCE1450150015501600lllllll lllllllllllllllllllllll The line joins the mean yields of the six batches, which havebeen reordered by increasing mean yield. The vertical positions are jittered slightly to reduceoverplotting. The lowest yield for batch A was observed ontwo distinct preparations from that ResponseNLMMA Mixed-Effects model for the dyestuff yield> fm1 <- lmer(Yield ~ 1 + (1 | Batch), Dyestuff)> print(fm1)Linear mixed model fit by REMLF ormula: Yield ~ 1 + (1 | Batch)Data: DyestuffAIC BIC logLik deviance effects:Groups Name Variance (Intercept) of obs: 30, groups: Batch, 6 Fixed effects:Estimate Std.

10 Error t value(Intercept) Fitted modelfm1has one fixed-effect parameter, the meanyield, and one random-effects term, generating a simple,scalar random effect for each level ResponseNLMME xtracting information from the fitted model fm1is an object of class"mer"( Mixed-Effects representation). There are manyextractorfunctions that can be applied tosuch objects.> fixef(fm1)(Intercept) > ranef(fm1, drop = TRUE)$BatchA B C D E > fitted(fm1)[1] [9] [17] [25] ResponseNLMMD efinition of linear Mixed-Effects models A Mixed-Effects model incorporates two vector-valued randomvariables: the response,Y, and the random effects,B.


Related search queries