/* this program simulates a simple peer influence model on two dimensions. It starts with a random distribution of oppinions, and each person changes their oppinion as a weighted function of their own oppinion and the other people's oppinion. User inputs the network, the relative size of the self weight, and the number of itterations. modified to have alpha be a distribution across actors Author: Moody Date: Feb 23, 2000 */ proc iml; %include 'c:\moody\sas\programs\modules\rangrp.mod'; %include 'c:\moody\sas\programs\modules\pajwrite.mod'; %include 'c:\moody\sas\programs\modules\pajpart.mod'; %include 'c:\moody\sas\programs\modules\pajwrtc.mod'; blk={.08 .005 .005, .005 .08 .005, .005 .005 .08}; grpsz={25, 25, 25}; net=rangrp(blk,grpsz); grp=net[,1]; net=net[,2:ncol(net)]; net=(net+net`)>0; mattrib net format=1.0; *print net; op=j(nrow(net),2,0); op=rannor(op); /* two vector oppinion set */ print op; maxop=abs(op); maxop=maxop[<>,]; do i=1 to ncol(op); op[,i]=op[,i]/maxop[i]; end; print op; start peerinf(y,w,alpha,n); opstk1=y[,1]; opstk2=y[,2]; do i=1 to n; op_i=alpha#(w*y)+(1-alpha)#y; opstk1=opstk1||op_i[,1]; opstk2=opstk2||op_i[,2]; y=op_i; end; return(opstk1||opstk2); finish; samegrp=j(nrow(net),ncol(net),0); do i=1 to nrow(samegrp); do j=1 to nrow(samegrp); samegrp[i,j]=(grp[i]=grp[j]); end; end; grpwt=5; netv=choose(net=1&samegrp=1,net*grpwt,net); /* increase within group ties by grpwt */ *mattrib netv format=1.0; *print netv; netw=netv+(3*i(nrow(net))); do i=1 to nrow(net); netw[i,]=netw[i,]/netw[i,+]; end; netw=choose(netw=.,0,netw); al=j(nrow(netw),1,.7); al[{1 2},]=.1; al[{26 27},]=.1; al[{51 52},]=.1; op[{1 2},]={.8 .8, .75 .75}; op[{26 27},]={-.8 -.8, -.75 -.75}; op[{51 52},]={.8 -.8, .75 -.75}; grp[{1 2}]=4; grp[{26 27}]=5; grp[{51 52}]=6; opvars=peerinf(op,netw,al,7); opset=grp||opvars; create outd from opset [colname={grp x0 x1 x2 x3 x4 x5 x6 x7 y0 y1 y2 y3 y4 y5 y6 y7}]; append from opset; id=1:nrow(net); id=id`; file 'c:\moody\classes\soc884\examples\peerinf1.net'; call pajwrite(net,id,2); file 'c:\moody\classes\soc884\examples\peerinf1.clu'; call pajpart(grp); %macro opwrite(net,x,y,grp); i=1; j=9; %do i=0 %to 7; /* normalize the vectors so pajak can plot them */ xv=opvars[,i]; yv=opvars[,j]; /* make positive */ xvmin=xv[><]; yvmin=yv[><]; print xvmin yvmin; xv=xv+(abs(xvmin)+.1); yv=yv+(abs(yvmin)+.1); /* put between zero and 1 */ yv=yv/yv[<>]; xv=xv/xv[<>]; print "&i" yv xv; call pgraf(yv||xv); call pgraf(yv||opvars[,j]); call pgraf(xv||opvars[,i]); file "c:\moody\classes\soc884\examples\pinf&i..net"; call pajwrtc(net,id,2,yv,xv); i=i+1; j=j+1; %end; %mend; %opwrite; quit; symbol1 value=circle height=2; proc gplot data=outd; plot y0*x0=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y1*x1=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y2*x2=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y3*x3=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y4*x4=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y5*x5=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y6*x6=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; plot y7*x7=grp /haxis = -1 to 1 by .2 vaxis = -1 to 1 by .2; run; proc means data=outd; run; proc print; var grp y0 x0; run;