[英]R: Sampling: Calib function: Error in svd(X) : infinite or missing values in 'x'
I feel like this is a common issue, yet I can't seem to find an answer. 我觉得这是一个普遍的问题,但我似乎找不到答案。 I am working with a sampled dataset and attempting to calculate calibration weights against known population totals using the Sampling package .
我正在使用采样数据集,并尝试使用Sampling包针对已知总体总数计算校准权重。 The calib function acts on a sample column or matrix (Xs), initial weights (d), and a population total (total) to calculate g-weights.
calib函数作用于样本列或矩阵(Xs),初始权重(d)和总体总数(总计),以计算g权重。 Below is the first column in my dataset which yields the error:
以下是我的数据集中的第一列,它会产生错误:
Error in svd(X) : infinite or missing values in 'x'
Other columns also yield this error, but for simplicity sake, I've only included the first. 其他列也产生此错误,但为简单起见,我仅包括第一列。 Reproducible example below:
以下是可重现的示例:
library("sampling")
# Sample
Xs = c(3793, 4505, 2272, 1126, 1839, 2060, 9077, 3174, 4013, 1673, 1299, 3981, 1770, 1059, 899, 2475, 1731, 2135, 843, 1880, 7887, 6402, 3022, 3345, 3954, 4489, 6222, 694)
Xs <- as.matrix(sapply(Xs, as.numeric))
# Initial Weights
d = rep(1, nrow(Xs))
# Population total
total = c(1616772)
g = calib(Xs, d, total, method="logit")
I then searched for infinite values and NaN, based on similar questions in SO, using the following code and found nothing. 然后,我根据以下SO中的类似问题,使用以下代码搜索了无穷大的数值和NaN,却一无所获。
length(Xs)
sum(is.finite(Xs))
sum(is.nan(Xs))
length(d)
sum(is.finite(d))
sum(is.nan(d))
length(total)
sum(is.finite(total))
sum(is.nan(total))
[1] 28
[1] 28
[1] 0
[1] 28
[1] 28
[1] 0
[1] 1
[1] 1
[1] 0
My apologies if this is elementary. 如果这很简单,我深表歉意。 Thank you.
谢谢。
I am not familiar with the package but I looked and the error comes from the function base::svd(). 我对该程序包不熟悉,但是我看了一下,错误来自于base :: svd()函数。 I suspected it might be an initiation problem so I tried the following and it worked:
我怀疑这可能是启动问题,因此我尝试了以下操作并成功运行:
library(sampling)
Xs = c(3793, 4505, 2272, 1126, 1839, 2060, 9077, 3174, 4013, 1673, 1299, 3981, 1770, 1059, 899, 2475, 1731, 2135, 843, 1880, 7887, 6402, 3022, 3345, 3954, 4489, 6222, 694)
Xs <- as.matrix(sapply(Xs, as.numeric))
# Initial Weights
d = rep(1, nrow(Xs))
# Population total
total = c(1616772)
g = calib(Xs, d, total, method="logit")
Be careful though! 不过要小心! trying different initations for d gives me very different result.
为d尝试不同的启发会给我非常不同的结果。 ie compare to using:
d = rep(2, nrow(Xs))
. 即与使用
d = rep(2, nrow(Xs))
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.