小编pol*_*kas的帖子

使用库 mouse() 中的估算数据集来拟合 R 中的多级模型

我是 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)

r lme4 missing-data r-mice imputation

8
推荐指数
1
解决办法
2873
查看次数

从 mutate_at() 更改为 mutate(across()) 函数问题

我正在尝试更新 tibble 中反向编码项目的代码,以使用across()dplyr 中的函数而不是mutate_at(). 我现在的代码如下所示:

\n
reversed_items <- c("x1","x4","x12") \n\ndata <- data %>% \n  mutate_at(vars(reversed_items), function(x)6-x )\n
Run Code Online (Sandbox Code Playgroud)\n

这有效。但是,每当我尝试更新代码以包含该across()函数时,我都会收到此错误:

\n
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)`.\n
Run Code Online (Sandbox Code Playgroud)\n

我读过: https: //www.tidyverse.org/blog/2020/04/dplyr-1-0-0-colwise/但无法让它工作。

\n

r dplyr

2
推荐指数
1
解决办法
1474
查看次数

一切都聚集()与pivot_longer()

看起来就像按行旋转一样pivot_longer()stack()相比之下,gather按列拆分数据。\n我如何指定pivot_longer获得与 相同的结果gather()。\n我不需要额外的变量和排序,这正是关于pivot_longer参数的。

\n
> 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"    \n
Run Code Online (Sandbox Code Playgroud)\n

r tidyr

2
推荐指数
1
解决办法
2225
查看次数

标签 统计

r ×3

dplyr ×1

imputation ×1

lme4 ×1

missing-data ×1

r-mice ×1

tidyr ×1