r - 如何使用 LMER 运行大型 data.frame?
问题描述
我正在使用一个包含大约 140 万个观测值的大型 data.frame。最初,当我运行我的模型时,我正在处理一个子样本(我的全样本的 10%)。这是因为使用原始数据运行一个模型可能需要大约两个小时。一旦我确定所有变量都很好地协调并且所有回归运行良好,我就使用完整样本运行我的模型。但是,回归没有收敛,我从两个不同的模型中收到以下两个错误:
Error in fun(xaa, ...) : Downdated VtV is not positive definite
Error in fun(xss, ...) : Downdated VtV is not positive definite
我不确定这是否相关,但我的笔记本电脑规格是:MacBook Pro(Retina,15 英寸,2015 年中)
处理器:2.5 GHz 四核 Intel Core i7
内存:16 GB 1600 MHz DDR3
显卡:英特尔 Iris Pro 1536 MB
数据是分层的,结构如下:个人(1 级)-> country_year(2 级)-> 国家(3 级)。
我使用该lmer
函数将这个模型拟合在一起,并在第 2 层和第 3 层包含一个随机斜率。您可以在下面找到可重现的代码。有人可以指导我如何解决这个问题吗?
df <- tibble(
y = rnorm(1400000),
x1 = rnorm(1400000),
x2 = rnorm(1400000),
country =sample.int(30,size=1400000,replace=TRUE)-1,
country_year =sample.int(10,size=1400000,replace=TRUE)-1
)
df$country = as.factor(df$country)
df$country_year = as.factor(df$country_year)
library(lme4)
model1 <- lmer(y~ x1 + x2 +
(x1 + x2 |country_year) +
(x1 + x2 |country), data=df)
解决方案
推荐阅读
- javascript - 如何在两个 slice reducer redux 工具包之间共享数据
- ruby-on-rails - 为什么在进行 Postgres 查询时,rails 不在“NaN”周围加上引号?
- python - 如何将我的 Python 脚本传递到 Slurm sbatch?
- fortran - 字符声明表
- c# - 在 Azure 认知搜索中处理单复数搜索词
- junit - 使用条件制作自定义类范围的 JUnit 注释
- directx - DirectX11可以将负值写入纹理格式化的浮点数吗?
- azure-devops - 链接到 KeyVault 的 Azure DevOps 变量组的“全选”选项
- excel - 遍历列,如果值为 1,则从上面复制并粘贴
- ios - apns-collapse-id (iOS) 如何与 Firebase 一起使用?