LME summary data – results table

[This article was first published on Matt's Stats n stuff » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

UPDATE: Based on the comment from ‘linuxizer’, I’ve updated this to stay inline with the S3 classes, something I didn’t have my head around at the time, still don’t know it inside out.

Brief post.

One thing I do often in my analysis is use things like ‘summary(mod)$coefficients’ and variance derivatives of that to pull the results from models into table so I can write my results nicely to csv, which can then be circulated to colleagues. I take the time to do this, so that when I go back and subset the data someone, I can instantly generate the same, nice, tailored results table. As it is often the case that you will run analysis multiple times, perhaps subsetting on years, or ages or subjects etc etc.

With lme, I found it frustrating that I couldn’t easily access coefficients and CIs. So wrote a very simple function to do this, so I can then use this output to populate my results tables.

Code is available here http://pastebin.com/TctYeggd

Example:

# lme summary

library(nlme)
?lme

fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
summary(fm1)

coef.lme <- function(mod){
    res <- data.frame(
        "Beta.CI" = paste(round(summary(mod)$coefficients$fixed, 3), " (",round(summary(mod)$coefficients$fixed-1.96*sqrt(diag(mod$varFix)), 2), ",", round(summary(mod)$coefficients$fixed+1.96*sqrt(diag(mod$varFix)), 2),")", sep=""),
        "P.value" = round(2 * pt(-abs(summary(mod)$coefficients$fixed/sqrt(diag(mod$varFix))), summary(mod)$fixDF[[1]]), 3)
    )
    return(res)
}

coef(fm1) # since this is an S3 class it will know to use the '.lme' function

####### Results in

> coef(fm1)
                         Beta.CI P.value
(Intercept) 16.761 (15.24,18.28)       0
age              0.66 (0.52,0.8)       0


To leave a comment for the author, please follow the link and comment on their blog: Matt's Stats n stuff » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)