我是 R 包装新手mice。但我正在尝试从中估算 5 个数据集popmis,然后为每个数据集拟合一个模型,最后在它们之间拟合一个lmer()模型。with()pool()
我认为pool()中的函数mice()不适用于lmer()来自lme4包的调用,对吧?
如果是这种情况,有没有办法编写一个定制的函数,其作用类似于pool()我下面的案例?
library(mice)
library(lme4)
imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`
fit <- with(imp, lme4::lmer(popular ~ sex + (1|school))) # works fine.
pool(fit) # BUT this one fails, should I loop here?
Run Code Online (Sandbox Code Playgroud) 我正在尝试更新 tibble 中反向编码项目的代码,以使用across()dplyr 中的函数而不是mutate_at(). 我现在的代码如下所示:
reversed_items <- c("x1","x4","x12") \n\ndata <- data %>% \n mutate_at(vars(reversed_items), function(x)6-x )\nRun Code Online (Sandbox Code Playgroud)\n这有效。但是,每当我尝试更新代码以包含该across()函数时,我都会收到此错误:
Error: Problem with `mutate()` input `..2`.\nx Input `..2` must be a vector, not a `formula` object.\n\xe2\x84\xb9 Input `..2` is `~recode(6 - .x)`.\nRun Code Online (Sandbox Code Playgroud)\n我读过: https: //www.tidyverse.org/blog/2020/04/dplyr-1-0-0-colwise/但无法让它工作。
\n看起来就像按行旋转一样pivot_longer()。stack()相比之下,gather按列拆分数据。\n我如何指定pivot_longer获得与 相同的结果gather()。\n我不需要额外的变量和排序,这正是关于pivot_longer参数的。
> all.equal(airquality %>% gather(), airquality %>% pivot_longer(everything(), names_to = "key", values_to = "value"))\n[1] "Attributes: < Component \xe2\x80\x9cclass\xe2\x80\x9d: Lengths (1, 3) differ (string compare on first 1) >"\n[2] "Attributes: < Component \xe2\x80\x9cclass\xe2\x80\x9d: 1 string mismatch >" \n[3] "Component \xe2\x80\x9ckey\xe2\x80\x9d: 764 string mismatches" \n[4] "Component \xe2\x80\x9cvalue\xe2\x80\x9d: 'is.NA' value mismatch: 44 in current 44 in target" \nRun Code Online (Sandbox Code Playgroud)\n