n=100; k=10; % An example such that two covariates have the same correlation with response, % to test tie breaker in LAR. In the reference paper, this situation is % excluded from the proof of correctness(by jittering the response). In % practice the code should run fine. % random response Y=rand(n,1); Y=Y-mean(Y); Y=Y/std(Y); % pick vectors from the space orthogonal to Y and with mean 0 % from them construct covariates with prescribed correlation to Y nA=null([Y'; ones(1,n)]); x1=nA(:,1); x2=nA(:,2); lambda=3; x1=lambda*x1+Y; % correlation with Y is 1/sqrt(1+lambda.^2*var(x1_old)/var(Y)) x2=lambda*x2+Y; xs=rand(n,k); X=[x1 x2 xs]; X=X-repmat(mean(X,1),n,1); X=X./repmat(std(X,0,1),n,1); % run it through LARS, if x1 and x2 are added first then they should appear together beta=lars(X,Y,[],true);