首页 > 解决方案 > Hiding output of stepAIC in Rmarkdown

问题描述

How best will I hide the output of stepAIC from the output in the Rmarkdown. I tried echo = FALSE, message = FALSE but it would not work. Any leads kindly?

---
title: "Multivariate Regression"
author: "Moses Otieno"
date: "11/05/2021"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)

library(gtsummary) # Grammar of tables 

```

```{r regression}
mod1 <- glm(response ~ trt + age + grade , trial, family = binomial)

step.model <- MASS::stepAIC(mod1, direction = "both")

t1 <- tbl_regression(step.model, exponentiate = TRUE)
t1
```

标签: rr-markdown

解决方案


设置trace=0?从?MASS::stepAIC,

trace:如果为正,则在“stepAIC”运行期间打印信息。较大的值可能会提供有关拟合过程的更多信息。

这是最好的方法,但如果你不能这样做,那么capture.output()也可以:

junk <- capture.output(step.model <- MASS::stepAIC(mod1, direction = "both"))

如果您将stepAIC()调用放在单独的 chunk中,我认为指定results="hide"为 chunk 选项也可以。


推荐阅读