/************************************************************************ S(X,Y,W,M) Calculate the similarity of two portfolios. Input: X and Y are the portfolios. They must be e x e conformable. They can both be Nx1 vectors or NxM matrices. One can be an Nx1 vector, the other an NxM matrix, etc. W is an Nx1 vector of weights, where each row represents the weight of the corresponding row element of the portfolios. W can also be a scalar, in which case all weights are set to that scalar. M is an Nx1 vector of max distances, where each row represents the max distance of the corresponding row element of the portfolios. M can also be a scalar, in which case all max distances are set to that scalar. Output: Vector or matrix of S similarity scores, depending on whether X and Y are vectors or matrices. Paper: This procedure is based on the measure of similarity, S, developed in Signorino, Curtis S. and Jeffrey M. Ritter. 1997. "Tau-b or Not Tau-b: Measuring the Similarity of Alliances and Interests." The current version of this paper can be found at http://www-vdc.fas.harvard.edu/staff/curt_signorino/sigrit97.htm. A previous version was presented at the 1997 annual meeting of the Midwest Political Science Association. Note: In the notation of the paper, this version of the procedure assumes the scoring rule l_k(a^i_k)=a^i_k. In other words, the portfolios are assumed to represent the points in the N-dimensional space and the distance is calculated based on those points. Example 1: We have two alliance portfolios Ai and Aj and the share of system capabilities W of each row nation in those portfolios. Our alliance data is coded 0,1,2,3, so the max alliance distance along any one dimension is 3. To calculate the similarity of the two alliance portfolios, weighting by system capabilities, we would calculate let Ai = 3 3 2 2; @ i's alliance portfolio @ let Aj = 2 2 3 3; @ j's alliance portfolio @ let W = .5 .3 .1 .1; @ nations' system shares @ S(Ai,Aj,W,3); Example 2: We are given two nations with alliance portfolios over a total of four nations and UN voting portfolios over three resolutions. The alliance data is coded 0,1,2,3, so the max alliance distance is 3. The UN data is coded 1,2,3, so the max UN distance is 2. We want to weight the alliances by the respective nations' share of the system capabilities, which we've been given for the four nations: .5, .3, .1, and .1. We decide to uniformly weight the UN votes. And we also decide to uniformly weight alliances versus UN votes. S would then be calculated for the stacked portfolios as follows: let X = 1 1 2 2 1 2 3; @ alliances | UN votes @ let Y = 0 1 2 3 3 2 1; @ alliances | UN votes @ let W = .5 .3 .1 .1 1 1 1; @ weight of each @ let M = 3 3 3 3 2 2 2; @ max dist for each @ S(X,Y,W,M); Please report any bugs to Curt Signorino curt@latte.harvard.edu Jeff Ritter jritter@fas.harvard.edu History: 12/29/97 - Added normalization of dimensions. Curt Signorino & Jeff Ritter, 12/29/97 ************************************************************************/ proc S(x,y,w,m); local r,sim,d,dmax; r=rows(x); @ # of rows in portfolios @ if rows(w)==1; @ check whether w is a scalar @ w=ones(r,1).*w; endif; if rows(m)==1; @ check whether m is a scalar @ m=ones(r,1).*m; endif; d=sumc((w./m).*abs(x-y)); @ distance between two points @ dmax=sumc(w); @ max dist possible, given normalization @ sim=1-2.*d./dmax; @ similarity score @ retp(sim); endp;