*Holland (2006) Crop Sci. 46:642-654 genotypic correlation macro This version is for RCBD of one test involving genotypes dataset need to be named "tall" variables names are rep & geno do the correlation two variables at a time, which ones are defined in the call of the macro ; %macro gencorr(TraitI, TraitJ); data subset; set tall; if trait 5 "&TraitI" or if trait 5"&TraitJ"; *Perform multivariate REML estimation of variance and covariance components, using the "asycov" option of proc mixed to obtain the asymptotic variancecovariance matrix of the estimates; proc mixed data5subset asycov; class trait rep geno; *Treat environments and replications as fixed effects to speed computation of the variance and covariance estimates of interest. Note that the F-tests associated with these factors are testing the hypothesis that there are no significant differences among environments or among replications for the two traits combined. Such hypothesis are generally not of real interest, instead tests of main effects of environments and replications, if they are of interest, should be conducted on each trait separately with univariate analyses; model y 5 rep(trait); * Treat genotypes ("geno") and genotype-by-environment interactions ("geno*env") as random effects and estimate their variance and covariance components for the two traits with the following codes; random trait/subject 5 geno type 5 un; * Model the residual error term ("rep*geno(env)") to allow for covariances between error effects on the two traits measured on the same plot, but not between different plots; repeated trait/ sub 5 rep*geno type 5 un; *Output the estimates of variance and covariance components to a data set called "estmat" and output the asymptotic variance-covariance matrix of those estimates to a data set called "covmat"; ods output covparms 5 estmat asycov 5 covmat; run; *Read variance and covariance estimates ("estmat" data set, to be read into a vector called "e") and their variance-covariance matrix ("covmat" data set, to be read into a matrix called "cov") into proc iml to estimate correlations and their standard errors using the delta method; proc iml; use estmat; read all into e; use covmat; read all into cov; *Obtain the "C" matrix by removing the extra first column of the "cov" matrix; C 5 cov(|1:nrow(cov), 2:ncol(cov)|); *Obtain genotypic covariance (CovG) and variance components (VG1 and VG2) from the elements of the "e" vector; CovG 5 e(|2,1|); VG1 5 e(|1,1|); VG2 5 e(|3,1|); *Obtain phenotypic covariance (CovP) and variance components (VP1 and VP2) from the elements of the "e" vector; CovP 5 CovG 1 e(|5,1|); VP1 5 VG1 1 e(|4,1|); VP2 5 VG2 1 e(|6,1|); *Create a module called "correl" that will estimate genotypic and phenotypic correlations and their standard errors; start correl(C, CovG, VG1, VG2, CovP, VP1, VP2, RG, RP, SERG, SERP); RG 5 CovG/sqrt(VG1*VG2); * Make the derivative vector for rg, note that the order of the rows and columns of the variance covariance matrix is VG1, CovG, VG2, VGE1, CovGE, VGE2, VError1, CovError, VError2; dg5 (21/(2*VG1))//(1/CovG)//(21/(2*VG2))//0//0//0; *Compute the variance of the estimate of the genotypic correlation using the delta method, then take its square root to obtain the standard error of the genotypic correlation estimate ("serg"); varrg 5 (RG**2)*dg9*C*dg; serg 5 sqrt(varrg); RP 5 CovP/sqrt(VP1*VP2); *Make the derivate vector for rp; d1p 5 21/(2*VP1); d2p 5 1/CovP; d3p 5 21/ (2*VP2); dp 5 d1p//d2p//d3p//d1p//d2p//d3p; *Compute the variance of the estimate of the phenotypic correlation using the delta method, then take its square root to obtain the standard error of the phenotypic correlation estimate ("serp"); varrp 5 (RP**2)*dp‘*C*dp; serp 5 sqrt(varrp); finish correl; * Run the "correl" module and display the results; call correl(C, CovG, VG1, VG2, CovP, VP1, VP2, RG, RP, SERG, SERP); print "Genotypic Correlation Between &TraitI and &TraitJ"; print RG serg; print "Phenotypic Correlation Between &TraitI and &TraitJ "; print RP serp; quit; run; * End the macro;