如何减少Markdown中的回归输出

发布于 2025-02-13 19:29:09 字数 106 浏览 3 评论 0原文

我想在Markdown中显示回归输出,但它包含许多字符变量,这些变量会导致许多自变量。有什么方法可以在摘要中显示前5个变量?结合选项(Max.print = 80)的摘要功能不提供我想要的解决方案。

I want to show a regression output in markdown but it contains a lot of character variables which result in a lot of independent variables. Is there any way to only show in the summary the first 5 variables? The summary function in combination with the options(max.print=80) does not provide the solution I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几味少女 2025-02-20 19:29:09

您可以使用tidy()函数broom package

library(broom)
library(magrittr)

lm(mpg ~ ., data = mtcars) %>% tidy() %>% head(n = 5)

#> # A tibble: 5 × 5
#>   term        estimate std.error statistic p.value
#>   <chr>          <dbl>     <dbl>     <dbl>   <dbl>
#> 1 (Intercept)  12.3      18.7        0.657   0.518
#> 2 cyl          -0.111     1.05      -0.107   0.916
#> 3 disp          0.0133    0.0179     0.747   0.463
#> 4 hp           -0.0215    0.0218    -0.987   0.335
#> 5 drat          0.787     1.64       0.481   0.635

在2022-07-08创建的 Reprex软件包(v2.0.1)

You can use tidy() function from broom package

library(broom)
library(magrittr)

lm(mpg ~ ., data = mtcars) %>% tidy() %>% head(n = 5)

#> # A tibble: 5 × 5
#>   term        estimate std.error statistic p.value
#>   <chr>          <dbl>     <dbl>     <dbl>   <dbl>
#> 1 (Intercept)  12.3      18.7        0.657   0.518
#> 2 cyl          -0.111     1.05      -0.107   0.916
#> 3 disp          0.0133    0.0179     0.747   0.463
#> 4 hp           -0.0215    0.0218    -0.987   0.335
#> 5 drat          0.787     1.64       0.481   0.635

Created on 2022-07-08 by the reprex package (v2.0.1)

相思故 2025-02-20 19:29:09

如果我正确理解您,例如,您可以从您想要的变量中征服系数(我使用mtcars dataset作为示例):

model = lm(mpg ~ ., data=mtcars)
smy = summary(model)
smy$coefficients[1:5,]
#>                Estimate  Std. Error    t value  Pr(>|t|)
#> (Intercept) 12.30337416 18.71788443  0.6573058 0.5181244
#> cyl         -0.11144048  1.04502336 -0.1066392 0.9160874
#> disp         0.01333524  0.01785750  0.7467585 0.4634887
#> hp          -0.02148212  0.02176858 -0.9868407 0.3349553
#> drat         0.78711097  1.63537307  0.4813036 0.6352779

在2022-07-07创建的 a href =“ https://reprex.tidyverse.org” rel =“ nofollow noreferrer”> reprex软件包 (v2.0.1)

If I understand you correctly, you could for example subset the coefficients from the variables you want like this (I use mtcars dataset as an example):

model = lm(mpg ~ ., data=mtcars)
smy = summary(model)
smy$coefficients[1:5,]
#>                Estimate  Std. Error    t value  Pr(>|t|)
#> (Intercept) 12.30337416 18.71788443  0.6573058 0.5181244
#> cyl         -0.11144048  1.04502336 -0.1066392 0.9160874
#> disp         0.01333524  0.01785750  0.7467585 0.4634887
#> hp          -0.02148212  0.02176858 -0.9868407 0.3349553
#> drat         0.78711097  1.63537307  0.4813036 0.6352779

Created on 2022-07-07 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文