Вы находитесь на странице: 1из 3

Procrustes distance.sas This routine computes the true Procrustes distance between each pair of specimens in the dataset.

Procrustes distance is reported as an angle in radians, representing the geodesic distance between two specimens in Procrustes space. As written here, the routine will print pairwise distances in the SAS OUTPUT window; distances will also be stored in a dataset named procd. The matri algebra for Orthogonal Procrustes Anal!sis comes from "ohlf # Slice $%&&'(; the code here follows their notation as closel! as possible. )*PUT+ One dataset containing onl! numeric coordinate ,ariables and a single character ,ariable of specimen labels. -ach row should represent the coordinates of a different specimen. Additional ,ariables can be screened out prior to beginning )./ using 0eep or drop statements in a data step. )nput data for this computation need not be superimposed. .atri of Procrustes distances between e,er! pair of specimens
"ohlf, 1. 2. # 3. -. Slice. %&&'. - tensions of the Procrustes method for the optimal superimposition of landmar0s. S!stematic 4oolog! 5&+6'78&.

OUTPUT+
"eference+

9ode annotation+
proc iml; use two; read all into X;

::: indicates lines that need to be changed for different datasets


Begins processing commands in Interactive Matrix Language. ### Tells IML to use data from dataset two. Inputs LL numeric data into a matrix X.

read all var !"# $! into name; '(3; n(nrow*X-; p(*ncol*X-.'-;

Inputs LL c%aracter varia&less into a matrix name. ### ' is t%e dimensionalit) of t%e data *eit%er + or ,-. n is t%e num&er of specimens computed as t%e num&er of rows in matrix X. p is t%e num&er of landmar's computed &) dividing t%e num&er of columns in X *corresponding to t%e num&er of coordinates- &) t%e dimensionalit) *'-. 1efines a matrix dmat using t%e /2function0 wit% t%e num&er of rows and columns e3ual to t%e num&er of specimens *n-. T%e default value for filling t%is matrix is 4. T%e purpose in generating t%is dumm) matrix is to %ave a place to record t%e distances as t%e) are later calculated. T%is creates a matrix ) of one row and columns e3ual to t%e num&er of varia&les for temporar) storage of specimen coordinate differences.

dmat(/*n0n-;

)(/*10ncol*X--;

do f(1 to n; do /(1 to n;

5ets up a loop wit% f c)cling up to t%e num&er of specimens. 5ets up a second loop 6IT#I7 T#8 9I$5T of /. Toget%er t%ese will c)cle t%roug% ever) com&ination of specimen pairs. 1efines X4 as t%e specimen given in t%e f row num&er. $es%apes t%e coordinate matrix of t%at specimen to %ave p x ' dimensions. T%ese are as a&ove wit% X4 5ets up an identit) matrix I of ran' p x p. 5ets up a p x p matrix wit% all values e3ual to 4.p. "omputes t%e centroid si?e of t%e first o&/ect. "omputes t%e centroid si?e of t%e second o&/ect. @ives t%e coordinates for t%e first specimen translated to t%e origin and scaled it &) its centroid si?e. s a&ove wit% X4prime 1efines cov+ as t%e matrix multiplication of t%e transpose of X4prime &) X+prime. <erforms a singular value decomposition on cov+0 )ielding B0 sig0 and A. T%e next four lines transform sig into a diagonal matrix of ones wit% t%eir signs corresponding to t%ose of t%e original elements of sig. #ere0 sig+ contains t%e a&solute values for all elements of sig. 1ividing sig &) sig+ )ields a vector of ones 'eeping t%eir original signs. Transposes t%e vector. "reates a new matrix 5 wit% t%e diagonal containing t%e ones from t%e previous 5. 1efines t%e rotation matrix #. X+star gives t%e new coordinates of X+ translated to a common origin wit% X40 scaled to a unit centroid si?e0 and rotated for t%e optimal least s3uares fit wit% X4. ) &ecomes a vector of t%e differences &etween t%e superimposed specimens at ever) coordinate. Matrix multiplies t%e transpose of ) &) ) and t%en ta'es t%e s3uare root of t%e trace

X4(X:f0;; X4(s%ape*X40p0'-; X+(X:/0;; X+(s%ape*X+0p0'-; I(I*p-; "a<(/*p0p01.p-; s4(s3rt*trace**I2"a<-=X4=X4>=*I2"a<---; s+(s3rt*trace**I2"a<-=X+=X+>=*I2"a<---; X4prime(*I2"a<-=X4.s4;

X+prime(*I2"a<-=X+.s+; cov+(X4prime>=X+prime; " LL 5A1 *B0sig0A0cov+-; sig+(a&s*sig-;

5(sig.sig+; 5(5>; 5(diag*5-; #(A=5=B>; X+star(X+prime=#;

)(X4prime2X+star; d(s3rt*trace*)>=)--;

*i.e0 t%e sum of diagonal elements w%ic% correspond to t%e s3uared differences in eac% coordinate- of t%is matrix and defines t%is distance as d. r%o(2=arsin*d.2-; dmat:/0f;(r%o; "omputes t%e angle r%o *in radians- as twice t%e arcsine of d.+. <uts t%e value r%o into t%e matrix dmat. 7ote t%at replacing r%o wit% d %ere will cause t%e output to &e a distance rat%er t%an an angle *geodesic distance-. utomaticall) defines t%e distance &etween a specimen and itself as ?ero0 eliminating potential pro&lems wit% rounding error. 8nds t%e / loop0 causing / to c)cle t%roug% again as /C4. 8nds t%e f loop *after all t%e /s %ave c)cled- causing f to iterate again D wit% eac% iteration containing a full c)cle of / interations. <rints matrix dmat to t%e output window0 wit% row and column names gives &) t%eir specimen la&els0 stored earlier in name. "reates a 5 5 dataset named procd to record all of t%e pairwise <rocrustes distances. Eutputs dmat data to t%e dataset. 8nds t%e IML session.

if /(f t%en do; dmat:/0f;(0; end;

end; end;

print dmat:rowname(name colname(name;;

create procd from dmat; append from dmat; a&ort;

Вам также может понравиться