lme4: Linear Mixed-Effects Models using 'Eigen' and S4

> library(lme4)
Loading required package: Matrix

Attaching package: 'Matrix'

The following object is masked from 'package:tidyr':

    expand

バージョン: 1.1.11


関数名 概略
.prt.methTit Print and Summary Method Utilities for Mixed Effects
Arabidopsis Arabidopsis clipping/fertilization data
Dyestuff Yield of dyestuff by batch
GHrule Univariate Gauss-Hermite quadrature rule
GQdk Sparse Gaussian / Gauss-Hermite Quadrature grid
InstEval University Lecture/Instructor Evaluations by Students at ETH
NelderMead-class Class '"NelderMead"' of Nelder-Mead optimizers and its Generator
Nelder_Mead Nelder-Mead Optimization of Parameters, Possibly (Box) Constrained
Pastes Paste strength by batch and cask
Penicillin Variation in penicillin testing
VarCorr Extract Variance and Correlation Components
VerbAgg Verbal Aggression item responses
bootMer Model-based (Semi-)Parametric Bootstrap for Mixed Models
cake Breakage Angle of Chocolate Cakes
cbpp Contagious bovine pleuropneumonia
confint.merMod Compute Confidence Intervals for Parameters of a [ng]lmer Fit
convergence Assessing Convergence for Fitted Models
devcomp Extract the deviance component list
drop1.merMod Drop all possible single fixed-effect terms from a mixed effect model
dummy Dummy variables (experimental)
expandDoubleVerts Expand terms with "||" notation into separate "|" terms
factorize Attempt to convert grouping variables to factors
findbars Determine random-effects expressions from a formula
fixef Extract fixed-effects estimates
fortify add information to data based on a fitted model
getME Extract or Get Generalized Components from a Fitted Mixed Effects Model
glmFamily Generator object for the 'glmFamily' class
glmFamily-class Class '"glmFamily"' - a reference class for 'family'
glmer Fitting Generalized Linear Mixed-Effects Models
glmer.nb Fitting GLMM's for Negative Binomial
glmerLaplaceHandle Handle for 'glmerLaplace'
golden-class Class '"golden"' and Generator for Golden Search Optimizer Class
grouseticks Data on red grouse ticks from Elston et al. 2001
hatvalues.merMod Diagonal elements of the hat matrix
isNested Is f1 nested within f2?
isREML Check characteristics of models
lmList Fit List of lm Objects with a Common Model
lmList4-class Class "lmList4" of 'lm' Objects on Common Model
lmResp Generator objects for the response classes
lmResp-class Reference Classes for Response Modules, '"(lm|glm|nls|lmer)Resp"'
lme4-package Linear, generalized linear, and nonlinear mixed models
lmer Fit Linear Mixed-Effects Models
lmerControl Control of Mixed Model Fitting
merMod-class Class "merMod" of Fitted Mixed-Effect Models
merPredD Generator object for the 'merPredD' class
merPredD-class Class '"merPredD"' - a Dense Predictor Reference Class
mkMerMod Create a 'merMod' Object
mkParsTemplate Make templates suitable for guiding mixed model simulations
mkReTrms Make Random Effect Terms: Create Z, Lambda, Lind, etc.
mkRespMod Create an lmerResp, glmResp or nlsResp instance
mkVarCorr Make Variance and Correlation Matrices from 'theta'
mkdevfun Create Deviance Evaluation Function from Predictor and Response Module
modular Modular Functions for Mixed Model Fits
ngrps Number of Levels of a Factor or a "merMod" Model
nlformula Manipulate a Nonlinear Model Formula
nlmer Fitting Nonlinear Mixed-Effects Models
nloptwrap Wrappers for additional optimizers
nobars Omit terms separated by vertical bars in a formula
plot.lmList4 plots for lmList4 objects
plot.merMod diagnostic plots for merMod fits
predict.merMod Predictions from a model at new data values
profile-methods Profile method for merMod objects
pvalues Getting p-values for fitted models
ranef Extract the modes of the random effects
rePos Generator object for the rePos (random-effects positions) class
rePos-class Class '"rePos"'
refit Refit a (merMod) Model with a Different Response
refitML Refit a Model by Maximum Likelihood Criterion
residuals.merMod residuals of merMod objects
sigma Extract Residual Standard Deviation 'Sigma'
simulate.merMod Simulate Responses From 'merMod' Object
sleepstudy Reaction times in a sleep deprivation study subbars "Sub[stitute] Bars"
troubleshooting Troubleshooting
varianceProf Transform Profile to the variance scale
vcconv Convert between representations of (co-)variance structures
xyplot.thpr Mixed-Effects Profile Plots (Regular / Density / Pairs)

fixef

固定効果の抽出

> sleepstudy %>% lmer(Reaction ~ Days + (1 | Subject), data = .) %>% 
+   fixef()
(Intercept)        Days 
  251.40510    10.46729

lmer

混合効果モデルによる推定

Arguments

  • formula... ランダム効果とする変数は(|)で囲む
  • data
  • REML
  • control
  • start
  • verbose
  • subset
  • weights
  • na.action
  • offset
  • contrasts
  • devFunOnly
  • ...
> (fit <- sleepstudy %>% lmer(Reaction ~ Days + (Days | Subject), data = .))
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject)
   Data: .
REML criterion at convergence: 1743.628
Random effects:
 Groups   Name        Std.Dev. Corr
 Subject  (Intercept) 24.740       
          Days         5.922   0.07
 Residual             25.592       
Number of obs: 180, groups:  Subject, 18
Fixed Effects:
(Intercept)         Days  
     251.41        10.47
> summary(fit)
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject)
   Data: .

REML criterion at convergence: 1743.6

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.9536 -0.4634  0.0231  0.4634  5.1793 

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 612.09   24.740       
          Days         35.07    5.922   0.07
 Residual             654.94   25.592       
Number of obs: 180, groups:  Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.825   36.84
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.138
> fit %>% terms() %>% str()
Classes 'terms', 'formula' length 3 Reaction ~ Days
  ..- attr(*, "variables")= language list(Reaction, Days)
  ..- attr(*, "factors")= int [1:2, 1] 0 1
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "Reaction" "Days"
  .. .. ..$ : chr "Days"
  ..- attr(*, "term.labels")= chr "Days"
  ..- attr(*, "order")= int 1
  ..- attr(*, "intercept")= int 1
  ..- attr(*, "response")= int 1
  ..- attr(*, ".Environment")=<environment: 0x11c31e118> 
  ..- attr(*, "predvars")= language list(Reaction, Days)

ranef

混合効果モデルからランダム効果の表示

> sleepstudy %>% lmer(Reaction ~ Days + (Days | Subject), data = .) %>% 
+   ranef()
$Subject
    (Intercept)        Days
308   2.2585637   9.1989722
309 -40.3985802  -8.6197026
310 -38.9602496  -5.4488792
330  23.6905025  -4.8143320
331  22.2602062  -3.0698952
332   9.0395271  -0.2721709
333  16.8404333  -0.2236248
334  -7.2325803   1.0745763
335  -0.3336936 -10.7521594
337  34.8903534   8.6282835
349 -25.2101138   1.1734148
350 -13.0699598   6.6142055
351   4.5778364  -3.0152574
352  20.8635944   3.5360130
369   3.2754532   0.8722166
370 -25.6128737   4.8224653
371   0.8070401  -0.9881551
372  12.3145406   1.2840295

sleepstudy

> sleepstudy %>% {
+   print(class(.))
+   print(dplyr::glimpse(.))
+ }
[1] "data.frame"
Observations: 180
Variables: 3
$ Reaction (dbl) 249.5600, 258.7047, 250.8006, 321.4398, 356.8519, 414...
$ Days     (dbl) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7,...
$ Subject  (fctr) 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 30...
NULL