This question already has an answer here:
in R, extract part of object from list
(1 answer)
Closed 4 years ago.
I have a dataframe that looks like this:
> head(forecasts)
$`1_1`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.370299 7.335176 7.405422 7.316583 7.424015
$`1_10`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.396656 7.359845 7.433467 7.340359 7.452953
$`1_2`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.780033 7.752462 7.807605 7.737866 7.822201
$`1_3`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.216894 7.178896 7.254892 7.158781 7.275007
$`1_4`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.501195 7.465049 7.537341 7.445915 7.556475
$`1_5`
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Dec 2016 7.455131 7.424918 7.485345 7.408924 7.501339
I would like to extract only the Point Forecast
A call to str(forecasts) returns a lot of output, this is the output for just one of the 89 lists in the 'forecasts' variable:
$ 9_9 :List of 10
..$ method : chr "ARIMA(0,0,0)(0,1,0)[12] with drift"
..$ model :List of 19
.. ..$ coef : Named num 0.00965
.. .. ..- attr(*, "names")= chr "drift"
.. ..$ sigma2 : num 0.0047
.. ..$ var.coef : num [1, 1] 1.24e-06
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr "drift"
.. .. .. ..$ : chr "drift"
.. ..$ mask : logi TRUE
.. ..$ loglik : num 33.4
.. ..$ aic : num -62.7
.. ..$ arma : int [1:7] 0 0 0 0 12 0 1
.. ..$ residuals: Time-Series [1:38] from 2014 to 2017: 0.00546 0.00583 0.006 0.00564 0.00563 ...
.. ..$ call : language .f(y = .x[[i]], x = list(x = c(5.4677292870219, 5.85045765518954, 6.02852764863892, 5.67941181324485, 5.67526620| __truncated__ ...
.. ..$ series : chr ".x[[i]]"
.. ..$ code : int 0
.. ..$ n.cond : int 0
.. ..$ nobs : int 26
.. ..$ model :List of 10
.. .. ..$ phi : num(0)
.. .. ..$ theta: num(0)
.. .. ..$ Delta: num [1:12] 0 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ Z : num [1:13] 1 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ a : num [1:13] 0.0677 5.6916 5.7073 5.692 5.7108 ...
.. .. ..$ P : num [1:13, 1:13] 0 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ T : num [1:13, 1:13] 0 1 0 0 0 0 0 0 0 0 ...
.. .. ..$ V : num [1:13, 1:13] 1 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ h : num 0
.. .. ..$ Pn : num [1:13, 1:13] 1 0 0 0 0 0 0 0 0 0 ...
.. ..$ xreg : int [1:38, 1] 1 2 3 4 5 6 7 8 9 10 ...
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : NULL
.. .. .. ..$ : chr "drift"
.. ..$ bic : num -60.2
.. ..$ aicc : num -62.2
.. ..$ x : Time-Series [1:38] from 2014 to 2017: 5.47 5.85 6.03 5.68 5.68 ...
.. ..$ fitted : Time-Series [1:38] from 2014 to 2017: 5.46 5.84 6.02 5.67 5.67 ...
.. ..- attr(*, "class")= chr [1:2] "ARIMA" "Arima"
..$ level : num [1:2] 80 95
..$ mean : Time-Series [1:1] from 2017 to 2017: 6.32
..$ lower : Time-Series [1, 1:2] from 2017 to 2017: 6.23 6.18
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "80%" "95%"
..$ upper : Time-Series [1, 1:2] from 2017 to 2017: 6.4 6.45
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "80%" "95%"
..$ x : Time-Series [1:38] from 2014 to 2017: 5.47 5.85 6.03 5.68 5.68 ...
..$ series : chr ".x[[i]]"
..$ fitted : Time-Series [1:38] from 2014 to 2017: 5.46 5.84 6.02 5.67 5.67 ...
..$ residuals: Time-Series [1:38] from 2014 to 2017: 0.00546 0.00583 0.006 0.00564 0.00563 ...
..- attr(*, "class")= chr "forecast"
We can extract the values from the list using lapply
lapply(forecasts, function(x) as.numeric(x$mean, na.rm = TRUE)))
If the number of forecast are same in all the list elements, this can be converted to a matrix or data.frame
sapply(forecasts, `[[`, "mean")
Or using tidyverse
library(tidyverse)
forecasts %>%
map_df(~ .x$mean %>%
as.numeric)
Related
I obtain 0 fitted values when using nnet function as below:
nnet(realized1~ann_t1+ann_t2+ann_t3, data=df2_input, size=2)
Output is
> str(nnet(realized1~ann_t1+ann_t2+ann_t3, data=df2_input, size=2))
# weights: 11
initial value 134.845214
final value 0.147077
converged
List of 18
$ n : num [1:3] 3 2 1
$ nunits : int 7
$ nconn : num [1:8] 0 0 0 0 0 4 8 11
$ conn : num [1:11] 0 1 2 3 0 1 2 3 0 4 ...
$ nsunits : int 7
$ decay : num 0
$ entropy : logi FALSE
$ softmax : logi FALSE
$ censored : logi FALSE
$ value : num 0.147
$ wts : num [1:11] 14.815 -69.862 0.244 -0.456 -5.638 ...
$ convergence : int 0
$ fitted.values: num [1:800, 1] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:800] "1601" "1602" "1603" "1604" ...
.. ..$ : NULL
$ residuals : num [1:800, 1] 0.004267 0.000401 0.002404 0.022561 0.001354 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:800] "1601" "1602" "1603" "1604" ...
.. ..$ : NULL
$ call : language nnet.formula(formula = realized1 ~ ann_t1 + ann_t2 + ann_t3, data = df2_input, size = 2)
$ terms :Classes 'terms', 'formula' language realized1 ~ ann_t1 + ann_t2 + ann_t3
.. ..- attr(*, "variables")= language list(realized1, ann_t1, ann_t2, ann_t3)
.. ..- attr(*, "factors")= int [1:4, 1:3] 0 1 0 0 0 0 1 0 0 0 ...
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:4] "realized1" "ann_t1" "ann_t2" "ann_t3"
.. .. .. ..$ : chr [1:3] "ann_t1" "ann_t2" "ann_t3"
.. ..- attr(*, "term.labels")= chr [1:3] "ann_t1" "ann_t2" "ann_t3"
.. ..- attr(*, "order")= int [1:3] 1 1 1
.. ..- attr(*, "intercept")= int 1
.. ..- attr(*, "response")= int 1
.. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
.. ..- attr(*, "predvars")= language list(realized1, ann_t1, ann_t2, ann_t3)
.. ..- attr(*, "dataClasses")= Named chr [1:4] "numeric" "numeric" "numeric" "numeric"
.. .. ..- attr(*, "names")= chr [1:4] "realized1" "ann_t1" "ann_t2" "ann_t3"
$ coefnames : chr [1:3] "ann_t1" "ann_t2" "ann_t3"
$ xlevels : Named list()
- attr(*, "class")= chr [1:2] "nnet.formula" "nnet"
Input data frame is as below:
> str(df2_input)
'data.frame': 800 obs. of 4 variables:
$ realized1: num 0.004267 0.000401 0.002404 0.022561 0.001354 ...
$ ann_t1 : num -4.4 -4.19 -4.3 -4.48 -4.6 ...
$ ann_t2 : num 0 -0.002996 -0.000298 -0.001964 -0.01963 ...
$ ann_t3 : num 0 -0.01662 0.00165 -0.01089 -0.10887 ...
Why do I get zero predictions and how can I fix it?
Thanks a lot.
I have done many bayesian models using the MCMCglmm package in R, like this one:
model=MCMCglmm(scale(lifespan)~scale(weight)*scale(littersize),
random=~idv(DNA1)+idv(DNA2),
data=df,
family="gaussian",
prior=prior1,
thin=50,
burnin=5000,
nitt=50000,
verbose=F)
summary(model)
post.mean l-95% CI u-95% CI eff.samp pMCMC
(Intercept) 11.23327 8.368 13.73756 6228 <2e-04 ***
weight -1.63770 -2.059 -1.23457 6600 <2e-04 ***
littersize 0.40960 0.024 0.80305 6600 0.0415 *
weight:littersize -0.33411 -0.635 -0.04406 5912 0.0248 *
I would like to plot the resulting interaction (weight:littersize) with ggeffects or sjPlots packages, like this:
plot_model(model,
type = "int",
terms = c("scale(lifespan)", "scale(weight)", "scale(littersize)"),
mdrt.values = "meansd",
ppd = TRUE)
But I obtain the next output:
`scale(weight)` was not found in model terms. Maybe misspelled?
`scale(littersize)` was not found in model terms. Maybe misspelled?
Error in terms.default(model) : no terms component nor attribute
Además: Warning messages:
1: Some model terms could not be found in model data. You probably need to load the data into the environment.
2: Some model terms could not be found in model data. You probably need to load the data into the environment.
Data is already loaded. I tried to write terms differently without the "scale(x)" term, and changed the model too to deal with equal terms, but I am still getting this error message. I am also open to plot this interaction with different packages.
My model str(model) is:
>str(model)
List of 20
$ Sol : 'mcmc' num [1:6600, 1:4] -0.814 1.215 -2.119 -0.125 -1.648 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:4] "(Intercept)" "scale(weight)" "scale(littersize)" "scale(weight):scale(littersize)"
..- attr(*, "mcpar")= num [1:3] 7e+04 4e+05 5e+01
$ Lambda : NULL
$ VCV : 'mcmc' num [1:6600, 1:3] 1.094 0.693 1.58 0.645 1.161 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:3] "phylo." "haplo." "units"
..- attr(*, "mcpar")= num [1:3] 7e+04 4e+05 5e+01
$ CP : NULL
$ Liab : NULL
$ Fixed :List of 3
..$ formula:Class 'formula' language scale(lifespan) ~ scale(weight) * scale(littersize)
.. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..$ nfl : int 4
..$ nll : num 0
$ Random :List of 5
..$ formula:Class 'formula' language ~idv(phylo) + idv(haplo)
.. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..$ nfl : num [1:2] 1 1
..$ nrl : int [1:2] 92 92
..$ nat : num [1:2] 0 0
..$ nrt : int [1:2] 1 1
$ Residual :List of 6
..$ formula :Class 'formula' language ~units
.. .. ..- attr(*, ".Environment")=<environment: 0x0000025ba05f8938>
..$ nfl : num 1
..$ nrl : int 92
..$ nrt : int 1
..$ family : chr "gaussian"
..$ original.family: chr "gaussian"
$ Deviance : 'mcmc' num [1:6600] -262.6 -137.3 -203.6 -83.6 -29.1 ...
..- attr(*, "mcpar")= num [1:3] 7e+04 4e+05 5e+01
$ DIC : num -158
$ X :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. ..# i : int [1:368] 0 1 2 3 4 5 6 7 8 9 ...
.. ..# p : int [1:5] 0 92 184 276 368
.. ..# Dim : int [1:2] 92 4
.. ..# Dimnames:List of 2
.. .. ..$ : chr [1:92] "1.1" "2.1" "3.1" "4.1" ...
.. .. ..$ : chr [1:4] "(Intercept)" "scale(weight)" "scale(littersize)" "scale(weight):scale(littersize)"
.. ..# x : num [1:368] 1 1 1 1 1 1 1 1 1 1 ...
.. ..# factors : list()
$ Z :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. ..# i : int [1:16928] 0 1 2 3 4 5 6 7 8 9 ...
.. ..# p : int [1:185] 0 92 184 276 368 460 552 644 736 828 ...
.. ..# Dim : int [1:2] 92 184
.. ..# Dimnames:List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:184] "phylo1.NA.1" "phylo2.NA.1" "phylo3.NA.1" "phylo4.NA.1" ...
.. ..# x : num [1:16928] 0.4726 0.0869 0.1053 0.087 0.1349 ...
.. ..# factors : list()
$ ZR :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. ..# i : int [1:92] 0 1 2 3 4 5 6 7 8 9 ...
.. ..# p : int [1:93] 0 1 2 3 4 5 6 7 8 9 ...
.. ..# Dim : int [1:2] 92 92
.. ..# Dimnames:List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:92] "units.1" "units.2" "units.3" "units.4" ...
.. ..# x : num [1:92] 1 1 1 1 1 1 1 1 1 1 ...
.. ..# factors : list()
$ XL : NULL
$ ginverse : NULL
$ error.term : int [1:92] 1 1 1 1 1 1 1 1 1 1 ...
$ family : chr [1:92] "gaussian" "gaussian" "gaussian" "gaussian" ...
$ Tune : num [1, 1] 1
..- attr(*, "dimnames")=List of 2
.. ..$ : chr "1"
.. ..$ : chr "1"
$ meta : logi FALSE
$ y.additional: num [1:92, 1:2] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, "class")= chr "MCMCglmm"
Thank you.
Try to scale your predictors before fitting the model, i.e.
df$lifespan <- as.vecor(scale(df$lifespan))
Or better, use effectsize::standardize(), which does not create a matrix for a one-dimensial vector when scaling your variables:
df <- effectsize::standardize(df, select = c("lifespan", "weight", "littersize"))
Then you can call your model like this:
model <- MCMCglmm(lifespan ~ weight * littersize,
random=~idv(DNA1)+idv(DNA2),
data=df,
family="gaussian",
prior=prior1,
thin=50,
burnin=5000,
nitt=50000,
verbose=F)
Does this work?
I have created an MI data set using the MICE package with 7 imputed data sets
imputeddata <- mice(distress_tibmi, m=7)
the structure of my data is now:
..$ id : num [1:342] 4 8 10 11 23 32 40 47 48 56 ...
..$ diagnosis : Factor w/ 2 levels "psychosis","bpd": 1 1 1 1 1 1 1 1 1 1 ...
..$ gender : Factor w/ 2 levels "female","male": 1 2 2 2 2 1 1 1 1 1 ...
..$ distress.time : Factor w/ 2 levels "baseline","post": 1 1 1 1 1 1 1 1 1 1 ...
..$ distress.score: num [1:342] -2.436 -1.242 0.251 -1.54 0.549 ...
..$ depression : num [1:342] 0.332 0.542 1.172 -0.298 1.172 ...
..$ anxiety : num [1:342] -1.898 -0.687 0.87 -0.687 1.043 ...
..$ choice : num [1:342] 6.73 2.18 2 6.45 3.55 ...
$ imp :List of 8
..$ id :'data.frame': 0 obs. of 7 variables:
.. ..$ 1: logi(0)
.. ..$ 2: logi(0)
.. ..$ 3: logi(0)
.. ..$ 4: logi(0)
.. ..$ 5: logi(0)
.. ..$ 6: logi(0)
.. ..$ 7: logi(0)
..$ diagnosis :'data.frame': 0 obs. of 7 variables:
.. ..$ 1: logi(0)
.. ..$ 2: logi(0)
.. ..$ 3: logi(0)
.. ..$ 4: logi(0)
.. ..$ 5: logi(0)
.. ..$ 6: logi(0)
.. ..$ 7: logi(0)
..$ gender :'data.frame': 0 obs. of 7 variables:
.. ..$ 1: logi(0)
.. ..$ 2: logi(0)
.. ..$ 3: logi(0)
.. ..$ 4: logi(0)
.. ..$ 5: logi(0)
.. ..$ 6: logi(0)
.. ..$ 7: logi(0)
..$ distress.time :'data.frame': 0 obs. of 7 variables:
.. ..$ 1: logi(0)
.. ..$ 2: logi(0)
.. ..$ 3: logi(0)
.. ..$ 4: logi(0)
.. ..$ 5: logi(0)
.. ..$ 6: logi(0)
.. ..$ 7: logi(0)
..$ distress.score:'data.frame': 59 obs. of 7 variables:
.. ..$ 1: num [1:59] -0.6808 -0.6448 -1.658 -0.0293 -0.3463 ...
.. ..$ 2: num [1:59] 1.2736 0.2507 -0.0478 -0.6448 1.2736 ...
.. ..$ 3: num [1:59] -0.681 0.848 -1.658 1.274 0.251 ...
.. ..$ 4: num [1:59] -1.3322 -0.0478 -0.6808 -0.355 -2.4358 ...
.. ..$ 5: num [1:59] -1.3322 -0.355 -4.8239 -0.6448 -0.0293 ...
.. ..$ 6: num [1:59] -1.3322 0.5493 -0.0293 -2.6352 0.8478 ...
.. ..$ 7: num [1:59] 0.5493 0.2507 1.1463 -0.0478 1.2736 ...
..$ depression :'data.frame': 24 obs. of 7 variables:
.. ..$ 1: num [1:24] -0.0882 -0.5084 -1.2966 0.542 -2.1891 ...
.. ..$ 2: num [1:24] 0.332 0.255 1.592 0.752 0.945 ...
.. ..$ 3: num [1:24] -2.159 0.332 -0.262 0.962 1.382 ...
.. ..$ 4: num [1:24] -0.2621 -0.0897 -1.7689 1.1172 0.7724 ...
.. ..$ 5: num [1:24] 0.122 -2.159 -2.399 1.462 -2.189 ...
.. ..$ 6: num [1:24] -0.298 -0.434 -0.607 1.172 0.962 ...
.. ..$ 7: num [1:24] 0.6 1.29 1.635 0.542 0.428 ...
..$ anxiety :'data.frame': 10 obs. of 7 variables:
.. ..$ 1: num [1:10] 0.909 -1.379 1.389 -1.268 -0.598 ...
.. ..$ 2: num [1:10] 1.0433 -1.3789 -0.0955 -0.7655 -0.598 ...
.. ..$ 3: num [1:10] 1.0771 -1.8979 -0.0955 -0.5138 0.0052 ...
.. ..$ 4: num [1:10] -0.598 -1.603 0.9095 -2.608 -0.0955 ...
.. ..$ 5: num [1:10] 0.742 0.2395 -1.7249 -2.1055 -0.0955 ...
.. ..$ 6: num [1:10] 1.412 -0.86 1.389 -2.608 0.575 ...
.. ..$ 7: num [1:10] 1.245 -1.033 0.909 0.909 -1.033 ...
..$ choice :'data.frame': 22 obs. of 7 variables:
.. ..$ 1: num [1:22] 4.55 3.91 7.09 4.27 3.55 ...
.. ..$ 2: num [1:22] 8.09 5.09 5.36 4.91 4.45 ...
.. ..$ 3: num [1:22] 4.27 7.09 3.91 3.91 7.09 ...
.. ..$ 4: num [1:22] 5.82 6.27 7 6.82 4.73 ...
.. ..$ 5: num [1:22] 6.18 5.36 5.36 3.18 3.18 ...
.. ..$ 6: num [1:22] 6.18 6.73 4.73 4.73 5 ...
.. ..$ 7: num [1:22] 5.45 7.09 7.45 3.18 4.91 ...
$ m : num 7
$ where : logi [1:342, 1:8] FALSE FALSE FALSE FALSE FALSE FALSE ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:342] "1" "2" "3" "4" ...
.. ..$ : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ blocks :List of 8
..$ id : chr "id"
..$ diagnosis : chr "diagnosis"
..$ gender : chr "gender"
..$ distress.time : chr "distress.time"
..$ distress.score: chr "distress.score"
..$ depression : chr "depression"
..$ anxiety : chr "anxiety"
..$ choice : chr "choice"
..- attr(*, "calltype")= Named chr [1:8] "type" "type" "type" "type" ...
.. ..- attr(*, "names")= chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ call : language mice(data = distress_tibmi, m = 7)
$ nmis : Named int [1:8] 0 0 0 0 59 24 10 22
..- attr(*, "names")= chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ method : Named chr [1:8] "" "" "" "" ...
..- attr(*, "names")= chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ predictorMatrix: num [1:8, 1:8] 0 1 1 1 1 1 1 1 1 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
.. ..$ : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ visitSequence : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ formulas :List of 8
..$ id :Class 'formula' language id ~ 0 + diagnosis + gender + distress.time + distress.score + depression + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ diagnosis :Class 'formula' language diagnosis ~ 0 + id + gender + distress.time + distress.score + depression + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ gender :Class 'formula' language gender ~ 0 + id + diagnosis + distress.time + distress.score + depression + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ distress.time :Class 'formula' language distress.time ~ 0 + id + diagnosis + gender + distress.score + depression + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ distress.score:Class 'formula' language distress.score ~ 0 + id + diagnosis + gender + distress.time + depression + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ depression :Class 'formula' language depression ~ 0 + id + diagnosis + gender + distress.time + distress.score + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ anxiety :Class 'formula' language anxiety ~ 0 + id + diagnosis + gender + distress.time + distress.score + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
..$ choice :Class 'formula' language choice ~ 0 + id + diagnosis + gender + distress.time + distress.score + ...
.. .. ..- attr(*, ".Environment")=<environment: 0x7ff907cd9d00>
$ post : Named chr [1:8] "" "" "" "" ...
..- attr(*, "names")= chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
$ blots :List of 8
..$ id : list()
..$ diagnosis : list()
..$ gender : list()
..$ distress.time : list()
..$ distress.score: list()
..$ depression : list()
..$ anxiety : list()
..$ choice : list()
$ seed : logi NA
$ iteration : num 5
$ lastSeedValue : int [1:626] 10403 331 -1243825859 461242975 2057104913 -837414599 -54045022 1529270132 -105270003 -1459771035 ...
$ chainMean : num [1:8, 1:5, 1:7] NaN NaN NaN NaN -0.727 ...
..- attr(*, "dimnames")=List of 3
.. ..$ : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
.. ..$ : chr [1:5] "1" "2" "3" "4" ...
.. ..$ : chr [1:7] "Chain 1" "Chain 2" "Chain 3" "Chain 4" ...
$ chainVar : num [1:8, 1:5, 1:7] NA NA NA NA 2.26 ...
..- attr(*, "dimnames")=List of 3
.. ..$ : chr [1:8] "id" "diagnosis" "gender" "distress.time" ...
.. ..$ : chr [1:5] "1" "2" "3" "4" ...
.. ..$ : chr [1:7] "Chain 1" "Chain 2" "Chain 3" "Chain 4" ...
$ loggedEvents : NULL
$ version :Classes 'package_version', 'numeric_version' hidden list of 1
..$ : int [1:3] 3 9 0
$ date : Date[1:1], format: ...
- attr(*, "class")= chr "mids"
Show in New WindowClear OutputExpand/Collapse Output
id diagnosis gender
Min. : 1.00 psychosis:250 female:196
1st Qu.: 76.75 bpd : 92 male :146
Median :198.00
Mean :215.66
3rd Qu.:337.00
Max. :514.00
distress.time distress.score depression
baseline:171 Min. :-4.8239 Min. :-2.39920
post :171 1st Qu.:-0.6808 1st Qu.:-0.76410
Median :-0.0293 Median : 0.08280
Mean :-0.3083 Mean :-0.06085
3rd Qu.: 0.6221 3rd Qu.: 0.77240
Max. : 1.2736 Max. : 1.80690
NA's :59 NA's :24
anxiety choice
Min. :-2.6080 Min. :0.0909
1st Qu.:-0.9330 1st Qu.:2.4545
Median :-0.0955 Median :4.0454
Mean :-0.1397 Mean :3.8903
3rd Qu.: 0.8702 3rd Qu.:5.1136
Max. : 1.7471 Max. :8.0909
NA's :10 NA's :22
Show in New WindowClear OutputExpand/Collapse Output
1
<dbl>
2
<dbl>
3
<dbl>
4
<dbl>
5
<dbl>
6
<dbl>
7
<dbl>
21 -0.6808 1.2736 -0.6808 -1.3322 -1.3322 -1.3322 0.5493
34 -0.6448 0.2507 0.8478 -0.0478 -0.3550 0.5493 0.2507
48 -1.6580 -0.0478 -1.6580 -0.6808 -4.8239 -0.0293 1.1463
141 -0.0293 -0.6448 1.2736 -0.3550 -0.6448 -2.6352 -0.0478
143 -0.3463 1.2736 0.2507 -2.4358 -0.0293 0.8478 1.2736
180 1.1463 -1.0065 -2.3094 -3.6124 -0.6448 -1.5403 -1.0065
181 -0.0293 -0.6808 -0.6808 -3.9381 -0.3463 -1.3322 0.2964
182 1.2736 -0.3463 0.9479 -0.0478 0.9479 -0.3463 1.1463
197 -0.3550 -0.0293 -0.6808 -0.3550 -1.3322 -4.8239 -0.6448
208 0.6221 0.2507 -0.6808 -0.3550 -0.6448 0.6221 -0.6448
1-10 of 59 rows
I created a lm with the imputed data set and summarised it using pool()
distressmodel <- with(data = imputeddata, exp = lm(distress.score ~ distress.time * diagnosis))
summary(mice::pool(distressmodel), conf.int = TRUE, conf.level = 0.95 )
however now I want to get the type 3 F values for the model, but this code is not working
car::Anova(mice::pool(distressmodel), type = 3)
it produces this error message:
Error in UseMethod("vcov") : no applicable method for 'vcov' applied to an object of class "c('mipo', 'data.frame')"
I also want to get the marginal effects of the model (eg see effects from only one level of the grouping variable which is diagnosis) which I have done successfully in my complete case analysis, but this code:
summary(margins(distressmodel, data = subset(imputeddata, diagnosis == "bpd", type = "response")))
produces this error
Error in subset_datlist(datlist = x, subset = subset, select = select, : object 'diagnosis' not found
Does anyone have any advice on alterations to the code or way to get the car::anova or margins () packages to work with an MI data set? (preferably being able to pool the results
The with(data, exp) procedure can be used to apply statistical test/models to multiple imputation outputs (mipo) only if they allow extracting the estimates with the coef method and a variance-covariance matrix with vcov. The latter seems not to work for the function car::Anova that you used.
Fortunately, there is the miceadds package, which offers procedures to conduct and pool additional statistical tests. miceadds::mi.anova seems to do exactly what you want:
miceadds::mi.anova(imputeddata, distress.score ~ distress.time * diagnosis, type=3)
I am not sure, however, about the marginal effects. In general, you can do a bit more coding and apply any statistical procedure to each imputed sample separately. Then you can pool it using the pool.scalar function. This method also gives you within-imputation, between-imputation, and total variance estimates for your pooled statistic. (And with that you can conduct a basic t-test for difference from 0, if you want.)
This approach relies on normal distribution of statistics – or on them being transformable to a normally distributed metric. (Stef van Buuren gives a list of statistics that can easily be transformed, pooled, and back-transformed here, see Table 5.2) So it should be possible for the marginal means you want, right?
I do not know the margins function you use (what package is it from?). But, if you want to get the marginal means and pool them yourself, this is the approach:
# transform your mids into a long-format data frame
imputed_l <- mice::complete(imputeddata, action="long")
nimp <- imputed_l$m #number of imputations for convenience
# create vectors to contain the marginal effects and their SEs from all seven imputations
mm_all <- vector("numeric", nimp)
mmse_all <- mm_all
# get marginal means and SEs for all imputations
for (i in 1:nimp) {
mm_all[i] <- Expression_producing_marginal_mean(..., data = subset(imputed_l, .imp=i) )
mmse_all[i] <- Expression_producing_SE(..., data = subset(imputed_l, .imp=i) )
}
# pool them (the U argument should be variances, so square the SEs)
mm_pool <- pool.scalar(Q=mm_all, U=mmse_all^2, n=nrow(imputed_l)/nimp)
mm_pool$qbar #marginal mean aggregated across imputations
sqrt(mm_pool$t) #SE of marginal mean (based on within- and between-imputations variance)
I would like to extract some results from a lmermod object
require(lme4)
(fm1 <- lmer(Yield ~ 1|Batch, Dyestuff))
This produces
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
In particular, I would like to extract the standard devations of the 2 random effects, ie 42.00 and 49.51. I guess there may be a built-in method to do this, but I couldn't find it quickly so I thought I should be able to find it by using str(fm1), which produces this:
Formal class 'lmerMod' [package "lme4"] with 13 slots
..# 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
..# Gp : int [1:2] 0 6
..# call : language lmer(formula = Yield ~ 1 | Batch, data = Dyestuff)
..# 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>
..# 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
..# cnms :List of 1
.. ..$ Batch: chr "(Intercept)"
..# lower : num 0
..# theta : num 0.848
..# beta : num 1527
..# u : num [1:6] -20.755 0.461 33.669 -27.212 66.877 ...
..# 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" ...
..# pp :Reference class 'merPredD' [package "lme4"] with 18 fields
.. ..$ Lambdat:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:6] 0 1 2 3 4 5
.. .. .. ..# p : int [1:7] 0 1 2 3 4 5 6
.. .. .. ..# Dim : int [1:2] 6 6
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : NULL
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:6] 0.848 0.848 0.848 0.848 0.848 ...
.. .. .. ..# factors : list()
.. ..$ LamtUt :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:30] 0 0 0 0 0 1 1 1 1 1 ...
.. .. .. ..# p : int [1:31] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. ..# Dim : int [1:2] 6 30
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : NULL
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:30] 0.848 0.848 0.848 0.848 0.848 ...
.. .. .. ..# 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
.. .. .. ..# i : int [1:30] 0 0 0 0 0 1 1 1 1 1 ...
.. .. .. ..# p : int [1:31] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. ..# Dim : int [1:2] 6 30
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : chr [1:6] "A" "B" "C" "D" ...
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:30] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. ..# 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
.. .. .. ..# i : int [1:30] 0 0 0 0 0 1 1 1 1 1 ...
.. .. .. ..# p : int [1:31] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. ..# Dim : int [1:2] 6 30
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : chr [1:6] "A" "B" "C" "D" ...
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:30] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. ..# 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
..# 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
...but this leaves me none the wiser.
lme4 supplies VarCorr for extracting variance and correlation components:
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
The call mF#X should return fixed effect design matrix (necessary for marginal and conditional R^2 in glmm).
However it does not work.
Is even such matrix listed in model structure?
I appreciate any suggestions.
str(mF)
Formal class 'glmerMod' [package "lme4"] with 13 slots
..# resp :Reference class 'glmResp' [package "lme4"] with 11 fields
.. ..$ Ptr :<externalptr>
.. ..$ mu : num [1:480] 0.168 0.356 0.168 0.356 0.284 ...
.. ..$ offset : num [1:480] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ sqrtXwt: num [1:480] 0.373 0.479 0.373 0.479 0.451 ...
.. ..$ sqrtrwt: num [1:480] 2.68 2.09 2.68 2.09 2.22 ...
.. ..$ weights: num [1:480] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ wtres : num [1:480] -0.449 -0.744 -0.449 1.344 -0.629 ...
.. ..$ y : num [1:480] 0 0 0 1 0 0 0 1 0 0 ...
.. ..$ eta : num [1:480] -1.603 -0.591 -1.603 -0.591 -0.927 ...
.. ..$ family :List of 11
.. .. ..$ family : chr "binomial"
.. .. ..$ link : chr "logit"
.. .. ..$ linkfun :function (mu)
.. .. ..$ linkinv :function (eta)
.. .. ..$ variance :function (mu)
.. .. ..$ dev.resids:function (y, mu, wt)
.. .. ..$ aic :function (y, n, mu, wt, dev)
.. .. ..$ mu.eta :function (eta)
.. .. ..$ validmu :function (mu)
.. .. ..$ valideta :function (eta)
.. .. ..$ simulate :function (object, nsim)
.. .. ..- attr(*, "class")= chr "family"
.. ..$ n : num [1:480] 1 1 1 1 1 1 1 1 1 1 ...
.. ..and 41 methods, of which 29 are possibly relevant:
.. .. aic, allInfo, allInfo#lmResp, copy#envRefClass, devResid, fam,
.. .. initialize, initialize#lmResp, initializePtr, Laplace, link, muEta, ptr,
.. .. ptr#lmResp, resDev, setOffset, setResp, setTheta, setWeights, sqrtWrkWt,
.. .. theta, updateMu, updateMu#lmResp, updateWts, variance, wrkResids,
.. .. wrkResp, wrss, wtWrkResp
..# Gp : int [1:3] 0 60 72
..# call : language lme4::glmer(formula = Colour ~ Treatment + Habitat + (1 | Population) + (1 | Container), data = Data, family = "binomial", control = structure(list( ...
..# frame :'data.frame': 480 obs. of 5 variables:
.. ..$ Colour : int [1:480] 0 0 0 1 0 0 0 1 0 0 ...
.. ..$ Treatment : Factor w/ 2 levels "Cont","Exp": 1 2 1 2 1 2 1 2 1 2 ...
.. ..$ Habitat : Factor w/ 2 levels "A","B": 1 1 1 1 2 2 2 2 1 1 ...
.. ..$ Population: int [1:480] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ Container : int [1:480] 2 2 2 2 2 2 2 2 4 4 ...
.. ..- attr(*, "terms")=Classes 'terms', 'formula' length 3 Colour ~ Treatment + Habitat + (1 + Population) + (1 + Container)
.. .. .. ..- attr(*, "variables")= language list(Colour, Treatment, Habitat, Population, Container)
.. .. .. ..- attr(*, "factors")= int [1:5, 1:4] 0 1 0 0 0 0 0 1 0 0 ...
.. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. ..$ : chr [1:5] "Colour" "Treatment" "Habitat" "Population" ...
.. .. .. .. .. ..$ : chr [1:4] "Treatment" "Habitat" "Population" "Container"
.. .. .. ..- attr(*, "term.labels")= chr [1:4] "Treatment" "Habitat" "Population" "Container"
.. .. .. ..- attr(*, "order")= int [1:4] 1 1 1 1
.. .. .. ..- attr(*, "intercept")= int 1
.. .. .. ..- attr(*, "response")= int 1
.. .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
.. .. .. ..- attr(*, "predvars")= language list(Colour, Treatment, Habitat, Population, Container)
.. .. .. ..- attr(*, "dataClasses")= Named chr [1:5] "numeric" "factor" "factor" "numeric" ...
.. .. .. .. ..- attr(*, "names")= chr [1:5] "Colour" "Treatment" "Habitat" "Population" ...
.. .. .. ..- attr(*, "predvars.fixed")= language list(Colour, Treatment, Habitat)
.. ..- attr(*, "formula")=Class 'formula' length 3 Colour ~ Treatment + Habitat + (1 | Population) + (1 | Container)
.. .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..# flist :List of 2
.. ..$ Container : Factor w/ 60 levels "2","4","6","8",..: 1 1 1 1 1 1 1 1 2 2 ...
.. ..$ Population: Factor w/ 12 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..- attr(*, "assign")= int [1:2] 1 2
..# cnms :List of 2
.. ..$ Container : chr "(Intercept)"
.. ..$ Population: chr "(Intercept)"
..# lower : num [1:2] 0 0
..# theta : num [1:2] 0.0761 1.0537
..# beta : num [1:3] -1.251 1.012 0.676
..# u : num [1:72] -0.05 0.0254 -0.05 0.1008 -0.05 ...
..# devcomp:List of 2
.. ..$ cmp : Named num [1:11] 27.3 8.5 438.1 10.6 448.7 ...
.. .. ..- attr(*, "names")= chr [1:11] "ldL2" "ldRX2" "wrss" "ussq" ...
.. ..$ dims: Named int [1:14] 480 480 3 477 2 72 1 1 0 2 ...
.. .. ..- attr(*, "names")= chr [1:14] "N" "n" "p" "nmp" ...
..# pp :Reference class 'merPredD' [package "lme4"] with 18 fields
.. ..$ Lambdat:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:72] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. ..# p : int [1:73] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. ..# Dim : int [1:2] 72 72
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : NULL
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:72] 0.0761 0.0761 0.0761 0.0761 0.0761 ...
.. .. .. ..# factors : list()
.. ..$ LamtUt :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:960] 0 60 0 60 0 60 0 60 0 60 ...
.. .. .. ..# p : int [1:481] 0 2 4 6 8 10 12 14 16 18 ...
.. .. .. ..# Dim : int [1:2] 72 480
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : NULL
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:960] 0.0284 0.3935 0.0365 0.5046 0.0284 ...
.. .. .. ..# factors : list()
.. ..$ Lind : int [1:72] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ Ptr :<externalptr>
.. ..$ RZX : num [1:72, 1:3] 0.124 0.125 0.124 0.125 0.124 ...
.. ..$ Ut :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:960] 0 60 0 60 0 60 0 60 0 60 ...
.. .. .. ..# p : int [1:481] 0 2 4 6 8 10 12 14 16 18 ...
.. .. .. ..# Dim : int [1:2] 72 480
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : chr [1:72] "2" "4" "6" "8" ...
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:960] 0.373 0.373 0.479 0.479 0.373 ...
.. .. .. ..# factors : list()
.. ..$ Utr : num [1:72] -0.094 -0.018 -0.094 0.058 -0.094 ...
.. ..$ V : num [1:480, 1:3] 0.373 0.479 0.373 0.479 0.451 ...
.. ..$ VtV : num [1:3, 1:3] 92.7 0 0 48.3 48.3 ...
.. ..$ Vtr : num [1:3] 15.738 0.879 3.455
.. ..$ X : num [1:480, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:480] "1" "2" "3" "4" ...
.. .. .. ..$ : chr [1:3] "(Intercept)" "TreatmentExp" "HabitatB"
.. .. ..- attr(*, "assign")= int [1:3] 0 1 2
.. .. ..- attr(*, "contrasts")=List of 2
.. .. .. ..$ Treatment: chr "contr.treatment"
.. .. .. ..$ Habitat : chr "contr.treatment"
.. ..$ Xwts : num [1:480] 0.373 0.479 0.373 0.479 0.451 ...
.. ..$ Zt :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
.. .. .. ..# i : int [1:960] 0 60 0 60 0 60 0 60 0 60 ...
.. .. .. ..# p : int [1:481] 0 2 4 6 8 10 12 14 16 18 ...
.. .. .. ..# Dim : int [1:2] 72 480
.. .. .. ..# Dimnames:List of 2
.. .. .. .. ..$ : chr [1:72] "2" "4" "6" "8" ...
.. .. .. .. ..$ : NULL
.. .. .. ..# x : num [1:960] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. ..# factors : list()
.. ..$ beta0 : num [1:3] 0 0 0
.. ..$ delb : num [1:3] 0 0 0
.. ..$ delu : num [1:72] -0.05 0.0254 -0.05 0.1008 -0.05 ...
.. ..$ theta : num [1:2] 0.0761 1.0537
.. ..$ u0 : num [1:72] 0 0 0 0 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
..# optinfo:List of 7
.. ..$ optimizer: chr "Nelder_Mead"
.. ..$ control :List of 3
.. .. ..$ xst : num [1:5] 0.02 0.02 0.0721 0.0421 0.0418
.. .. ..$ xt : num [1:5] 1.00e-05 1.00e-05 3.60e-05 2.11e-05 2.09e-05
.. .. ..$ verbose: int 0
.. ..$ derivs :List of 2
.. .. ..$ gradient: num [1:5] 4.64e-05 9.60e-05 -6.73e-05 -6.46e-05 -1.26e-04
.. .. ..$ Hessian : num [1:5, 1:5] 2.644 -0.247 0.162 -1.023 -0.625 ...
.. ..$ conv :List of 2
.. .. ..$ opt : num 0
.. .. ..$ lme4: list()
.. ..$ feval : num 232
.. ..$ warnings : list()
.. ..$ val : num [1:5] 0.0761 1.0537 -1.2511 1.0118 0.676
You can use the function model.matrix to obtain the fixed-effects design matrix:
model.matrix(fit)
where fit is the object returned by glmer.