We often use logistic regression models in our analyses and we also often need to publish the results as tables in our papers. And, we always use MS Word since this is the standard office application in our department. So I thought about an easy way of how to transfer the results of fitted (generalized) linear models from R to Word. An appropriate way – for me – is to create HTML tables, simply open them in Word and copy’n’paste them into my document. This works much better than all things I have tried with SPSS tables (if someone has an easier solution, let me know!).

I wrote two small functions called sjt.lm resp. sjt.glm, which are included in my sjPlot-R-package. These functions require at least one or more fitted (g)lm-objects. It’s recommended to supply labels of predictor and dependent variables as further parameters. Here are some examples of different table styles…

First, compute two fitted models and create labels:

require("sjPlot")
y1 <- ifelse(swiss$Fertility<median(swiss$Fertility), 0, 1)
y2 <- ifelse(swiss$Agriculture<median(swiss$Agriculture), 0, 1)

fitOR1 <- glm(y1 ~ swiss$Education +
              swiss$Examination + 
              swiss$Infant.Mortality + 
              swiss$Catholic, 
              family=binomial(link="logit"))

fitOR2 <- glm(y2 ~ swiss$Education +
              swiss$Examination + 
              swiss$Infant.Mortality + 
              swiss$Catholic, 
              family=binomial(link="logit"))

lab <- c("Education", "Examination", "Infant Mortality", "Catholic")
labdep <- c("Fertility", "Agriculture")

Now, generate the tables:

sjt.glm(fitOR1, fitOR2,
        labelDependentVariables=labdep,
        labelPredictors=lab,
        file="or_table1.html")

Default table style

sjt.glm(fitOR1, fitOR2,
        labelDependentVariables=labdep,
        labelPredictors=lab,
        file="or_table2.html",
        pvaluesAsNumbers=T)

Table with p-values as numbers

sjt.glm(fitOR1, fitOR2,
        labelDependentVariables=labdep,
        labelPredictors=lab,
        file="or_table3.html",
        separateConfColumn=T)

Table with separated column for CI

sjt.glm(fitOR1, fitOR2,
        labelDependentVariables=labdep,
        labelPredictors=lab,
        file="or_table4.html",
        pvaluesAsNumbers=T,
        separateConfColumn=T)

Table with p-values as numbers and separated column for CI

These html-files can be opened with many word processors and the table can be copied’n’pasted into your own document. If you don’t specify the file parameter, the table will be shown in your default browser or in the viewer pane of your R-IDE (for instance, the RStudio viewer pane).