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

Access results of intervals.lme as a dataframe + r + lme

I am using a linear mixed effects model to determine the relationship between 2 variables over time, model –

data(mtcars)

# linear mixed effects model
mlme <- lme(mpg ~ wt, random = ~ 1|cyl, data = mtcars)

I then access the confidence intervals using –

conf <- intervals(mlme, level = 0.95, which = 'fixed')
conf

Returning the results –

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

Approximate 95% confidence intervals

 Fixed effects:
               lower      est.    upper
(Intercept) 7.431921 18.416639 29.40136
DairyTotal  2.001397  6.716849 11.43230

I want to access the values of the lower and upper limits so I can use them as variables but can’t find a method to do so. If you want to access the coefficients for example you can use coef(summary(mlme)) and convert it to a dataframe.

I tried converting the result to a dataframe using data.frame(coef) but get the error:

> data.frame(conf)
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ‘"intervals.lme"’ to a data.frame

Can anyone recommend a method to access variables that are returned in this format?

>Solution :

Here is an example with the mtcars dataset how we could access the lower and upper ci as variables:

library(nlme)

data(mtcars)

# linear mixed effects model
mlme <- lme(mpg ~ wt, random = ~ 1|cyl, data = mtcars)

# Confidence intervals
conf <- intervals(mlme, level = 0.95, which = 'fixed')

# Lower and upper confidence intervals as variables
lower <- conf$fixed["(Intercept)", "lower"]
upper <- conf$fixed["(Intercept)", "upper"]

[1] 25.7204
[1] 37.32919
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