function [R2,out]=rsquared(x,y,kmax,method,h) %RSQUARED calculates the R-squared value of the robust or classical PCR/PLS analysis. This function % is used in rpcr.m and rsimpls.m. % % The Robust R-squared is described in: % Hubert, M., Verboven, S. (2003), % "A robust PCR method for high-dimensional regressors", % Journal of Chemometrics, 17, 438-452. % % The required input arguments % x : the explanatory variables % y : the response variables % kmax : the number of components to choose in the ROBPCA method % method : the method for which the R2 has to be computed. It can be 'RSIMPLS' or 'RPCR'. % %Optional input arguments % h : the quantile used in RPCR/RSIMPLS % % I/O: R2=rsquared(x,y,10) % % This function is part of LIBRA: the Matlab Library for Robust Analysis, % available at: % http://wis.kuleuven.be/stat/robust.html % % Written by S.Verboven on 31-10-2002 % Last updated on 18-02-2003 if nargin<4 error('Missing input arguments') end [n,p]=size(x); [n,q]=size(y); cutoffWeights = sqrt(chi2inv(0.975,q)); if nargin<5 h=floor(0.75*n); end count=1; if q>1 while count*q+q+(q*(q+1)/2) <= h count=count+1; end else while count+2