Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 查找断点前后的坡度_R_Decomposition - Fatal编程技术网

R 查找断点前后的坡度

R 查找断点前后的坡度,r,decomposition,R,Decomposition,我目前正在使用R中的bfast包来分解时间序列。我很好奇是否有可能在断点前后提取趋势段的斜率(直到一个端点或另一个断点) 以下示例摘自参考手册 生成这个的代码就在这里 require(bfast) require(strucchange) require(sandwich) require(forecast) require(raster) require(sp) fit <- bfast(harvest, season="harmonic", max.iter=2) plot(fit,

我目前正在使用R中的bfast包来分解时间序列。我很好奇是否有可能在断点前后提取趋势段的斜率(直到一个端点或另一个断点)

以下示例摘自参考手册

生成这个的代码就在这里

require(bfast)
require(strucchange)
require(sandwich)
require(forecast)
require(raster)
require(sp)
fit <- bfast(harvest, season="harmonic", max.iter=2)
plot(fit, type="trend")
require(bfast)
要求(结构变更)
需要(三明治)
需求(预测)
需要(光栅)
需要(sp)
适合
将为您提供“每个确定趋势段的斜率和重要性值”


有趣的是,当您指定:type=“trend”

从绘图中提取坡度值以便可以将其存储为对象以供以后使用时,它确实起作用

(plot(fit, ANOVA=TRUE)$slope)
如果在plot函数中使用str(),则非常有趣

> str(plot(fit, ANOVA=TRUE))
'data.frame':   5 obs. of  2 variables:
 $ slope: num  0.00109 0.01314 -0.20077 0.14659 0.11524
 $ prob : num  9.07e-01 2.41e-05 1.01e-13 3.08e-13 1.06e-13
> (plot(fit, ANOVA=TRUE)$slope)
[1]  0.001088344  0.013139678 -0.200767197  0.146594801  0.115236688
> 

这个问题已经很老了,但我找到了一种更快的方法,不用调用plot()或str()函数以及它们所涉及的计算时间

niter <- length(fit$output)
slopes<-coef(fit$output[[niter]]$bp.Vt)[,2]

niter感谢您的努力。将ANOVA设置为TRUE将给出绘图上的坡度,但我实际上想提取坡度值,以便将它们存储为对象。不过非常感谢,我是通过使用它找到它的。
niter <- length(fit$output)
slopes<-coef(fit$output[[niter]]$bp.Vt)[,2]