- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
I am applying ARIMA
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Seemant Tiwari
le 25 Nov 2023
Commenté : Seemant Tiwari
le 27 Jan 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
0 commentaires
Réponse acceptée
Hassaan
le 8 Jan 2024
Modifié(e) : Hassaan
le 8 Jan 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
Feel free to contact me.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Oceanography and Hydrology dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!