r - 卡方模拟错误 - 无法分配大小为 134217728 Tb 的内存块
问题描述
我正在对我的数据运行以下函数,并且不断收到与内存块大小有关的错误。我的数据不是那么大(800 行,3 列),并且该功能仅在我将其减少到 300 行时才有效。
SSAS <- function(x, conf.int = 0.95, B = 10000)
{
x <- as.matrix(x)
nr <- nrow(x)
nc <- ncol(x)
sr <- rowSums(x)
sc <- colSums(x)
n <- sum(x)
E <- outer(sr, sc, "*")/n
dimnames(E) <- dimnames(x)
tmp <- .Call(stats:::C_chisq_sim, sr, sc, B, E)
obs <- sum(sort((x - E)^2/E, decreasing = TRUE))/n
sim <- tmp/n
p0 <- (1 - conf.int)/2
return(c(obs, quantile(sim, p0), quantile(sim, 1 -p0)))
}
错误:
FUN(X[[i]], ...) 中的错误:无法分配大小为 134217728 Tb 的内存块
但是,当我使用提供的较大的试验数据(超过 1000 行)时,该功能可以正常工作。
cap <- read.table("http://pbil.univ-lyon1.fr/R/donnees/mfdcapreolus.txt",
h = T)
l1 <- splitmfd(cap)
w <- matrix(unlist(lapply(l1, SSAS)), ncol = 3, byrow = T)
(分裂)
splitmfd <- function(mfd) {
loca1 <- function(x) {
x <- t(x[, 1:2])
dimnames(x) <- list(c("mal", "fem"), as.character(1:ncol(x)))
x
}
l0 <- split(mfd, mfd$mon)
lapply(l0, loca1)
}
我的数据如下所示:(而不是样本中的第 1-12 个月,我将其分为 3 个时期 - Prenurse、Nurse 和 PostNurse)
> head(groups)
X n_male_mat n_fem_mat PERIOD
1 1 0 22 PRENURS
2 2 0 14 PRENURS
3 3 4 19 PRENURS
4 4 1 0 PRENURS
5 5 0 21 NURSE
6 6 0 11 NURSE
解决方案
推荐阅读
- vb.net - vb.net 选择特定行,从一行到另一行
- python - xlsxwriter 无法将超过 1,048,576 行写入多个表和工作表
- java - Spring Boot thymeleaf 无法访问属性
- java - 对于这种方法,Java 中 Python 的 urllib2 代码等价物是什么?
- reactjs - 使用 react-router-dom v4 在 redux 操作中重定向
- dart - Dart DNS 查找 TXT 记录
- javascript - Javascript“like”函数针对数组
- robotframework - \?{argument} 和 ?{argument} 在机器人框架中是什么意思?
- r - 使用同一组中满足条件的第一行设置列值
- chapel - 场地的适当教堂所有权