Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extracting index value from a list in R?

I want to extract the random effects from my lmer model, including the person this random effect belongs to. My goal is to create a tibble that has one column for the person and another column for the random effect.

Using coef(modelA)$bib I am able to extract the random effect to a list. Here I also see which person the random effect belongs to.

> coef(modelA)$bib
    (Intercept)
31   0.37031060
32   0.49877575
33   0.50586345
34   0.52036187
35   0.49813250

However, adding this to a tibble, this information is lost.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

> tibble(randEffectModA)
# A tibble: 65 x 1
   `(Intercept)`
           <dbl>
 1         0.370
 2         0.499
 3         0.506
 4         0.520
 5         0.498

Is there a simple way to solve this problem?

>Solution :

Those are rownames and tibbles do not support rownames.

You have few options –

  1. Keep the information in a dataframe instead of tibble so the rownames are maintained.
result <- data.frame(coef(modelA)$bib)
  1. Create the rownames as separate column if you want to use tibbles.
randEffectModA <- data.frame(coef(modelA)$bib)

result <- tibble::tibble(person_no = rownames(randEffectModA), 
                         intercept = unlist(randEffectModA))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading