-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmer-data-extract-boot-fnc.R
63 lines (44 loc) · 2.25 KB
/
lmer-data-extract-boot-fnc.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
lmer.data.extract.boot = function(lmer.mod, iter, name=deparse(substitute(lmer.mod))){
#extract predictor names & create data frame, attach other cols to new data frame
mod.data = data.frame(summary(lmer.mod)$coefficients[,1])
names(mod.data) = "estimate"
mod.data$std.error = as.numeric(summary(lmer.mod)$coefficients[,2]) #std errors
mod.data$df = as.numeric(summary(lmer.mod)$coefficients[,3]) #degrees of freedom
mod.data$t.val = as.numeric(summary(lmer.mod)$coefficients[,4]) #t-values
mod.data$p.val = as.numeric(summary(lmer.mod)$coefficients[,5]) #p-values
#extract AIC, BIC, logLik, deviance df.resid
mod.data$AIC = as.numeric(summary(lmer.mod)$AIC[1])
mod.data$BIC = as.numeric(summary(lmer.mod)$AICtab[2][1])
mod.data$logLik = as.numeric(summary(lmer.mod)$AICtab[3][1])
mod.data$deviance = as.numeric(summary(lmer.mod)$AICtab[4][1])
mod.data$df.resid = as.numeric(summary(lmer.mod)$AICtab[5][1])
#add number of datapoints
mod.data$N = as.numeric(summary(lmer.mod)$devcomp$dims[1])
#add model name
mod.data$model = name
mod.data$iter = iter
return(mod.data)
}
lmer.ranef.data.extract.boot = function(lmer.mod, iter, name=deparse(substitute(lmer.mod))){
#extract random effect variance, standard error, correlations between slope and intercept
mod.data.ranef = as.data.frame(VarCorr(lmer.mod))
mod.data.ranef$n.subj = as.numeric(summary(lmer.mod)$ngrps[1]) #number of subjects
mod.data.ranef$n.item = as.numeric(summary(lmer.mod)$ngrps[2]) #number of items
#add number of datapoints
mod.data.ranef$N = as.numeric(summary(lmer.mod)$devcomp$dims[1])
#add model name
mod.data.ranef$model = name
mod.data.ranef$iter = iter
return(mod.data.ranef)
}
lmer.optim.data.extract.boot = function(lmer.mod, iter, name=deparse(substitute(lmer.mod))){
optim.data = as.data.frame(lmer.mod@optinfo$derivs$gradient)
names(optim.data) = "gradient"
optim.data$optimizer = lmer.mod@optinfo$optimizer
optim.data$conv.opt = lmer.mod@optinfo$conv$opt
optim.data$code = lmer.mod@optinfo$conv$lme4$code
optim.data$fval = lmer.mod@optinfo$feval
optim.data$val = lmer.mod@optinfo$val
optim.data$model = name
return(optim.data)
}