偏最小二乘法PLS回归NIPALS算法的Matlab程序及例子②function[T,P,W,Wstar,U,b,C,B_pls,...Bpls_star,Xori_rec,Yori_rec,...R2_X,R2_Y]=PLS_nipals(X,Y,nfactor)%USAGE:[T,P,W,Wstar,U,b,C,Bpls,Bpls_star,Xhat,Yhat,R2X,R2Y]=PLS_nipals(X,Y,nfact)%PLSregressionNIPALSalgorithmPLS回归NIPALS算法%ComputethePLSregressioncoefficientsPLS回归系数的计算%X=T*P'Y=T*B*C'=X*BplsXandYbeingZ-scores%B=diag(b)%Y=X*Bpls_starwithXbeingaugmentedwithacolofones%andYandXhavingtheiroriginalunits%T'*T=I(NBnormalization<>SAS)%W'*W=I%%TestforPLSregression%HerveAbdiNovember2002/revNovember2004%%%VersionwithT,W,andCbeingunitnormalized%U,Parenot%nfact=numberoflatentvariablestokeep保持潜在变量的数量%default=rank(X)X_ori=X;Y_ori=Y;ifexist('nfactor')~=1;nfactor=rank(X);endM_X=mean(X);M_Y=mean(Y);S_X=std(X);S_Y=std(Y);X=zscore(X);Y=zscore(Y);[nn,np]=size(X);[n,nq]=size(Y);ifnn~=n;error(['Incompatible#ofrowsforXandY']);end%Precisionforconvergenceepsilon=eps;%#ofcomponentskepts%Initialistion%TheYsetU=zeros(n,nfactor);C=zeros(nq,nfactor);%TheXsetT=zeros(n,nfactor);P=zeros(np,nfactor);W=zeros(np,nfactor);b=zeros(1,nfactor);R2_X=zeros(1,nfactor);R2_Y=zeros(1,nfactor);Xres=X;Yres=Y;SS_X=sum(sum(X.^2));SS_Y=sum(sum(Y.^2));forl=1:nfactort=normaliz(Yres(:,1));t0=normaliz(rand(n,1)*10);u=t;nstep=0;maxstep=100;while(((t0-t)'*(t0-t)>epsilon/2)&(nstepTh...