如何将列添加到基于LM的FLEXTABL
假设我用这样的LM制作了一个模型,
library(flextable)
set.seed(123)
mydata <- data.frame(y=runif(100,1,100), x1=runif(100,1,100), x2=runif(100,1,100))
model <- lm(y~x1+x2, data=mydata)
as_flextable(model)
这使我可以通过估计,标准错误,T值和PR(&GT; | T |)发弹。假设我想在Flextable中添加一列,例如,如果我的y
已记录,并且我想要一个列显示exp(型号$ cefficients)-1
。
是否有一种直接的方法可以做到这一点,或者我必须从头开始重新创建桌子?
Let's say I make a model with lm such as
library(flextable)
set.seed(123)
mydata <- data.frame(y=runif(100,1,100), x1=runif(100,1,100), x2=runif(100,1,100))
model <- lm(y~x1+x2, data=mydata)
as_flextable(model)
This gives me a flextable with the Estimate, Standard Error, t value, and Pr(>|t|). Let's say I want to add a column to the flextable, for instance, if my y
is logged and I want a column that shows exp(model$coefficients)-1
.
Is there a straightforward way to do that or do I have to recreate the table from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在引用
flextable
'sas_flextable.lm
函数的源代码时,很明显,没有内置的方法可以执行此操作。我通过从源复制来制作“新”功能。new_cols
此功能的参数必须是命名函数列表,其中列表中每个函数的名称将成为新列名。列表中的功能将采用术语,估算,std.error,p.Value
作为输入,因为这些是data_t
tibble的名称。例如:
In referencing the source code of
flextable
'sas_flextable.lm
function it's clear there's no built in way to do it. I made a "new" function by copying from source.the
new_cols
parameter to this function needs to be a named list of functions where the name of each function in the list will become the new column name. The functions inside the list will taketerm, estimate, std.error, p.value
as input as those are the names of thedata_t
tibble.For example: