matlab lags,Choose ARMA Lags Using BIC

Simulate ARMA time series

Simulate an ARMA(2,1) time series with 100 observations.

Mdl0 = arima('Constant',0.2,'AR',{0.75,-0.4},...

'MA',0.7,'Variance',0.1);

rng('default')

Y = simulate(Mdl0,100);

figure

plot(Y)

xlim([0,100])

title('Simulated ARMA(2,1) Series')

4a179b61cd7fc2675927445cce9c8243.png

Plot Sample ACF and PACF

Plot the sample autocorrelation function (ACF) and partial autocorrelation function (PACF) for the simulated data.

figure

subplot(2,1,1)

autocorr(Y)

subplot(2,1,2)

parcorr(Y)

ccd2ad8752f6ca8b3c338a053d0aefc8.png

Both the sample ACF and PACF decay relatively slowly. This is consistent with an ARMA model. The ARMA lags cannot be selected solely by looking at the ACF and PACF, but it seems no more than four AR or MA terms are needed.

Fit ARMA(p,q) Models to Data

To identify the best lags, fit several models with different lag choices. Here, fit all combinations of p = 1,...,4 and q = 1,...,4 (a total of 16 models). Store the loglikelihood objective function and number of coefficients for each fitted model.

LOGL = zeros(4,4); % Initialize

PQ = zeros(4,4);

for p = 1:4

for q = 1:4

Mdl = arima(p,0,q);

[EstMdl,~,logL] = estimate(Mdl,Y,'Display','off');

LOGL(p,q) = logL;

PQ(p,q) = p + q;

end

end

Calculate BIC

Calculate the BIC for each fitted model. The number of parameters in a model is p + q + 1 (for the AR and MA coefficients, and constant term). The number of observations in the data set is 100.

LOGL = reshape(LOGL,16,1);

PQ = reshape(PQ,16,1);

[~,bic] = aicbic(LOGL,PQ+1,100);

reshape(bic,4,4)

ans = 4×4

108.6241 105.9489 109.4164 113.8443

99.1639 101.5886 105.5203 109.4348

102.9094 106.0305 107.6489 99.6794

107.4045 100.7072 98.3511 102.0209

In the output BIC matrix, the rows correspond to the AR degree (p) and the columns correspond to the MA degree (q). The smallest value is best.

The smallest BIC value is 99.1639 in the (2,1) position. This corresponds to an ARMA(2,1) model, matching the model that generated the data.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MATLAB中,进行自回归移动平均模型(Autoregressive Moving Average, ARMA)的检验通常用于判断时间序列数据是否符合白噪声假设,即随机过程的均值、方差以及自相关函数都是常数,不存在长期依赖。以下是一般的步骤: 1. **数据准备**:首先,你需要有一个未经处理的时间序列数据集。如果数据已经存在,比如`data`。 2. **平稳性检查**:ARMA模型通常需要数据是平稳的。可以使用`adfTest`函数来检查单位根,如ADF(Augmented Dickey-Fuller test)统计量。 ```matlab [pValue, ~,~, ~] = adfTest(data); if pValue > significanceLevel, % significanceLevel一般设为0.05 disp('数据可能存在单位根,需要进行差分处理') end ``` 3. **ARMA模型识别**:通过`arima`函数进行初步估计,可以选择合适的p (自回归阶) 和q (移动平均阶)。 ```matlab [mod, opt] = arima(x, 'ARLags', 1:5, 'MALags', 1:5); % 选择适当的阶数 ``` 4. **残差分析**:对拟合后的模型计算残差,然后使用`acf`和`pacf`函数查看自相关和偏自相关图,确认残差满足白噪声的特性。 ```matlab residuals = resid(mod); [~, lags] = acf(residuals, 'lags', 40); plot(lags, abs(lags), 'b-', 'LineWidth', 2); xlabel('Lag'); ylabel('ACF Magnitude'); ``` 5. **Q-statistic检验**:使用`armaOrderSelect`函数或者` armaSpecgram`进行模型诊断,看是否有显著的AR或MA部分。 6. **白色噪声测试**:如`Box-Pierce`和Breusch-Godfrey检验等,验证残差序列是独立同分布的,即无自相关。 ```matlab [h, pValue,~,~] = boxtest(residuals); if pValue > significanceLevel, disp('残差满足白噪声假设'); end ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值