POLS 6386 MEASUREMENT THEORY
Due 25 February 2003
# The "#" is a comment statement -- # double_center.r -- Double-Center Program that is, it tells the R compiler # that what follows on this line are # The Data Are assumed to be Squared Distances -- Data Must comments, not commands! # Be Transformed to Squared Distances Below # T This reads in the Color Matrix Data -- Note that you have to tell it how many columns! colornames Same as Homework 4 attach(colornames) Same as Homework 4 TT Copy matrix T into matrix TT nrow Counts number of rows ncol Counts number of columns xrow Initializes Vector xcol Initializes Vector matrixmean Initialize to zero # # Transform the Matrix This transforms the similarities data from a range of # 0 - 100 to a range of 0 - 4 in squared distances i Note that this loops nrow times because it starts at 0! i Increment the counter or it will loop forever! j Initialize column index to 0 while (j Note that this loops ncol times because it starts at 0! j Increment the counter or it will loop forever! TT[i,j] Here is the Transformation } } T Copy matrix TT into matrix T # # Set Row and Column Vectors to zero i These two loops simply initialize the vectors to zero while (i Set counter to zero while (i Loop over Rows i Increment the counter or it will loop forever j Set column counter to zero while (j Loop over Columns to get Row Means j Increment the counter or it will loop forever xrow[i] Add up elements in the row (add across columns) matrixmean This gives us the matrix mean TT[i,j] Initialize matrix TT to zero } } # Compute Column Means j Set counter to zero while (j Loop over Columns j Increment the counter or it will loop forever i Set row counter to zero while (i Loop over Rows to get Column Means i Increment the counter or it will loop forever xcol[j] Add up elements in the column (add across rows) } } # Double-Center the Matrix This Double-Centers the Matrix i Set counter to zero while (i Loop over Rows i Increment the counter or it will loop forever j Set column counter to zero while (j Loop over Columns j Increment the counter or it will loop forever TT[i,j] TT is the Double-Centered Matrix } } End of Double-Center Code ev Compute the Eigenvalues and Eigenvectors DIMNEW.1 Put the First Eigenvector in DIMNEW.1 DIMNEW.2 Put the Second Eigenvector in DIMNEW.2 plot(DIMNEW.1,DIMNEW.2,type="n",main="The Color Circle From Double Centering", xlab="First Dimension",ylab="Second Dimension", xlim=c(-1.0,1.0),ylim=c(-1.0,1.0)) Plot Commands text(DIMNEW.1,DIMNEW.2,labels=row.names(colornames),adj=0)Download the R program and two example files below and place them in the same directory on your disk. Note that you will have to use Epsilon to change the path statements in double_center.r.
 7.928536e+00 5.197332e+00 1.763696e+00 1.495726e+00 6.338461e-01  4.120299e-01 1.660689e-01 1.266656e-01 7.386280e-02 1.666023e-02  5.380350e-03 9.296853e-15 1.069314e-01 1.897294e-01These are the eigenvalues of the double-centered matrix (technically, the absolute values of the eigenvalues). Paste these into Excel and make a plot like that shown in Home Work Number 3, problem 2.b. Turn in this plot with the appropriate title (e.g., "Eigenvalues of Double-Centered Color Data").
idno respondent id number partyid strength of party id -- 0 to 6 income raw income category incomeq income quintile -- 1 to 5 race 0 = white, 1 = black sex 0 = man, 1 = woman south 0 = north, 1 = south education 1=HS, 2=SC, 3=College age age in years uulbj lbj position urban unrest uuhhh humphrey pos urban unrest uunixon nixon position urban unrest uuwallace wallace pos urban unrest uuself self placement urban unrest vnmlbj lbj pos vietnam vnmhhh hhh pos vietnam vnmnixon nixon pos vietnam vnmwallace wallace pos vietnam vnmself self placement vietnam voted 1=voted, 5=did not vote votedfor who voted for -- 1 = humphrey, 2= nixon, 3=wallace wallace wallace therm humphrey humphrey thermometer nixon nixon thermometer mccarthy mccarthy thermometer reagan reagan thermometer rockefeller rockefeller thermometer lbj lbj thermometer romney romney thermometer kennedy robert kennedy thermometer muskie muskie thermometer agnew agnew thermometer lemay "bombs away with Curtis LeMay" thermometer
TT If T[i,j] = 98 or 99 set TT[i,j] = NA (missing data) else if set TT[i,j] = T[i,j]To compute the correlation matrix use the command:
[,1] [,2] [,3] ....etc [1,] 1.00000000 -0.3108400 0.01690949 ....etc .... etc etc etc ...You need this correlation matrix to duplicate what Weisberg and Rusk did with KYST. Use Epsilon to copy the correlation matrix into your KYST control card file. Note that you will have to reassemble the matrix using Epsilon and note that because of the pecularities of R, the second column of the matrix has one less digit than the other columns!!! You will have to stick a zero at the end of each correlation in the second column to get everything to work. Your KYST control card file should look something like this:
TORSCA PRE-ITERATIONS=3 DIMMAX=3,DIMMIN=1 PRINT HISTORY,PRINT DISTANCES COORDINATES=ROTATE ITERATIONS=50 REGRESSION=DESCENDING DATA,LOWERHALFMATRIX,DIAGONAL=PRESENT,CUTOFF=-2.00 1968 FEELING THERMOMETER CORRELATION MATRIX 12 1 1 (14X,12F12.8) Wallace 1.00000000 -0.31084000 0.01690949 ... etc etc ...etc etc ... COMPUTE STOPReport the Stress Values for 1, 2, and 3 dimensions and use R to graph the results in two dimensions.