r将表中的回归模型输出到word [英] regression models in r output table to word

查看:152
本文介绍了r将表中的回归模型输出到word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用sjplot创建一个组合表.这将创建一个HTML表.我想制作一张可以导出为word的表格.

I have been using sjplot to create a combined table. This creates a HTML table. I would like to make a table that can be exported to word.

我已经查看了这篇讨论复制和粘贴到单词中的帖子,但这改变了列和行的格式.将多个回归表输出为多个R

I have reviewed this post which discusses copy and pasting into word, but this alters the formatting of the columns and lines. Output several regression tables into multiple pages of a Word document in R

n1 <- glm(N  ~ Age_2 , data = n_data, family = "binomial")
g1 <- glm(G  ~ Age_2 , data = g1_data, family = "binomial")
ga1 <- glm(G_1  ~ Age_2 , data = ga1_data, family = "binomial")
l1 <- glm(L_1  ~ Age_2 , data = l1_data, family = "binomial")
c1 <- glm(C_1  ~ Age_2 , data = c1_data, family = "binomial")
m1 <- glm(m  ~ Age_2 , data = m1_data, family = "binomial")

tab_model (n1,g1,ga1,l1,c1,m1)

除了每组观察的总数之外,还可以在行中添加具有结果的编号(即N的数量)吗?

Also is it possible to add a line with the number that had the outcome (ie. number of N), in addition to the total number of observations per group?

有什么建议吗?愿意尝试其他软件包.

Any suggestions? Willing to try other packages.

推荐答案

由于 sjPlot 输出为html,因此很难直接将其添加到Word文档中.这是一个示例,说明如何使用 knitr rmarkdown jtools huxtable 代码>.我正在将RStudio与rmarkdown文档一起使用,并将其编织到Word文档中.

Since sjPlot outputs to html, it's very hard to get it into a Word document directly. Here's an example of how to do something similar to what you want to do using knitr, rmarkdown, jtools, and huxtable. I'm using RStudio with an rmarkdown document, which I knit to a Word document.

---
title: "jtools to Output Logistic Regression Models"
author: "sar"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: word_document
---

```{r setup, include=FALSE}
library(knitr)
library(jtools)
library(huxtable)

knitr::opts_chunk$set(echo=FALSE, warning = FALSE)

```

# Introduction

This is a test document to demonstrate how knitr and rmarkdown can be used to put output from jtools
into a Word Document

```{r OutputTable}
set.seed(1234)
logistic_s <- data.frame(N=rbinom(200,1,0.5),
                         G=rbinom(200,1,0.5),
                         G_1=rbinom(200,1,0.5),
                         L_1=rbinom(200,1,0.5),
                         C_1=rbinom(200,1,0.5),
                         m=rbinom(200,1,0.5),
                         Age_2=round(rnorm(200,40,6)))

n1 <- glm(N  ~ Age_2 , data = logistic_s, family = "binomial")
g1 <- glm(G  ~ Age_2 , data = logistic_s, family = "binomial")
ga1 <- glm(G_1  ~ Age_2 , data = logistic_s, family = "binomial")
l1 <- glm(L_1  ~ Age_2 , data = logistic_s, family = "binomial")
c1 <- glm(C_1  ~ Age_2 , data = logistic_s, family = "binomial")
m1 <- glm(m  ~ Age_2 , data = logistic_s, family = "binomial")

model_summs <- export_summs(n1,g1,ga1,l1,c1,m1,
                            error_format = "({conf.low}, {conf.high})",
                            model.names = c("N","G","G_1","L_1","C_1","m"))

col_width(model_summs) = c(0.84,rep(0.95,6))

model_summs
```

这篇关于r将表中的回归模型输出到word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆