2014-12-17 15 views
5

chciałbym wyodrębnić pewne rezultaty z lmermod obiektuWyciąganie wynika z `lmermod` sprzeciw

require(lme4) 
(fm1 <- lmer(Yield ~ 1|Batch, Dyestuff)) 

ta produkuje

Linear mixed model fit by REML ['lmerMod'] 
Formula: Yield ~ 1 | Batch 
    Data: Dyestuff 
REML criterion at convergence: 319.6543 
Random effects: 
Groups Name  Std.Dev. 
Batch (Intercept) 42.00 
Residual    49.51 
Number of obs: 30, groups: Batch, 6 
Fixed Effects: 
(Intercept) 
     1527 

W szczególności chciałbym wyodrębnić standardowe devations z 2 efekty losowe, tj. 42,00 i 49,51. Chyba nie może być wbudowany w sposób to zrobić, ale nie mogłem znaleźć go szybko, więc pomyślałem, że powinienem być w stanie go znaleźć za pomocą str(fm1), która produkuje to:

Formal class 'lmerMod' [package "lme4"] with 13 slots 
    [email protected] resp :Reference class 'lmerResp' [package "lme4"] with 9 fields 
    .. ..$ Ptr :<externalptr> 
    .. ..$ mu  : num [1:30] 1510 1510 1510 1510 1510 ... 
    .. ..$ offset : num [1:30] 0 0 0 0 0 0 0 0 0 0 ... 
    .. ..$ sqrtXwt: num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. ..$ sqrtrwt: num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. ..$ weights: num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. ..$ wtres : num [1:30] 35.1 -69.9 -69.9 10.1 70.1 ... 
    .. ..$ y  : num [1:30] 1545 1440 1440 1520 1580 ... 
    .. ..$ REML : int 1 
    .. ..and 26 methods, of which 14 are possibly relevant: 
    .. .. allInfo, copy#envRefClass, initialize, initialize#lmResp, 
    .. .. initializePtr, initializePtr#lmResp, objective, ptr, ptr#lmResp, 
    .. .. setOffset, setResp, setWeights, updateMu, wrss 
    [email protected] Gp  : int [1:2] 0 6 
    [email protected] call : language lmer(formula = Yield ~ 1 | Batch, data = Dyestuff) 
    [email protected] frame :'data.frame':  30 obs. of 2 variables: 
    .. ..$ Yield: num [1:30] 1545 1440 1440 1520 1580 ... 
    .. ..$ Batch: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 2 2 2 2 2 ... 
    .. ..- attr(*, "terms")=Classes 'terms', 'formula' length 3 Yield ~ 1 + Batch 
    .. .. .. ..- attr(*, "variables")= language list(Yield, Batch) 
    .. .. .. ..- attr(*, "factors")= int [1:2, 1] 0 1 
    .. .. .. .. ..- attr(*, "dimnames")=List of 2 
    .. .. .. .. .. ..$ : chr [1:2] "Yield" "Batch" 
    .. .. .. .. .. ..$ : chr "Batch" 
    .. .. .. ..- attr(*, "term.labels")= chr "Batch" 
    .. .. .. ..- attr(*, "order")= int 1 
    .. .. .. ..- attr(*, "intercept")= int 1 
    .. .. .. ..- attr(*, "response")= int 1 
    .. .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
    .. .. .. ..- attr(*, "predvars")= language list(Yield, Batch) 
    .. .. .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor" 
    .. .. .. .. ..- attr(*, "names")= chr [1:2] "Yield" "Batch" 
    .. .. .. ..- attr(*, "predvars.fixed")= language list(Yield) 
    .. ..- attr(*, "formula")=Class 'formula' length 3 Yield ~ 1 | Batch 
    .. .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
    [email protected] flist :List of 1 
    .. ..$ Batch: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 2 2 2 2 2 ... 
    .. ..- attr(*, "assign")= int 1 
    [email protected] cnms :List of 1 
    .. ..$ Batch: chr "(Intercept)" 
    [email protected] lower : num 0 
    [email protected] theta : num 0.848 
    [email protected] beta : num 1527 
    [email protected] u  : num [1:6] -20.755 0.461 33.669 -27.212 66.877 ... 
    [email protected] devcomp:List of 2 
    .. ..$ cmp : Named num [1:10] 9.15 1.88 61495.41 9590.84 71086.25 ... 
    .. .. ..- attr(*, "names")= chr [1:10] "ldL2" "ldRX2" "wrss" "ussq" ... 
    .. ..$ dims: Named int [1:12] 30 30 1 29 1 6 1 1 0 1 ... 
    .. .. ..- attr(*, "names")= chr [1:12] "N" "n" "p" "nmp" ... 
    [email protected] pp  :Reference class 'merPredD' [package "lme4"] with 18 fields 
    .. ..$ Lambdat:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
    .. .. .. [email protected] i  : int [1:6] 0 1 2 3 4 5 
    .. .. .. [email protected] p  : int [1:7] 0 1 2 3 4 5 6 
    .. .. .. [email protected] Dim  : int [1:2] 6 6 
    .. .. .. [email protected] Dimnames:List of 2 
    .. .. .. .. ..$ : NULL 
    .. .. .. .. ..$ : NULL 
    .. .. .. [email protected] x  : num [1:6] 0.848 0.848 0.848 0.848 0.848 ... 
    .. .. .. [email protected] factors : list() 
    .. ..$ LamtUt :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
    .. .. .. [email protected] i  : int [1:30] 0 0 0 0 0 1 1 1 1 1 ... 
    .. .. .. [email protected] p  : int [1:31] 0 1 2 3 4 5 6 7 8 9 ... 
    .. .. .. [email protected] Dim  : int [1:2] 6 30 
    .. .. .. [email protected] Dimnames:List of 2 
    .. .. .. .. ..$ : NULL 
    .. .. .. .. ..$ : NULL 
    .. .. .. [email protected] x  : num [1:30] 0.848 0.848 0.848 0.848 0.848 ... 
    .. .. .. [email protected] factors : list() 
    .. ..$ Lind : int [1:6] 1 1 1 1 1 1 
    .. ..$ Ptr :<externalptr> 
    .. ..$ RZX : num [1:6, 1] 1.98 1.98 1.98 1.98 1.98 ... 
    .. ..$ Ut  :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
    .. .. .. [email protected] i  : int [1:30] 0 0 0 0 0 1 1 1 1 1 ... 
    .. .. .. [email protected] p  : int [1:31] 0 1 2 3 4 5 6 7 8 9 ... 
    .. .. .. [email protected] Dim  : int [1:2] 6 30 
    .. .. .. [email protected] Dimnames:List of 2 
    .. .. .. .. ..$ : chr [1:6] "A" "B" "C" "D" ... 
    .. .. .. .. ..$ : NULL 
    .. .. .. [email protected] x  : num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. .. .. [email protected] factors : list() 
    .. ..$ Utr : num [1:6] 6384 6481 6634 6354 6787 ... 
    .. ..$ V  : num [1:30, 1] 1 1 1 1 1 1 1 1 1 1 ... 
    .. ..$ VtV : num [1, 1] 30 
    .. ..$ Vtr : num 45825 
    .. ..$ X  : num [1:30, 1] 1 1 1 1 1 1 1 1 1 1 ... 
    .. .. ..- attr(*, "dimnames")=List of 2 
    .. .. .. ..$ : chr [1:30] "1" "2" "3" "4" ... 
    .. .. .. ..$ : chr "(Intercept)" 
    .. .. ..- attr(*, "assign")= int 0 
    .. ..$ Xwts : num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. ..$ Zt  :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
    .. .. .. [email protected] i  : int [1:30] 0 0 0 0 0 1 1 1 1 1 ... 
    .. .. .. [email protected] p  : int [1:31] 0 1 2 3 4 5 6 7 8 9 ... 
    .. .. .. [email protected] Dim  : int [1:2] 6 30 
    .. .. .. [email protected] Dimnames:List of 2 
    .. .. .. .. ..$ : chr [1:6] "A" "B" "C" "D" ... 
    .. .. .. .. ..$ : NULL 
    .. .. .. [email protected] x  : num [1:30] 1 1 1 1 1 1 1 1 1 1 ... 
    .. .. .. [email protected] factors : list() 
    .. ..$ beta0 : num 0 
    .. ..$ delb : num 1527 
    .. ..$ delu : num [1:6] -20.755 0.461 33.669 -27.212 66.877 ... 
    .. ..$ theta : num 0.848 
    .. ..$ u0  : num [1:6] 0 0 0 0 0 0 
    .. ..and 42 methods, of which 30 are possibly relevant: 
    .. .. b, beta, CcNumer, copy#envRefClass, initialize, initializePtr, 
    .. .. installPars, L, ldL2, ldRX2, linPred, P, ptr, RX, RXdiag, RXi, 
    .. .. setBeta0, setDelb, setDelu, setTheta, solve, solveU, sqrL, u, unsc, 
    .. .. updateDecomp, updateL, updateLamtUt, updateRes, updateXwts 
    [email protected] optinfo:List of 7 
    .. ..$ optimizer: chr "bobyqa" 
    .. ..$ control :List of 1 
    .. .. ..$ iprint: int 0 
    .. ..$ derivs :List of 2 
    .. .. ..$ gradient: num 1.61e-07 
    .. .. ..$ Hessian : num [1, 1] 14.1 
    .. ..$ conv  :List of 2 
    .. .. ..$ opt : int 0 
    .. .. ..$ lme4: list() 
    .. ..$ feval : int 16 
    .. ..$ warnings : list() 
    .. ..$ val  : num 0.848 

... ale to nie pozostawia mi mądrzejszego.

+0

próbowałeś za pomocą 'atrybuty (FM1)'? –

+0

@DavidArenburg Nie miałem, więc po prostu próbowałem i znalazłem drugi element jako 'fm1 @ devcomp $ cmp [10]', ale nadal nie mogę znaleźć pierwszego. –

+0

Klasa jest pisana 'lmerMod' –

Odpowiedz

5

lme4 materiały VarCorr ekstrakcji wariancji i korelacji komponentów:

varcor <- VarCorr(fm1) 
as.data.frame(varcor) 
#  grp  var1 var2 vcov sdcor 
#1 Batch (Intercept) <NA> 1764.05 42.0006 
#2 Residual  <NA> <NA> 2451.25 49.5101 
+2

jeśli OP może zasugerować, gdzie w dokumentacji, którą sprawdził/spodziewał się znaleźć te informacje, mógłbym spróbować poprawić dokumentację, aby było łatwiej znaleźć ... –

+0

Cóż. Po prostu spojrzałem (w sekwencji) na '? Lmer' i po przejrzeniu indeksu na'? 'Klasie lmerMod'' i wypróbowałem '? Summary.lmerMod' (chociaż ta ostatnia nie istnieje). vcov', ale nie udał się tam, ponieważ kontekst wskazał, że był tylko dla efektów stałych. Wygląda na to, że prawdopodobnie powinienem był tam pojechać, ponieważ jakiś pomocny adnotator mógłby w przyszłości umieścić tam również link. –

+0

Myślę, że niewygodne jest to, że 'class (fm1)' jest 'lmerMod', ale metody, które chcesz, są dla klasy' VarCorr.merMod. 'Kiedy robisz' metody (class = "lm") ', otrzymujesz garść użytecznych funkcji, ale 'metody (class =" lmerMod ")' nic nie zwraca. Jeśli użytkownik nie zna funkcji 'VarCorr' (czytając dokumentację) lub wyodrębnił' summary (fm1) $ varcor' po przejrzeniu 'str', może to być trudne dla użytkownika, aby znaleźć potrzebne informacje. Kiedy wpadłem na ten problem na początku zeszłego roku, użyłem super-getto 'capture.output' do metody przetwarzania tekstu. edytowane tak, aby odzwierciedlało 'lmerMod' – Vlo

Powiązane problemy