* NONPARADOM - 2. * This program tests for nonparallel dominance, a form of asymmetry in predictability, between i to j, and k to L, as described by Wampold (1984, 1989, 1992). The data are assumed to be a series of integer codes with values ranging from "1" to what ever value the user specifies in the "ncodes" computation at the start of the program. * Set 'seed' to a non-negative integer; 1953125 is good. SET MXLOOPS=3000000 length=none printback=none width=80 seed = 1953125. matrix. * Enter the number of possible code values here. compute ncodes = 6. * This program tests the difference in predictability between i to j, and k to L. Enter the code values for your desired test below. compute i = 5 . compute j = 3 . compute k = 6 . compute L = 2 . * Enter labels for the codes (5 characters maximum), if desired, here. compute labels={"Code 1","Code 2","Code 3","Code 4","Code 5","Code 6", "Code 7","Code 8","Code 9","Code 10","Code 11","Code 12","Code 13", "Code 14","Code 15"}. * Enter the lag number for the analyses here. compute lag = 1. * Can adjacent events be coded the same? Enter "1" if yes, enter "0" if no. compute adjacent = 1. * Enter "1" for one-tailed tests; enter "2" for two-tailed tests. compute tailed = 1. * Do you want to run permutation tests of significance? "1"=yes, "0"=no; Warning: these computations are time-consuming. compute permtest = 0. * Enter the number of desired permutations per block here. compute nperms = 10. * Enter the number of desired blocks of permutations here. compute nblocks = 3. * Confidence intervals for the permutation tests: Enter "95" for 95% confidence intervals; enter "99" for 99% confidence intervals. compute confid = 95. * Would you like to save any matrix output data for use in SPSS or elsewhere? e.g., Would you like to save the transitional frequency matrix? the expected frequencies? kappas? z-values? If "yes," see the commands at the end of this file. * Enter/read the data into a matrix with the name "alldata". The program provides results for each session/dyad/group in your data set. The very first code for each session/dyad/group must be > 999. The program interprets codes > 999 as session/dyad/group numbers, and breaks the codes down into dyads/groups on this basis. The very last code in that you enter, at the very end of the data codes, must be a number > 999 (to signal the end of the data file). Use the following example as a model. It involves data for 3 sessions/dyads/groups; the sessions/dyad/group numbers are 1000, 2000, and 3000; and the last code in the data matrix is 9999999. compute alldata = { 1000; 2;5;2;4;2;5;2;4;2;4;2;2;5;2;4;2;5;3;4;3;4;1;4;4;1; 2;5;2;1;5;4;2;5;1;4;4;2;3;6;6;2;2;6;5;5;5;6;3;6;3; 3;6;3;2;5;3;5;2;6;2;2;2;5;2;4;4;5;2;5;2;5;5;4;2;5; 5;5;2;5;2;5;2;5;2;2;5;2;5;2;2;5;5;2;2;2;5;2;5;2;5; 2;5;2;2;5;2;5;3;5;2;5;5;2;2;5;2;2;5;2;6;2;5;4;2;5; 2;4;4;2;1;2; 2000; 5;2;5;2;5;5;5;3;5;2;5;5;2;5;5;2;5;2;5; 2;4;2;4;2;5;4;2;2;5;2;5;5;5;2;5;2;5;5;2;5;2;5;5;2; 1;2;5;1;5;1;5;5;4;2;2;2;3;6;3;6;3;6;3;6;3;6;3;3;6; 6;6;5;1;2;5;2;5;5;2;4;5;5;2;5;5;2;5;2;5;2;5;1;5;4; 2;2;5;2;5;2;5;4;1;4;4;2;4;4;2;4;2;3;5;4;2;2;5;2;6; 1;4;1;4;5;5;5;4;5;2;4;5; 3000; 5;2;5;2;2;2;5;2;2;5;2;2;4; 2;2;2;6;2;4;3;3;3;3;2;3;6;3;5;3;3;5;3;2;2;2;2;6;3; 6;3;6;2;6;1;6;3;3;3;3;5;3;5;2;5;3;3;6;3;1;4;1;5;1; 5;6;3;3;6;3;6;3;6;3;6;3;6;3;3;6;3;6;3;2;5;2;5;2;5; 2;5;2;2;2;3;5;1;6;1;6;6;6;1;6;6;1;6;1;6;2;5;1;6;6; 6;2;2;6;6;6;2;6;2;6;2;5;5;5;5;5;5;6; 9999999 }. compute dyadnum = alldata(1,1). compute data = { 0 }. compute out = make(1,5,0). * setting up the data for each group/dyad. loop #dydloop = 1 to nrow(alldata). do if ( #dydloop > 1 and alldata(#dydloop,1) < 1000 ). compute data = { data ; alldata(#dydloop,1) }. end if. do if ( #dydloop > 1 and alldata(#dydloop,1) ge 1000 ). compute data = data(2:nrow(data), 1). * start of group/dyad analyses. compute freqs = make(ncodes,ncodes,0). loop #c = 1 to nrow(data). do if ( #c + lag le nrow(data) ). compute freqs((data(#c,1)),(data((#c+lag),1))) = freqs((data(#c,1)),(data((#c+lag),1))) + 1. end if. end loop. compute pd = make(ncodes,ncodes,-9999). compute et = make(ncodes,ncodes,-9999). compute rowtots = rsum(freqs). compute coltots = csum(freqs). compute n = nrow(data). compute nr = rowtots. compute nr(data(n,1)) = nr(data(n,1)) + 1. compute prow = nr / (msum(nr)). loop #i = 1 to ncodes. loop #j = 1 to ncodes. do if (nr(#i,1) > 0 and nr(#j,1) > 0 and prow(#j,1) > 0). compute pd(#i,#j)=((freqs(#i,#j) / nr(#i,1)) - prow(#j,1) ) / prow(#j,1). do if (nr(#i,1) > 0 and nr(#j,1) > 0). compute et(#i,#j) = (nr(#i,1) * nr(#j,1)) / n. end if. end if. end loop. end loop. do if (nr(i,1) le nr(j,1)). compute minij = nr(i,1). else. compute minij = nr(j,1). end if. do if (nr(k,1) le nr(L,1)). compute minkL = nr(k,1). else. compute minkL = nr(L,1). end if. * kappa. compute kappa = -9999. compute case = -9999. do if ( freqs(i,j) = et(i,j) ). compute kappa = 0. compute case = 0. end if. do if ( nr(i,1) > 0 and nr(j,1) > 0 and nr(k,1) > 0 and nr(L,1) > 0). * Wampold's 1st case. do if ( freqs(i,j) > et(i,j) and freqs(k,L) ge et(k,L) ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)-nr(i,1)*nr(j,1)*freqs(k,L))/ ( nr(k,1)*nr(L,1)*minij-(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n)). do if ( kappa < 0 ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)-nr(i,1)*nr(j,1)*freqs(k,L))/ ( nr(i,1)*nr(j,1)*minkL - (nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n)). end if. compute case = 1. end if. * Wampold's 2nd case. do if ( freqs(i,j) < et(i,j) and freqs(k,L) le et(k,L) ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)-nr(i,1)*nr(j,1)*freqs(k,L))/ (-1*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n)). compute case = 2. end if. * Wampold's 3rd case. do if ( freqs(i,j) > et(i,j) and freqs(k,L) le et(k,L) ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)+nr(i,1)*nr(j,1)*freqs(k,L)- 2*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n) )/ ( nr(k,1)*nr(L,1)*minij - (nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n)). do if ( kappa < 0 ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)+nr(i,1)*nr(j,1)*freqs(k,L)- 2*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n) )/ (nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n). end if. compute case = 3. end if. * Wampold's 4rth case. do if ( freqs(i,j) < et(i,j) and freqs(k,L) ge et(k,L) ). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)+nr(i,1)*nr(j,1)*freqs(k,L)- 2*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n) )/ (-1*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n)). do if (kappa < 0). compute kappa=(nr(k,1)*nr(L,1)*freqs(i,j)+nr(i,1)*nr(j,1)*freqs(k,L)- 2*(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n) )/ ((nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n) - nr(i,1)*nr(j,1)*minkL ). end if. compute case = 4. end if. end if. * observed frequency, expected frequency, variance, & z. compute zeqk = 9999. compute obs = -9999. compute ett = -9999. compute zkappa = -9999. compute pzkappa = -9999. do if (pd (i,j) ne -9999 and pd(k,L) ne -9999). * same direction. do if ( (pd(i,j)>=0 and pd(k,L)>=0) or (pd(i,j)<=0 and pd(k,L)<=0) ). compute obs=nr(k,1)*nr(L,1)*freqs(i,j)-nr(i,1)*nr(j,1)*freqs(k,L). compute ett = 0 . compute var=(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)* (n*nr(i,1)*nr(j,1) + n*nr(k,1)*nr(L,1) - nr(i,1)*nr(j,1)*nr(k,1) - nr(i,1)*nr(j,1)*nr(L,1) - nr(i,1)*nr(K,1)*nr(L,1) - nr(j,1)*nr(K,1)*nr(L,1) ))/ (n*(n-1)). compute zkappa = obs / sqrt(var). compute zeqk = zkappa. * different directions. else if ( (pd(i,j)<=0 and pd(k,L)>=0) or (pd(i,j)>=0 and pd(k,L)<=0) ). compute obs=nr(k,1)*nr(L,1)*freqs(i,j)+nr(i,1)*nr(j,1)*freqs(k,L). compute ett = 2*nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)/n. compute var=(nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1)* (4*nr(i,1)*nr(j,1)*nr(k,1)*nr(L,1) + n**2 *nr(i,1)*nr(j,1) + n**2 *nr(k,1)*nr(L,1) - n*nr(i,1)*nr(j,1)*nr(k,1) - n*nr(i,1)*nr(j,1)*nr(L,1)- n*nr(i,1)*nr(K,1)*nr(L,1) - n*nr(j,1)*nr(K,1)*nr(L,1) )) / (n**2 *(n-1)). compute zkappa = ( obs - ett ) / sqrt(var). do if ( ((pd(i,j) = 0 or pd(j,i) = 0)) and zeqk < zkappa ). compute zkappa = zeqk. end if. end if. compute pzkappa = (1 - cdfnorm(abs(zkappa))) * tailed. end if. do if (kappa > 0). compute sign = 1. else if (kappa < 0 and kappa ne -9999). compute sign = -1. else. compute sign = 0. end if. compute b = labels(1,1:ncodes). compute bb = { b,"Totals"}. print /space=3. print tailed /title="Requested 'tail' (1 or 2) for Significance Tests =". print dyadnum /title="Session/Group/Segment Number:". print {freqs, rowtots; coltots, msum(rowtots) } /title="Cell Frequencies, Row & Collumn Totals, & N"/cnames=bb/rnames=bb. print et /format "f5.4" /title="Expected Values/Frequencies"/cnames=b/rnames=b. print { i, j, k, L } /format "f12.4"/title = "Nonparallel Dominance Test for the following values of i, j, k, & L" /cnames={"Code i =","Code j =", "Code k =", "Code L =" }. print case /title="Sequential Dominance 'Case' Type (Wampold, 1989)" . print /title="Case 1: i increases j, and j increases i". print /title="Case 2: i decreases j, and j decreases i". print /title="Case 3: i increases j, and j decreases i". print /title="Case 4: i decreases j, and j increases i". print { ett, obs, kappa, zkappa*sign, pzkappa } /format "f12.4" /title="Results:"/cnames={"Expected", "Observed", "kappa","z", "sig."}. print /title= "The above Expected&Observed values are weighted; see Wampold,1989,p 184". * Permutation tests of significance. do if (permtest = 1 and obs ne -9999 and ett ne -9999). compute obs2 = obs. compute obs22 = ett-(obs2-ett). compute sigs = make(nblocks,1,1). loop #block = 1 to nblocks. print #block /title="Currently computing for block #:". print /space=1. compute results = make(nperms,1,-9999). loop #perm = 1 to nperms. * permuting the sequences; alogrithm from Castellan 1992. * when adjacent codes may be the same. compute datap = data. do if (adjacent = 1). loop #i = 1 to (nrow(datap) -1). compute kay=trunc((nrow(datap)-#i+1) * uniform(1,1) + 1 ) + #i - 1. compute d = datap(#i,1). compute datap(#i,1) = datap(kay,1). compute datap(kay,1) = d. end loop. end if. * when adjacent codes may NOT be the same. do if (adjacent = 0). compute datap = { 0; data; 0 }. loop #i = 2 to (nrow(datap) - 2). compute limit = 10000. loop #j = 1 to limit. compute kay = trunc(((nrow(datap)-1)-#i+1) * uniform(1,1) + 1) + #i - 1. do if ((datap(#i-1,1) ne datap(kay,1)) and (datap(#i+1,1) ne datap(kay,1)) and (datap(kay-1,1) ne datap(#i,1)) and (datap(kay+1,1) ne datap(#i,1)) ). break. end if. end loop. compute d = datap(#i,1). compute datap(#i,1) = datap(kay,1). compute datap( kay,1) = d. end loop. compute datap = datap(2:(nrow(datap)-1),:). end if. * transitional frequency matrix for permuted data. compute freqsp = make(ncodes,ncodes,0). loop #c = 1 to nrow(datap). do if ( #c + lag le nrow(datap) ). compute freqsp((datap(#c,1)),(datap((#c+lag),1))) = freqsp((datap(#c,1)),(datap((#c+lag),1))) + 1. end if. end loop. * nonparallel dominance frequency for permuted data. compute np = nrow(datap). compute nrp = rsum(freqsp). compute nrp(datap(np,1)) = nrp(datap(np,1)) + 1. do if (case = 1 or case = 2). compute obsp=nrp(k,1)*nrp(L,1)*freqsp(i,j)-nrp(i,1)*nrp(j,1)*freqsp(k,L). else if (case = 3 or case = 4). compute obsp=nrp(k,1)*nrp(L,1)*freqsp(i,j)+nrp(i,1)*nrp(j,1)*freqsp(k,L). end if. compute results(#perm,1) = obsp. end loop. * sig levels for the current block of permutations. * one-tailed. do if (tailed = 1). compute counter = 0. loop #i = 1 to nrow(results). do if ( case = 1 or case = 3 ). do if ( sign > 0 and results(#i,1) >= obs2 ). compute counter = counter + 1. else if ( sign < 0 and results(#i,1) <= obs2 ). compute counter = counter + 1. end if. end if. do if ( case = 2 or case = 4 ). do if ( sign > 0 and results(#i,1) <= obs2 ). compute counter = counter + 1. else if ( sign < 0 and results(#i,1) >= obs2 ). compute counter = counter + 1. end if. end if. end loop. do if (sign ne 0). compute sigs(#block,1) = counter / nperms. end if. end if. * two-tailed. do if (tailed = 2). compute counter = 0. loop #i = 1 to nrow(results). do if ( case = 1 or case = 3 ). do if ( sign > 0 and ((results(#i,1) >= obs2) or (results(#i,1) <= obs22))). compute counter = counter + 1. else if ( sign < 0 and ((results(#i,1) <= obs2) or (results(#i,1) >= obs22))). compute counter = counter + 1. end if. end if. do if ( case = 2 or case = 4 ). do if ( sign > 0 and ((results(#i,1) <= obs2) or (results(#i,1) >= obs22))). compute counter = counter + 1. else if ( sign < 0 and ((results(#i,1) >= obs2) or (results(#i,1) <= obs22))). compute counter = counter + 1. end if. end if. end loop. do if (sign ne 0). compute sigs(#block,1) = counter / nperms. end if. end if. end loop. * mean significance levels and confidence intervals. do if (confid = 95 and tailed = 1). compute z = 1.645. else if (confid = 95 and tailed = 2). compute z = 1.96. else if (confid = 99 and tailed = 1). compute z = 2.326. else if (confid = 99 and tailed = 2). compute z = 2.576. end if. compute meansigs = csum(sigs) / nblocks. do if (nblocks > 1). compute semeans=(sqrt(cssq(sigs-meansigs)/(nblocks -1)))/(sqrt(nblocks)). compute confidhi = meansigs + z &* semeans. compute confidlo = meansigs - z &* semeans. end if. print nperms /title="Number of permutations per block: ". print nblocks /title="Number of blocks of permutations: ". print meansigs /format="f7.5" /title="Mean Significance Level". do if (nblocks > 1). print confid /title="Percentage for the Confidence Interval:". print {confidlo,confidhi} /format="f7.5" /title="Low & High Ends of the Confidence Interval". end if. end if. compute out = { out; dyadnum, ett, obs, kappa, zkappa*sign }. compute data = {0}. compute dyadnum = alldata(#dydloop,1). end if. end loop. compute out = out(2:nrow(out),:). * The following SAVE command will save output data in an SPSS system file. You must provide legal file and directory names for your system (e.g., 'C:\output.sav'), and then "activate" the SAVE command by removing the "*" that currently makes the command a mere comment. * save out / outfile ='Hard Disk:output.sav'. print out. end matrix. * get file='Hard Disk:output.sav' / rename (col1=dyadnum) (col2=ett) (col3=obs) (col4=kappa) (col5=zkappa) / map . * descriptives var= all.