如何将mlogit结果导出到excel?

问题描述 投票:0回答:1

是否有任何软件包可以帮助我将多项式对数的结果导出到excel中,例如像表格一样?

r export export-to-excel
1个回答
0
投票

broom包可以合理地整理多项式输出。

library(broom)
library(nnet)

fit.gear <- multinom(gear ~ mpg + factor(am), data = mtcars)
summary(fit.gear)

Call:
multinom(formula = gear ~ mpg + factor(am), data = mtcars)

Coefficients:
  (Intercept)       mpg factor(am)1
4   -11.15154 0.5249369    11.90045
5   -18.39374 0.3662580    22.44211

Std. Errors:
  (Intercept)       mpg factor(am)1
4    5.317047 0.2680456   66.895845
5   67.931319 0.2924021    2.169944

Residual Deviance: 28.03075 
AIC: 40.03075

tidy(fit.gear)
# A tibble: 6 x 6
  y.level term        estimate std.error statistic  p.value
  <chr>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
1 4       (Intercept)  1.44e-5     5.32     -2.10  3.60e- 2
2 4       mpg          1.69e+0     0.268     1.96  5.02e- 2
3 4       factor(am)1  1.47e+5    66.9       0.178 8.59e- 1
4 5       (Intercept)  1.03e-8    67.9      -0.271 7.87e- 1
5 5       mpg          1.44e+0     0.292     1.25  2.10e- 1
6 5       factor(am)1  5.58e+9     2.17     10.3   4.54e-25

然后用openxlsx包将其发送到Excel中。

library(openxlsx)
write.xlsx(file="E:/.../fitgear.xlsx", tidy(fit.gear))

(注意 tidy 函数默认对系数进行指数化处理,尽管帮助页面错误的说默认为FALSE)。) 所以这些是相对风险比率,这就是为什么它们与 summary. 如果你想要置信区间,你就必须要求它们)。)

© www.soinside.com 2019 - 2024. All rights reserved.