I'm fairly new to R and I'm trying to simulate some data, fit it to a model, and do a runs test of the residuals. However, I get a strange type error when performing the runs test. Here is my code:
我是R的新手,我正在尝试模拟一些数据,使其适合模型,并对残差进行运行测试。但是,执行运行测试时出现奇怪的类型错误。这是我的代码:
library(TSA)
d = arima.sim(list(ma=c(0.5)), n=5000)
model = arima(d, order=c(0, 0, 1), include.mean=FALSE)
runs(model$residuals)
The error is:
错误是:
Error in if (pvalue > 0.5) pvalue <- 1 - pvalue :
missing value where TRUE/FALSE needed
What does this error mean?
这个错误是什么意思?
1 个解决方案
#1
1
I'm not familiar with this package but I can tell that either your data is a particular case or this package (runs function at least) needs a re-review.
我不熟悉这个软件包,但我可以告诉您,您的数据是特定情况,或者此软件包(至少运行功能)需要重新审核。
pdf <- pdf/sum(pdf) # pdf contains Inf, so becomes NaN
mu <- 1 + 2 * n1 * n2/(n1 + n2)
if (r1 <= mu) # This is verified
pvalue <- sum(pdf[(1:l2) <= r1]) # pvalue is not calculated, pdf is all NaN
if (r1 > mu) # there should be some R versions without else...
pvalue <- sum(pdf[(1:l2) >= r1])
if (pvalue > 0.5) # This gives you the error! pvalue is all NaN
pvalue <- 1 - pvalue
few lines above pdf gets the Inf values:
pdf以上几行获得Inf值:
for (i in seq(4, l2, 2)) { # when i is 166 pdf gets its first Inf value
r <- (i - 2)/2
f[r + 1] <- (n1 - r) * (n2 - r)/r/r * f[r]
pdf[i] <- f[r + 1]
}
I can't go any further cause I don't know neither how such data is supposed to look like nor the results you should get from such function. Try to give a look yourself into the function, I had enough :-) the missing else in the code above is not the only odd thing into it. Hope that helped
我不能再进一步了,因为我既不知道这些数据应该是什么样子,也不知道你应该从这样的函数得到的结果。试着看看你自己的功能,我已经足够了:-)上面代码中缺少的其他东西并不是唯一奇怪的东西。希望有所帮助
#1
1
I'm not familiar with this package but I can tell that either your data is a particular case or this package (runs function at least) needs a re-review.
我不熟悉这个软件包,但我可以告诉您,您的数据是特定情况,或者此软件包(至少运行功能)需要重新审核。
pdf <- pdf/sum(pdf) # pdf contains Inf, so becomes NaN
mu <- 1 + 2 * n1 * n2/(n1 + n2)
if (r1 <= mu) # This is verified
pvalue <- sum(pdf[(1:l2) <= r1]) # pvalue is not calculated, pdf is all NaN
if (r1 > mu) # there should be some R versions without else...
pvalue <- sum(pdf[(1:l2) >= r1])
if (pvalue > 0.5) # This gives you the error! pvalue is all NaN
pvalue <- 1 - pvalue
few lines above pdf gets the Inf values:
pdf以上几行获得Inf值:
for (i in seq(4, l2, 2)) { # when i is 166 pdf gets its first Inf value
r <- (i - 2)/2
f[r + 1] <- (n1 - r) * (n2 - r)/r/r * f[r]
pdf[i] <- f[r + 1]
}
I can't go any further cause I don't know neither how such data is supposed to look like nor the results you should get from such function. Try to give a look yourself into the function, I had enough :-) the missing else in the code above is not the only odd thing into it. Hope that helped
我不能再进一步了,因为我既不知道这些数据应该是什么样子,也不知道你应该从这样的函数得到的结果。试着看看你自己的功能,我已经足够了:-)上面代码中缺少的其他东西并不是唯一奇怪的东西。希望有所帮助