如何解决扫帚更新后的问题?
我有这段代码可以一次运行多个线性模型,每个因子水平分开。首先,我使用 filter
和 group_by
对数据进行子集化,然后使用 do()
构建模型并使用 tidy()
dados <- read.table("Rafael_bovo_dados2.txt",h=TRUE)
dim(dados)#dimensões da tabela
head(dados); str(dados)
df_lm <- dados %>%
filter(Species == "Physalaemus_cuvieri") %>%
group_by(Mountain_Range) %>%
do(mod = lm(EWL_ug~as.factor(Altitude),data = .))
df_lm %>%
tidy(mod)
这最后一行用于返回一个表格,其中包含所有这些模型的汇总统计数据和其他结果,例如 this vignette 中的那些。但是,这现在返回一个错误,指出不推荐使用 tidy。
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x),na.rm = na.rm) :
is.atomic(x) is not TRUE
In addition: Warning messages:
1: Data frame tidiers are deprecated and will be removed in an upcoming release of broom.
2: `data_frame()` is deprecated as of tibble 1.1.0.
Please use `tibble()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
3: In mean.default(X[[i]],...) :
argument is not numeric or logical: returning NA
4: In mean.default(X[[i]],...) :
argument is not numeric or logical: returning NA
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x),na.rm = na.rm) :
NAs introduced by coercion
解决方法
经过一些挖掘,我能够调整代码:
df_lm <- dados %>%
filter(Species == "Physalaemus_cuvieri") %>%
nest_by(Mountain_Range) %>%
mutate(mod = list(lm(EWL_ug~as.factor(Altitude),data = data)))
df_lm %>%
summarise(broom::tidy(mod))
现在它返回了我的预期:
`summarise()` regrouping output by 'Mountain_Range' (override with `.groups` argument)
# A tibble: 4 x 6
# Groups: Mountain_Range [2]
Mountain_Range term estimate std.error statistic p.value
<chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 Serra_da_Mantiq… (Intercept) 2.93 0.188 15.6 7.68e- 9
2 Serra_da_Mantiq… as.factor(… -0.497 0.226 -2.19 5.07e- 2
3 Serra_do_Mar (Intercept) 2.70 0.149 18.1 5.33e-13
4 Serra_do_Mar as.factor(… -0.0669 0.201 -0.333 7.43e- 1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。