Search code examples
rms-wordlmerreporters

output lmer summary information to word using ReporteRs


I am using the package ReporteRs in R to output the results of statistical tests, and plots, to Word 2010.

I'm using lmer in the lme4 package to do some analysis, and I would like to output the results of summary(foo.lmer) to Word. I wish to capture everything in the lmerMod object and put it into Word. For example, here's a summary(foo.lmer) result that I have:

Linear mixed model fit by REML ['lmerMod']
Formula: value ~ Drug * Time + (Time + 1 | ID)
Data: DWeight.Female

REML criterion at convergence: 2296.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.3165 -0.6132  0.0343  0.6476  2.3088 

Random effects:
Groups   Name        Variance  Std.Dev. Corr
    ID   (Intercept) 573.98186 23.9579      
         Time          0.07738  0.2782  0.29
Residual              15.61168  3.9512      
Number of obs: 360, groups:  ID, 40

Fixed effects:
                 Estimate Std. Error t value
(Intercept)     270.44441    5.83694   46.33
Drug              1.24479    4.11450    0.30
Time              1.30481    0.07641   17.08
Drug:Time        -0.11055    0.05386   -2.05

Correlation of Fixed Effects:
        (Intr)   Drug  Time  
Drug    -0.758              
Time     0.211 -0.160       
Drug:Tm -0.160  0.211 -0.758

How can I store this information, with the fixed widths and hard returns, so that I can output this information using ReporteRs? I could copy and paste, but I am trying to automate the output, and I am often re-writing over the output Word document.

The fixed effects output is the most essential part, however it would be very useful to have all the output copied into Word.

update and resolution Thanks to the suggestion to use capture.output in the reply, this code worked for me, still using ReporteRs:

 D1male.Results <- capture.output(summary(D1Male.lmer))
 myBWdoc = docx()
 myBWdoc = addTitle( myBWdoc, "Drug 1 Results", level = 1 )
 myBWdoc = addTitle( myBWdoc, "Repeated Measures Models", level = 2 )
 myBWdoc = addParagraph( myBWdoc, D1male.Results)

If you want to put your response as an answer I can accept and upvote it.


Solution

  • Try to use the capture.output() function. Like this:

    Results <- capture.output(summary(your.lmer.model))
    

    It stores the summary information in the new variable. After that you can use it in e.g. ReporteRs paragraph functions.