Azzera filtri
Azzera filtri

I am applying ARIMA

4 visualizzazioni (ultimi 30 giorni)
Seemant Tiwari
Seemant Tiwari il 25 Nov 2023
Commentato: Seemant Tiwari il 27 Gen 2024
Hi all,
I have time series data.
My input series is Temperature, humidity, pressure
And i want to predict wind speed one day ahead, so my target series is wind speed
I am arranging my data for 1 day ahead prediction like:
d = ones(1,365);
X_new = [Temperature; humidity; pressure];
X = mat2cell (X_new, 3, 24*d);
Input series = X
T_new = [wind speed];
T = mat2cell (T_new,1, 24*d);
Target series = T
For next step i want to calculate p, d, q Can any one help me to write code for next step about my input series and target series

Risposta accettata

Hassaan
Hassaan il 8 Gen 2024
Modificato: Hassaan il 8 Gen 2024
% Assuming X_new and T_new are your full datasets for temperature, humidity,
% pressure, and wind speed respectively
% Reshape the data into a 365x24 matrix (assuming hourly data)
Temperature = reshape(Temperature, 24, []); % Reshape into 24-hour segments
Humidity = reshape(Humidity, 24, []);
Pressure = reshape(Pressure, 24, []);
WindSpeed = reshape(WindSpeed, 24, []);
% Prepare the dataset for ARIMA; usually ARIMA works with univariate series,
% so you may need to run separate models for each input or create a multivariate model.
% Here's how you would prepare for a univariate ARIMA for wind speed prediction.
% For simplicity, let's predict wind speed based on its past values.
% Flatten the data back to a vector for ARIMA
WindSpeedVector = WindSpeed(:);
% Divide the data into training and testing
trainData = WindSpeedVector(1:end-24); % all data except the last day
testData = WindSpeedVector(end-23:end); % the last day for validation
% Use autocorrelation to determine a good starting point for 'p' and 'q'
figure;
autocorr(trainData);
figure;
parcorr(trainData);
% Use ADF test to determine if data is stationary or how much differencing 'd' is needed
[~,pValue,~,~,~] = adftest(trainData);
% If pValue is greater than 0.05, we may need to difference the data
if pValue > 0.05
d = 1;
else
d = 0;
end
% Initialize a range of p and q to try
p = 0:3;
q = 0:3;
% Initialize AIC, BIC matrices to store the values for each model
AIC = zeros(length(p), length(q));
BIC = zeros(length(p), length(q));
% Grid search over p and q values
for i = 1:length(p)
for j = 1:length(q)
model = arima(p(i), d, q(j));
try
[fit,~,logL] = estimate(model, trainData, 'Display', 'off');
[aic, bic] = aicbic(logL, numParams(fit), length(trainData));
AIC(i,j) = aic;
BIC(i,j) = bic;
catch e
% If model fails to converge, assign a large AIC/BIC
AIC(i,j) = inf;
BIC(i,j) = inf;
end
end
end
% Find the indices of the minimum AIC and BIC
[minAIC, idxAIC] = min(AIC(:));
[minBIC, idxBIC] = min(BIC(:));
% Convert linear indices to subscripts to find corresponding p and q values
[pAIC, qAIC] = ind2sub(size(AIC), idxAIC);
[pBIC, qBIC] = ind2sub(size(BIC), idxBIC);
% Display the results
fprintf('Optimal p and q according to AIC: p = %d, q = %d\n', pAIC, qAIC);
fprintf('Optimal p and q according to BIC: p = %d, q = %d\n', pBIC, qBIC);
A basic grid search approach for determining the ARIMA model's p and q parameters based on AIC and BIC, and d based on the ADF test. The autocorrelation and partial autocorrelation plots can provide insights into potential values for p and q. You might need to adjust the code according to your specific data structure and requirements.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  2 Commenti
Seemant Tiwari
Seemant Tiwari il 23 Gen 2024
Plz share your mail id.
Thank you very much
Seemant Tiwari
Seemant Tiwari il 27 Gen 2024
Hi,
I want to create model. now i know p, d, q value. can you tell me, how can we get these values?
MD = ARIMA ('AR', { }, 'MA', { }, 'SAR', { }, 'SMA', { }, 'D', .., 'SEASONALITY',.., 'CONSTANT',.., 'VARIANCE'..)
How shall we calculate value of SAR, SMA, CONSTANT AND VARIANCE.?
For AR value is 1
MA value is 1
D is 1

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Conditional Mean Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by