- 积分
 - 1480
 
	- 贡献
 -  
 
	- 精华
 
	- 在线时间
 -  小时
 
	- 注册时间
 - 2015-4-9
 
	- 最后登录
 - 1970-1-1
 
 
 
 
 
 
 | 
	
 
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册 
 
 
 
x
 
 本帖最后由 zhaokg 于 2025-4-25 09:58 编辑  
 
借贵宝地分享自己开发的一个贝叶斯间序列分析算法BEAST。它主要用于把时间序列分解为趋势(trend)和季节周期波动(seasonality), 同时对这2项也进行突变点检测。如果时间序列没有季节项,也可以只进行趋势分析和突变点检测 (changepoint detection and trend analysis)。  这个算法和程序已经被一些文章和教材用过或者介绍过,其中包括一篇文献用它来分析降雨数据(White, J.H., Walsh, J.E. and Thoman Jr, R.L., 2021. Using Bayesian statistics to detect trends in Alaskan precipitation. International Journal of Climatology, 41(3), pp.2045-2059.)我觉的BEAST可能对分析某些气象数据或许有些用处。 这个算法在这个网址有更多介绍 https://github.com/zhaokg/Rbeast. 
 
相比传统的突变点分析方法(比如bfast或者是M-K),它的优势是不仅告诉那儿发生突变,并且给出每个时间点发出突变的概率;也可以告诉发生几个突变点的概率(比如有1个突变点的概率,有2个的概率,....)。 
 
 
这个算法可以在R, Matlab,或者 Python中调用。在R中,已经做成一个package,可以直接用install.packages("Rbeast")安装 
 - install.packages("Rbeast")
 
 - library(Rbeast)
 
 - data(Nile)                                       #  annual streamflow of the Nile River   
 
 - out = beast(Nile, season='none')      #  'none': trend-only data without seasonlaity   
 
 - print(out)                  
 
 - plot(out)
 
  复制代码 
 
 
 
在Matlab中,可以不用手动下载, 直接可以用下面前2行代码在线安装 (如果下面自动download 不work, 可以直接去https://github.com/zhaokg/Rbeast/tree/master/Matlab手动下载:
 - beastPath = 'c:\beast'                                                 % 本地安装目录
 
 - eval(webread('http://b.link/rbeast',weboptions('cert','')))  % 自动安装在beastPath指定目录
 
 - load('Nile.mat')                                                          % 尼罗河年径流量
 
 - out = beast(Nile, 'season', 'none','start', 1871)               % trend-only data without seasonality
 
 - printbeast(out)
 
 - plotbeast(out)
 
 - %下图为这个例子的结果
 
 - %第一个截屏是 突变点个数的概率,比如说有54%的概率存在1个突变点
 
 - %第二个截屏是 画出的主要结果
 
  复制代码 
 
 
 
 
 
 
 
Matlab中另外一个例子 
 - load('googletrend.mat')               % 美国自2004年每月在Google搜索'beach'关键词的频度:这个时间序列有一个周期项
 
 - o = beast( beach )                       % Apply BEAST to the 'beach time series: beach is a data vector only; the time
 
 -                                                  % info can be supplied using the start and deltat
 
 -                                                  % keywords, as in the next commented line
 
 - %o = beast( beach,'start',[2004,1],'deltat',1/12 )
 
 - printbeast(o)          % print the changepoints detected
 
 - plotbeast(o)            % plot the results: o.season.Y and o.trend.Y are the seasonal and trend compoents
 
  复制代码 
 
在Python中,已经做成一个package放在https://pypi.org/project/Rbeast/, 可以直接用pip install Rbeast安装: 
 
 - import Rbeast as rb
 
 - nile, year = rb.load_example('nile')
 
 - o            = rb.beast( nile, start=1871, season='none')
 
 - rb.plot(o, title='Annual streamflow of the Nile River')
 
 - rb.print(o)
 
 
  复制代码 
 
 |   
 
 
 
 |