简体   繁体   English

R:采样:校准函数:svd(X)中的错误:“ x”中的值无穷或缺失

[英]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.

相关问题 R - svd()函数 - &#39;x&#39;中的无限或缺失值 - R - svd() function - infinite or missing values in 'x' R 中的 PCA:svd(x,nu=0,nv=k)中的错误:“x”中的值无限或缺失 - PCA in R: Error in svd(x, nu=0, nv=k) : Infinite or missing values in 'x' R MASS软件包中的lm.ridge()说“ svd(X)中的错误:&#39;x&#39;中的值无穷或缺失” - lm.ridge() in R MASS package saying “Error in svd(X) : infinite or missing values in 'x'” 计算R错误中的SVD:缺失值或无限值 - Calculate SVD in R error: missing or infinite values svd(x, nu = 0, nv = k) 中的错误:“x”中的值无限或缺失。 矩阵中没有 NA 或 Inf 值 - Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'. There are no NA or Inf values in matrix svd(x,nu = 0)中的错误:&#39;x&#39;中的值无限或缺失(检查是否存在负值) - Error in svd(x, nu = 0) : infinite or missing values in 'x' (checked no negative values exist) svd(X)中的错误:&#39;x&#39;中的值无穷或缺失。 在GAS中使用BacktestVaR时 - Error in svd(X) : infinite or missing values in 'x' . when using BacktestVaR in GAS R-&#39;x&#39;中的无穷或缺失值 - R - Infinite or missing values in 'x' R- prcomp() 的“x”中的无限或缺失值 - R- infinite or missing values in 'x' for prcomp() 特征(x)中的错误:“x”中的无限值或缺失值 &gt; 在 robumeta 中 - Error in eigen(x) : infinite or missing values in 'x' > in robumeta
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM