% function to do pcr regression a=pcr_bj(x,y,k) saved as pcr_bj.m % programmed by B. Joseph June 2001 % % The program solves the set of redundant equations % Xa=y % inputs to the function call are % X: a matrix % y : the right hand side vector % k : the number of principal components to be retained in the % PCR regression % the function returns a vector a. function a=pcr_bj(x,y,k) [u,s,v]=svd(x); ut=u(:,1:k); vt=v(:,1:k); st=s(1:k,1:k); t=ut*st; p=vt; a=p*inv(t'*t)*t'*y; return