function cv = covpairpermute(y, cov, geno, chrid, nperm) %permutation test for covpairwise %to test effects of marker pairs that interact with a covariate % %Input Variable: % y: nxk matrix of trait values % cov: nx1 vector of covariates, use [] if none % geno: nxm genotyping array, encoded as 0-1 or as 0-1-2 % nperm: number of permutations %OUTPUT VARIABLES % cv: 4x4matrix of critical values (.8, .9, .95 and .99) from permutation analysis %missing data check if any(any(isnan(geno)))| any(isnan(cov)) | any(isnan(y)) exit('missing data in geno, yy or cov') end %permutation test Fmax = zeros(nperm,4); for j = 1:nperm %generate the permutation indices ord = randperm(length(y)); %permute the trait values and covariate ptrait = y(ord); pcov = cov(ord,:); %compute overall F and record the maximum value [F1, F2, F3, F4] = covpairwise(ptrait, pcov, geno, chrid); Fmax(j,:) = max([F1(:), F2(:), F3(:), F4(:)]); end %sort maximal F's Fmax = sort(Fmax); %compute critical values cv=Fmax([ceil(.8*nperm),ceil(.9*nperm),ceil(.95*nperm),ceil(.99*nperm)],:);