LME summary data – results table

May 21, 2012

(This article was first published on Matt's Stats n stuff » R, and kindly contributed to R-bloggers)

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


# lme summary


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

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)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)