Effacer les filtres
Effacer les filtres

How to solve index? error

3 vues (au cours des 30 derniers jours)
형현
형현 le 1 Fév 2024
Commenté : 형현 le 2 Fév 2024
% 엑셀 파일 경로 및 시트 이름 설정
file_path = '종가 차분(한화).xlsx';
sheet_name = 'Sheet1';
% 엑셀 파일에서 데이터 가져오기
excel_data = readtable(file_path, 'Sheet', sheet_name);
% 2번째 열의 데이터 선택
variable_to_test = excel_data{:, 2};
% ADF 단위근 검정 수행
[h, pValue, stat, cValue, reg] = adftest(variable_to_test, 'lags', 0)
h = logical
1
pValue = 1.0000e-03
stat = -16.5478
cValue = -1.9417
reg = struct with fields:
num: 304 size: 303 names: {'a'} coeff: 0.0503 se: 0.0574 Cov: 0.0033 tStats: [1×1 struct] FStat: [1×1 struct] yMu: 1.7162 ySigma: 43.1074 yHat: [303×1 double] res: [303×1 double] DWStat: 1.9979 SSR: 2.2173e+03 SSE: 5.6066e+05 SST: 5.6288e+05 MSE: 1.8565e+03 RMSE: 43.0870 RSq: 0.0039 aRSq: 0.0039 LL: -1.5697e+03 AIC: 3.1414e+03 BIC: 3.1451e+03 HQC: 3.1429e+03
% 결과 출력
fprintf('ADF 단위근 검정 결과:\n');
ADF 단위근 검정 결과:
fprintf('검정 통계량 (ADF 통계량): %.4f\n', stat);
검정 통계량 (ADF 통계량): -16.5478
fprintf('P-값: %.4f\n', pValue);
P-값: 0.0010
fprintf('임계값 (1%%, 5%%, 10%%): %.4f, %.4f, %.4f\n', cValue(1), cValue(2), cValue(3));
Index exceeds the number of array elements. Index must not exceed 1.
% 검정 결과 해석
if h == 0
fprintf('결론: 귀무가설을 기각할 수 없으므로 시계열에는 단위근이 존재합니다.\n');
else
fprintf('결론: 귀무가설을 기각하므로 시계열에는 단위근이 존재하지 않습니다.\n');
end
As I do it, I keep getting errors in the index part. If you look at the file, as you know, I'm trying to get an adf with the time series data in the second column (it's a first-order differential value), but why is this error occurring

Réponses (1)

Cris LaPierre
Cris LaPierre le 1 Fév 2024
cValue is a scalar (only contains a single value), so the error is coming from your attempts to index a 2nd and 3rd value.
  4 commentaires
Walter Roberson
Walter Roberson le 1 Fév 2024
Perhaps you want to increase the number of lags ?
형현
형현 le 2 Fév 2024
That's right, since the data I originally wanted to use uses a total of 10 variables on the Excel file, there are a total of 10 time series data columns, and through this, I would like to conduct an adf test at once to derive the T and P values in a table.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by