R包`bfast`错误:缺少需要TRUE / FALSE的值

时间:2023-01-12 22:29:42

I am using the R package bfast to detect any change point in a time series, and come across the following error. Is there any suggestion? Thanks a lot.

我使用R包bfast来检测时间序列中的任何变化点,并遇到以下错误。有什么建议吗?非常感谢。

library(bfast)
Mydata = Nile
bf1 <- bfast01(data = Mydata)

Error in if (is.nan(p0) || p0 < a2 || p0 > (1 - a2)) { : missing value where TRUE/FALSE needed

if(is.nan(p0)|| p0 (1 - a2)){:缺失值需要TRUE / FALSE时出错

1 个解决方案

#1


2  

It seems that bfast01 tries to guess the model from the other function arguments. I'm not too familiar with bfast but this seems to lead to the error on the Nile data.

似乎bfast01试图从其他函数参数猜测模型。我对bfast不太熟悉,但这似乎导致了尼罗河数据的错误。

If we explicitly specify the model,

如果我们明确指定模型,

fit <- bfast01(Nile, formula = response ~ trend);

there won't be an error, and bfast01 picks up a change point at index 28.

没有错误,bfast01会在索引28处获取一个更改点。

fit$breakpoints;
#[1] 28

This result is consistent with results from a similar change point analysis using changepoint:

此结果与使用变更点的类似变更点分析的结果一致:

changepoint::cpt.mean(Nile, class = FALSE);
#    cpt conf.value
#     28          1

Note that for the bfast change point analysis, a model involving only a trend component seems sufficient, as the seasonal/autoregressive effects occur on a smaller scale. You'll need to check the validity of the model based on your real data.

请注意,对于bfast变换点分析,仅涉及趋势分量的模型似乎就足够了,因为季节性/自回归效应发生在较小的范围内。您需要根据实际数据检查模型的有效性。

#1


2  

It seems that bfast01 tries to guess the model from the other function arguments. I'm not too familiar with bfast but this seems to lead to the error on the Nile data.

似乎bfast01试图从其他函数参数猜测模型。我对bfast不太熟悉,但这似乎导致了尼罗河数据的错误。

If we explicitly specify the model,

如果我们明确指定模型,

fit <- bfast01(Nile, formula = response ~ trend);

there won't be an error, and bfast01 picks up a change point at index 28.

没有错误,bfast01会在索引28处获取一个更改点。

fit$breakpoints;
#[1] 28

This result is consistent with results from a similar change point analysis using changepoint:

此结果与使用变更点的类似变更点分析的结果一致:

changepoint::cpt.mean(Nile, class = FALSE);
#    cpt conf.value
#     28          1

Note that for the bfast change point analysis, a model involving only a trend component seems sufficient, as the seasonal/autoregressive effects occur on a smaller scale. You'll need to check the validity of the model based on your real data.

请注意,对于bfast变换点分析,仅涉及趋势分量的模型似乎就足够了,因为季节性/自回归效应发生在较小的范围内。您需要根据实际数据检查模型的有效性。