这是一个从如何进行调查加权问题开始的传奇。现在我似乎做对了,但我遇到了一些障碍(有关导入过程和strata
变量来源的详细信息,请参阅上一篇文章):
> require(foreign)
> ipums <- read.dta('/path/to/data.dta')
> require(survey)
> ipums.design <- svydesign(id=~serial, strata=~strata, data=ipums, weights=perwt)
Error in if (nbins > .Machine$integer.max) stop("attempt to make a table with >= 2^31 elements") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In pd * (as.integer(cat) - 1L) : NAs produced by integer overflow
2: In pd * nl : NAs produced by integer overflow
> traceback()
9: tabulate(bin, pd)
8: as.vector(data)
7: array(tabulate(bin, pd), dims, dimnames = dn)
6: table(ids[, 1], strata[, 1])
5: inherits(x, "data.frame")
4: is.data.frame(x)
3: rowSums(table(ids[, 1], strata[, 1]) > 0)
2: svydesign.default(id = ~serial, weights = ~perwt, strata = ~strata,
data = ipums)
1: svydesign(id = ~serial, weights = ~perwt, strata = ~strata, data = ipums)
这个错误似乎来自tabulate
函数,我希望它足够简单以规避,首先通过改变.Machine$integer.max
> .Machine$integer.max <- 2^40
当这不起作用时,整个源代码tabulate
:
> tabulate <- function(bin, nbins = max(1L, bin, na.rm=TRUE))
{
if(!is.numeric(bin) && !is.factor(bin))
stop("'bin' must be numeric or a factor")
#if (nbins > .Machine$integer.max)
if (nbins > 2^40) #replacement line
stop("attempt to make a table with >= 2^31 elements")
.C("R_tabulate",
as.integer(bin),
as.integer(length(bin)),
as.integer(nbins),
ans = integer(nbins),
NAOK = TRUE,
PACKAGE="base")$ans
}
两者都没有规避问题。显然这是创建这个包的原因之一ff
,但让我担心的是这个问题在多大程度上是我无法避免的R
。这篇文章似乎表明,即使我要使用可以避免此问题的包,我一次也只能访问 2^31 个元素。我希望使用sql
(sqlite
或postgresql
) 来解决内存问题,但恐怕我会花一些时间让它工作,只是遇到相同的基本限制。
尝试切换回Stata
也不能解决问题。再次查看上一篇文章了解我的使用方式svyset
,但我想运行的计算导致Stata
挂起:
svy: mean age, over(strata)
我不知道是否向它投入更多内存会解决问题。我R
在有 16 个演出的桌面上运行,我Stata
通过 Windows 服务器使用,目前将内存分配设置为 2000MB,但理论上我可以尝试增加它。
总而言之:
- 这是硬限制
R
吗? sql
能解决我的R
问题吗?- 如果我把它分成许多单独的文件,会修复它(很多工作......)?
- 会投入大量内存
Stata
吗? - 我是否以某种方式认真地吠叫错误的树?