【发布时间】:2021-11-08 16:41:08
【问题描述】:
我刚刚发现了 gtsummary 包,我想哇,我想为我的线性回归获得这种类型的快速表,但我遇到了一些麻烦,无法让它为我工作。 我有一个包含生长和荧光数据的数据表。数据按实验条件荧光类型分组。我对此数据进行了线性回归,请参见下面的示例
#make a dummy data table
d <- data.frame(
condition = rep(c('B', 'U'), 20),
growth = rep(1:20, 2),
type=rep(c(F1,F2,F3,F4),5)
response= rnorm(20)
)
#run lm on grouped data by condition and fluorescence type
linear_models <- d%>%
group_by(type,condition)%>%
do(model = lm(growth ~fluo, data = .))
#make table with tbl_regression
tbl_regression(linear_models)
这里我收到一条错误消息,告诉我 tidy 函数未能整理模型
! `broom::tidy()` failed to tidy the model.
x Calling var(x) on a factor x is defunct.
Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)
! `tidy_parameters()` also failed.
! `broom::tidy()` failed to tidy the model.
x Calling var(x) on a factor x is defunct.
Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)
! `tidy_parameters()` also failed.
x There was an error calling `tidy_fun()`. Most likely, this is because the
function supplied in `tidy_fun=` was misspelled, does not exist, is not
compatible with your object, or was missing necessary arguments (e.g. `conf.level=` or `conf.int=`). See error message below.
Error: Error in eval(expr, envir = list(`?` = function(...) stop()), enclos = envir): You need to install 'parameters' to use 'tidy_parameters'.
In addition: There were 16 warnings (use warnings() to see them)
我尝试直接使用 broom::tidy 获得一张桌子,它可以工作,但它不是我想要获得的桌子。
linear_models <- d%>%
group_by(type,condition)%>%
do(broom::tidy(lm(growth ~fluo, .)))
谁能提示我在 tbl_regression 函数中遗漏了什么以及如何在我的模型上工作?
对不起,太长了!谢谢
【问题讨论】:
-
输入示例中没有
fluo列 -
对不起,我在创建虚拟数据时弄错了列名,fluo 应该是响应