function out=pcout(data,comp); %PCOUT is the method proposed by Filzmoser et al. "Outlier detection in %high dimensions",Computational Statistics&Data Analysis (2008). out.w % Method is claimed to be well for outlier detection in high dimensions. %Required input: % data: The data matrix % comp: Determines the # of components: % less than 1 (percentage of explained variance) % greater than 1 (# of components) %Output: % out.w : Final weights % out.rd1 : distances based on kurtosis weighted components % out.rd2 : distances based on original components % out.V : Coeffients for sphered data % out.T : Scores for sphered data % out.med : Robust center % out.mad : Robust scatter %Created by: Nedret Billor & Asuman Turkmen %Updated on 04/01/2009 %MAIN PROGRAM: [n p]=size(data); %Step1: Robustly sphering the data and computing semi-robust covariance matrix a1=medscale(data,1); X=a1.sc;%Sphered data matrix, X* %Step2: PCA analysis for X in step 1 and robustly sphered PC's (k %components are chosen based on 99% default cutoff) [Z,s,v1,V,pr]=pca(X); I=(1:size(Z,2))'; e=cumsum(pr)/100; % [U D V]=svd(X'*X,0); % Z=X*V; % I=(1:p)'; % e=cumsum(diag(D)/sum(diag(D))); if comp<1 k=min(I(e>=comp)); else k=comp; end; Told=Z(:,1:k); a2=medscale(Told,1); T=a2.sc;%Sphered principal components,T* %Step3: Computing robust kurtosis weights for each component and computing %Euclidian norms for weighted components T1=(T.^4); we1=abs(mean(T1)-3); We1=diag(we1./sum(we1)); Z=T*We1; if k==1; RD=abs(Z); else Z2=Z.^2; RD=(sqrt(sum(Z2')))'; %Equivalent to the Robust Mahalanobis distances end;% d=(RD*sqrt((chi2inv(0.5,k))))/median(RD);%Location distance %Step4: Determine the weights w1; r=medscale(d,1); c=r.med+2.5*r.mad; M=quantile(d,.33); cM=c-M; w1=repmat(0,n,1); for i=1:n; if (M