Rolling Window PCA- Save Explained factors for every period
Show older comments
I need to do rolling window PCA and I have a rolling window size=20. But I want to save all explained factors for [coeff,scores,explained]=pcacov(X) function in for loop.
What would be the most simple solution?
Thank you very much.
Answers (1)
the cyclist
on 19 Dec 2015
One way;
numberOfVars = 100; % Set to however big your data are
numberOfWindows = 10;
explainedArray = zeros(numberOfVars,numberOfRuns);
for nw = 1:numberOfWindows
[coeff,scores,explained]=pcacov(X);
explainedArray(:,nw) = explained;
end
4 Comments
meral serçe
on 19 Dec 2015
the cyclist
on 19 Dec 2015
I assumed you only needed help with the storage in the for loop, since that is all you asked about.
Just modify this line
[coeff,scores,explained]=pcacov(X);
so that you have the rolling window within X each time. Maybe something like
X = biggerX(<define window in here>,:)
Do you need help in how to define a rolling window?
meral serçe
on 21 Dec 2015
the cyclist
on 24 Dec 2015
Insert a line like this in the loop:
rollingWindowX = fullX(nw:nw+20,:)
and do the PCA on rollingWindowX.
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!