lqs函数出错

时间:2014-05-04 19:05:50

标签: r

我使用包rlm中的函数MASS收到此错误:

x <- c(14642, 14769, 14847, 15128, 15239)
y <- c(27368, 27368, 27368, 30411, 30490)

> rlm(y~x, method = "MM")
Error in if (abs(s2/scale - 1) < 1e-05) break : 
  missing value where TRUE/FALSE needed
> traceback()
6: lqs.default(c(1, 1, 1, 1, 1, 14642, 14769, 14847, 15128, 15239
   ), c(27368, 27368, 27368, 30411, 30490), intercept = FALSE, method = "S", 
       k0 = 1.548)
5: lqs(c(1, 1, 1, 1, 1, 14642, 14769, 14847, 15128, 15239), c(27368, 
   27368, 27368, 30411, 30490), intercept = FALSE, method = "S", 
       k0 = 1.548)
4: do.call("lqs", c(list(x, y, intercept = FALSE, method = "S", 
       k0 = 1.548), lqs.control))
3: rlm.default(x, y, weights, method = method, wt.method = wt.method, 
       ...)
2: rlm.formula(y ~ x, method = "MM")
1: rlm(y ~ x, method = "MM")

方法==“M”不会发生这种情况,但我想知道发生了什么,因为上面对上面的数百万y~x对(几点)运行,而错误没有发生到现在。

此外,当我使用一些随机数代替y时,没有问题:

> rlm(rnorm(5)~x, method = "MM")
Call:
rlm(formula = rnorm(5) ~ x, method = "MM")
Converged in 5 iterations

Coefficients:
 (Intercept)            x 
23.801869752 -0.001621104 

Degrees of freedom: 5 total; 3 residual
Scale estimate: 0.657 

但是,仅更改x会产生不同的错误:

> rlm(y~I(1:5), method = "MM")
Error in lm.wfit(x, y, w, method = "qr") : 
  missing or negative weights not allowed

所以,我猜这是因为开头有三个相同的点,但我得到的第一个错误(in if (abs(s2/scale - 1) < 1e-05) break)对我没有任何意义。如果我的数据具有某些值并且没有丢失随机数,为什么变量会丢失?

0 个答案:

没有答案