**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

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

Created by Pretty R at inside-R.org

**leave a comment**for the author, please follow the link and comment on his blog:

**Matt's Stats n stuff » R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...