You are on page 1of 4

* codes 03/28/2013, Umesh Rosyara; * please test the codes; data straberry; infile 'C:\gca_sca_first_step1_OR.

txt' dsd dlm='09'x truncover firstobs=2; input SN Evaluation_Year ID $ Parent1 $ Parent2 $ Line $ Tester $ cross $ P_FILLED_ACHENES GLOSS EXTERNAL_COLOR PH SOLUBLE_SOLIDS; run; TITLE 'The strawberry data' ; proc print DATA=straberry (OBS=20) NOOBS; run; ; proc contents can be used to display list of variables and types; proc contents data=straberry out=contents noprint; run; ***************************************non editing zone ; * sort data, important for the followinng step; PROC SORT DATA=strawberry; BY Line Tester; run; * names of line and testers; PROC SUMMARY DATA=straberry NOPRINT;; CLASS Line Tester ;; OUTPUT OUT=plist(where=(_type_=3)); TITLE 'List of lines, testers and number of progenies per cross' ; PROC PRINT DATA=plist noobs; var line tester _FREQ_; RUN; *the above step will produce list of tester and crosses; **************** * now create a new dataset named parent ; DATA parent; SET plist(rename=(Line=parent)) plist(rename=(Tester=parent)); PROC SUMMARY DATA=parent(keep=parent); CLASS parent; OUTPUT OUT=parent(where=(_type_=1)); DATA parent(drop=_type_ _freq_ pn); SET parent; pn+1; CALL SYMPUT('pn',compress(pn)); *get total number of parents; * creates a macro variable called &pn, i.e. number of parents, used for creating Z matrix TITLE 'List of parents' ; PROC PRINT DATA=parent; RUN; * the above step produce list of parents;

************************************************************ * step 2: creating user defined Z matrix for the random effects; * using proc IML to generate the dummy variables; * construct dummy variables ; PROC IML; USE straberry; READ ALL VAR {Line Tester} INTO dt; CLOSE strawberry; n=NROW(dt); USE parent; READ all var {parent} into p; CLOSE parent; pcode=CHAR(1:NROW(p),5,0)`; * 5 is the length; *** create pcode corresponding parent coding in dummy; p=p||pcode; PRINT n p ; *Check number of observations and parents(pn); CREATE pcode FROM pcode [COLNAME={'p'}]; APPEND FROM pcode ; CLOSE pcode; *create dummy variables; a=SHAPE(0,n,NROW(p)); DO i=1 to n; DO k=1 to nrow(p);; IF dt[i,1]=p[k,1] | dt[i,2]=p[k,1] then a[i,k]=1; END; END; CREATE dummy from a; APPEND FROM a; CLOSE dummy; QUIT; * you can see the dummy variables with 1 and 0; proc print data = dummy (OBS=20) NOOBS; run; * merging the design matrix (dummy variable with the main dataset ; DATA straberry; MERGE straberry dummy; PROC SORT DATA=straberry; BY Evaluation_Year cross; RUN; * printing dataset after merging, only 20 observation and selected variable; * P_FILLED_ACHENES is printed ; * only 5 column of dummy variable matrix are printed; TITLE 'Data with dummy variables' ; PROC PRINT DATA=straberry (OBS=20) NOOBS; VAR line tester P_FILLED_ACHENES col1-col5; RUN; * running proc mixed on P_FILLED_ACHENES ; * without BLUP soution;

PROC MIXED DATA=straberry COVTEST ASYCOV UPDATE PLOTS; CLASS Evaluation_Year cross ; MODEL P_FILLED_ACHENES = Evaluation_Year cross; RANDOM COL1-COL&pn / TYPE=TOEP(1); * GCA effects ; * using variance component is Banded Toeplitz; * after the Random statement to obtain a single VC for line and tester; RANDOM cross; * SCA effects ; ODS OUTPUT COVPARMS=_varcomp ASYCOV=_cov; RUN;

PROC MIXED DATA=straberry COVTEST ASYCOV UPDATE; CLASS Evaluation_Year cross Line Tester; MODEL P_FILLED_ACHENES = Evaluation_Year; RANDOM COL1-COL&pn / TYPE=TOEP(1); * GCA effects ; * using variance component is Banded Toeplitz; * after the Random statement to obtain a single VC for line and tester; RANDOM cross / solution; * SCA effects ; *RANDOM Line * Tester /solution; ODS OUTPUT COVPARMS=_varcomp ASYCOV=_cov; ODS output SolutionR = BLUPDATA; ** Write the BLUP solutions into a SAS data set; RUN; proc print data= BLUPDATA; run;

* section 3: estimation of variance components ********************************* ****** ***** although you can use the above output to calculate different VC manually; ***** the objective of this section is to automate the process; proc iml ; USE _varcomp; READ all var {Estimate} into VC; CLOSE _varcomp; * Creating matrix of covariances of variance components; USE _cov; READ all var {CovP1 CovP2 CovP3} into COV; CLOSE _cov;

***** vector of coefficients for the numerator of heritability; AU=SHAPE(0,nrow(VC),1); AU[1,1]=1*4; *** vector of coefficients for the denominator of heritability; AV=SHAPE(1,nrow(VC),1); AV[1,1]=2; Total=VC[+,1]; *Take the SUM of VC column vector to obtain; *total observed variance; phen=AV`*VC; *Phenotypic variance; h2_i=AU`*VC/Phen ; *Heritability =Additive/Phenotypic; VC_pct=VC/Total*100; *Percentage of variances by each term; Var_VC=VECDIAG(Cov); *Variance of variances; SE_VC=sqrt(Var_VC); *Standard Errors of variances ; * Delta method to estimate standard error of heritability; var_U =AU`*Cov*AU ; *variance of numerator ; var_V =AV`*Cov*AV ; *variance of denominator ; cov_UV=AU`*Cov*AV ; *covariances between variances; seh2i = sqrt( (h2_i*h2_i) * ((var_U/(AU`*VC)**2)+(var_V/(AV`*VC)**2) (2*cov_UV/(A U`*VC)/(AV`*VC)))); PRINT VC [format=6.3] SE_VC [format=6.4] VC_pct [format=6.1] phen [format=6.3] h2_i [format=6.3] seh2_i [format=6.3] ;; RUN; QUIT;

You might also like