MATLAB: Can PRINCOMP be used on incomplete or missing data in MATLAB 7.8 (R2009a)

Statistics and Machine Learning Toolbox

I wish to do principal component analysis on a dataset containing missing data. I have used NaNs as placeholders. When I pass the data into PRINCOMP, I obtain the following error:
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.
Error in ==> princomp at 69
[U,sigma,coeff] = svd(x0,econFlag); % put in 1/sqrt(n-1) later

Best Answer

The algorithm underlying PRINCOMP that determines these coefficients does SVD on the input matrix. If the input matrix contains NaNs or Infs as placeholders for the empty elements, SVD can not be done. Therefore, PRINCOMP can only be used with complete data.
As a workaround, you could use the ISNAN and ISINF functions to identify and remove NaN or INF elements if it makes sense for your situation.
Computing the principal components for incomplete or missing data is an area of active research in the Statistics community. These methods often suggest ways for estimating values for the missing data and then doing PCA. This may or may not be an option, depending on whether you have a reliable way of extrapolating values for timestamps where no data was observed.