% load the diabetes data from the paper X=dlmread('diabX.tab',' ',1,1); y=dlmread('diaby.tab',' ',1,1); fit_from_R=dlmread('diabfit.tab',' ',1,1); % also load the answer from the R code that accompanied the paper, for comparison % normalize the covariates [n,m]=size(X); stdX=std(X,0,1); X=X./repmat(stdX,n,1); % normalize the response y=y-mean(y); stdy=std(y); y=y./stdy; % get the answer from LAR betas=lars(X,y); % correct for normalization nsteps=size(betas,2); betas=betas.*repmat((stdy./stdX)',1,nsteps); % look at the betas as they change and compare to fit from R figure(1); s=sum(abs(betas),1); plot(s, betas'); xlabel('|\beta|'); ylabel('\beta_i'); title('coefficients(\beta''s) as they change'); fprintf('discrepancy between matlab and R fit = %g\n',norm(betas-fit_from_R(2:end,:)'));