POLI 277 MEASUREMENT THEORY
Eighth Assignment
Due 11 June 2008
#
# OC_in_R_2008.r
#
# Program to Run R Version of OC
#
#
# Remove all objects just to be safe
#
rm(list=ls(all=TRUE))
#
library(pscl)
library(oc)
#
#
sen104 <- readKH("https://legacy.voteview.com/k7ftp/sen104kh.ord",
dtl=NULL,
yea=c(1,2,3),
nay=c(4,5,6),
missing=c(7,8,9),
notInLegis=0,
desc="104th U.S. Senate",
debug=FALSE)
#
#
# Call OC
#
# Example: 1-Dim
#
#result <- oc(sen104, dims=1, polarity=c(3))
#
# Example: 2-Dim
#
result <- oc(sen104, dims=2, polarity=c(3,2))
#
# ---- Useful Commands To See What is in an Object
#
# > length(result)
# [1] 5
# > class(result)
# [1] "OCobject"
# > names(result)
# [1] "legislators" "rollcalls" "dimensions" "eigenvalues" "fits"
#
# result$legislators
# result$rollcalls
# result$dimensions
# result$eigenvalues
# result$fits
#
write.table(result$legislators,"c:/ucsd_homework_8/oc_104_x.txt")
write.table(result$rollcalls,"c:/ucsd_homework_8/oc_104_z.txt")
#
#
# idealKeith2_2008.r -- Implements Simon's IDEAL in R
#
rm(list=ls(all=TRUE))
#
library(pscl)
#
s104 <- readKH("https://legacy.voteview.com/k7ftp/sen104kh.ord",dtl=NULL,
yea=c(1,2,3),
nay=c(4,5,6),
missing=c(7,8,9),
notInLegis=0,
desc="104th U.S. Senate",
debug=FALSE)
#
# ---- Useful Commands To See What is in an Object
#
# > length(kpideal)
# [1] 9
# > class(kpideal)
# [1] "ideal"
# > names(kpideal)
# [1] "n" "m" "d" "codes" "x" "beta" "xbar"
# [8] "betabar" "call"
#
#
csts <- constrain.legis(s104,x=list("KERRY (D MA)"=c(-1,0),
"HELMS (R NC)"=c(1,0),
"NUNN (D GA)"=c(0,1)),d=2)
kpideal <- ideal(s104, d=2, priors=csts, startvals=csts, store.item=TRUE)
#
# > length(sumkpideal)
# [1] 6
# > class(sumkpideal)
# [1] "summary.ideal"
# > names(sumkpideal)
# [1] "object" "xResults" "bResults" "bSig" "party.quant"
# [6] "sort"
#
sumkpideal <- summary(kpideal,sort=FALSE,include.beta=TRUE)
#
write.table(sumkpideal$x,"c:/ucsd_homework_8/tab_simon_sen104_2x_2008.txt")
#
# Beta Parameter -- Item Discrimination Parameter for the two dimensions
#
write.table(sumkpideal$bResults[[1]],"c:/ucsd_homework_8/tab_simon_sen104_beta_1_2008.txt")
write.table(sumkpideal$bResults[[2]],"c:/ucsd_homework_8/tab_simon_sen104_beta_2_2008.txt")
#
# Alpha Parameter --
#
write.table(sumkpideal$bResults[[3]],"c:/ucsd_homework_8/tab_simon_sen104_alpha_2008.txt")
#
#
This is essentially the same syntax as the one-dimensional version used in
Question 2 of Homework 7. "Mean" "Std.Dev." "X2.5." "X97.5." "Mean.1" "Std.Dev..1" "X2.5..1" "X97.5..1" "CLINTON (D USA)" -0.309800660630002 0.0820744674618486 -0.481062906618014 -0.194230974599213 0.852141777864466 0.0888073997277851 0.679174077497147 1.03341616372539 "HEFLIN (D AL)" 0.0523260706523132 0.0101396330019580 0.0349089791158351 0.0703623150002144 0.936495397549168 0.0428951631538186 0.864716079446086 0.995326685303183 "SHELBY (R AL)" 0.481083075616966 0.0283741205452315 0.43704542284841 0.530626601279085 0.501992598599106 0.0914404650609623 0.290065360872579 0.610904536877101 "MURKOWSKI (R AK)" 0.58878180590512 0.0386327999207745 0.52191796413427 0.658790947549848 0.424465879422533 0.0857664846781842 0.212628350554421 0.531406383231817 "STEVENS (R AK)" 0.388943321757698 0.0231102557849764 0.353665898643312 0.426233254767796 0.491315913415243 0.0819189929641352 0.319929661392822 0.583706465669113 "KYL (R AZ)" 0.791543883096709 0.0441407372827541 0.726069146494467 0.900107574680152 -0.0122168904940798 0.115580586198544 -0.305988676967472 0.105848870529313 "MCCAIN (R AZ)" 0.534259782110626 0.0279878085864998 0.481143773251961 0.591158296625865 0.149750336020222 0.117870207683573 -0.136553729615176 0.270174465129845 "BUMPERS (D AR)" -0.233952706116256 0.0286250108675216 -0.285838750170946 -0.184556462964888 0.895974235997767 0.0522246794446473 0.802197799066418 0.977781191905431 "PRYOR (D AR)" -0.214233870708218 0.029386470895039 -0.267488373279433 -0.171075391402431 0.926385795765566 0.04203519069195 0.852370866716206 0.99881056858926 "BOXER (D CA)" -0.353123894266271 0.0383997665507928 -0.429059098000123 -0.279205780624982 0.886858826488446 0.0611278978741801 0.790637348731473 0.987152293328753 etc etc etc "ROBB (D VA)" -0.0765595324569559 0.0171911592586988 -0.115284324215793 -0.0515365724972953 0.826327660754874 0.0455652857584553 0.738168499289204 0.890932643723725 "WARNER (R VA)" 0.469823004481214 0.0257348240077078 0.428264833346734 0.527508326491039 0.405404853077247 0.0825355749105414 0.197365823595529 0.502348625995226 "GORTON (R WA)" 0.414595198527792 0.0282271326942752 0.374719993185643 0.478943792096745 0.523511301267852 0.0878998602440685 0.332276518438102 0.635701490946549 "MURRAY (D WA)" -0.279202231783151 0.0308639559428242 -0.338304469568743 -0.221708420250837 0.912686565540023 0.0557169694431833 0.821486525022157 0.993421496179954 "BYRD (D WV)" -0.0824692431560245 0.0202961509150374 -0.118081495310561 -0.050915738722338 0.828124439444435 0.0549633482932388 0.72624472433837 0.902889461589322 "ROCKEFELLER (D WV)" -0.194940235082881 0.0245489441150112 -0.234319401472846 -0.159662657926650 0.868099385418423 0.0467513614888446 0.782692753122446 0.932533243337904 "FEINGOLD (D WI)" -0.801050665925436 0.0583498488854194 -0.944072297378732 -0.71491362586842 0.065920377424451 0.0591633510251908 -0.0726832794968281 0.152254420418534 "KOHL (D WI)" -0.221048225268323 0.0413372987550044 -0.295063890392400 -0.148121335570306 0.590207432731952 0.0641559932713525 0.46444514456243 0.69488583944295 "SIMPSON (R WY)" 0.34389693321095 0.0212580442525637 0.306097198230730 0.387984849556693 0.471773523069905 0.0812593866561098 0.267158282326177 0.566104008894769 "THOMAS (R WY)" 0.598440926866661 0.0271559725964159 0.556507619251528 0.652790991048585 0.220152255272786 0.110697525932443 -0.0367575203267522 0.343244602415605The first and fifth columns of numbers are the Posterior Means for the first and second dimensions.
100 FORMAT(31X,2I4,28X,I1,37X,A2,3I2,411X,14I3,113X,I2,2X,5I1,28X,I1,
C 19X,I2,5I1,I2,5I1,5X,I2,5I1,I2,5I1,33X,I2,5I1,61X,I2,6X,I1,
C 120X,I2,7X,I2,687X,I1,20X,I1,63X,33I3)
The format statement I used to write the data file is: 200 FORMAT(1X,2I4,1X,I1,1X,A2,4I2,1X,14I3,1X,I2,5I1,1X,I1,1X,
C I2,5I1,I2,5I1,I2,5I1,I2,5I1,I2,5I1,1X,I2,1X,I1,1X,
C I2,1X,I2,1X,I1,1X,I1,1X,33I3)
The variables in the file are: I4 2004 Pre Case ID"
I4 2004 Post Case ID"
I1 sex (1=Man, 2=Woman)
A2 Postal abbreviation of state
I2 FIPS state code
I2 ICPSR state code
I2 South/Non-South (1=Southern State, 0=Non-Southern State)
I2 Congressional District number
I3 Feeling Thermometer: GW Bush"
I3 Feeling Thermometer: John Kerry"
I3 Feeling Thermometer: Nader"
I3 Feeling Thermometer: Cheney"
I3 Feeling Thermometer: John Edwards"
I3 Feeling Thermometer: Laura Bush"
I3 Feeling Thermometer: Hillary Clinton"
I3 Feeling Thermometer: Bill Clinton"
I3 Feeling Thermometer: Colin Powell"
I3 Feeling Thermometer: John Ashcroft"
I3 Feeling Thermometer: John McCain"
I3 Feeling Thermometer: Democratic party"
I3 Feeling Thermometer: Republican party"
I3 Feeling Thermometer: Ronald Reagan"
I2 Liberal/conservative self-placement -7-point scale"
I1 Liberal/conservative Placement - GW Bush"
I1 Liberal/conservative Placement - Kerry"
I1 Liberal/conservative Placement - Nader"
I1 Liberal/conservative Placement - Dem Party"
I1 Liberal/conservative Placement - Rep party"
I1 Party ID (0=Strong Democrat -- 6=Strong Republican) {end of first line of format statement}
I2 Spending and Services - 7-point scale self-placement" C GOVT SHOULD PROVIDE MANY FEWER SERVICES -- GOVT SHOULD PROVIDE MANY MORE SERVICES
I1 Importance of spending/services issue to R"
I1 Spending and Services Placement: GW Bush"
I1 Spending and Services Placement: Kerry"
I1 Spending and Services Placement: Dem party"
I1 Spending and Services Placement: Rep party"
I2 Defense spending - 7-point scale self-placement" C GOVT SHOULD DECREASE DEFENSE SPENDING -- GOVT SHOULD INCREASE DEFENSE SPENDING
I1 Importance of defense spending issue to R"
I1 Defense spending scale: GW Bush placement"
I1 Defense spending scale: Kerry placement"
I1 Defense spending scale: Dem party placement"
I1 Defense spending scale: Rep party placement"
I2 Job and Good Standard of Living -scale self-placement" C GOVT SHOULD SEE TO JOBS AND STANDARD OF LIVING -- GOVT SHOULD LET EACH PERSON GET AHEAD ON OWN
I1 Importance of guaranteed jobs/standard living issue"
I1 Job and Good Standard of Living - GW Bush placement"
I1 Job and Good Standard of Living - Kerry placement"
I1 Job and Good Standard of Living - Dem party placement"
I1 Job and Good Standard of Living - Rep party placement"
I2 Government assistance to blacks-7 point scale self-pl" C GOVT SHOULD HELP BLACKS -- BLACKS SHOULD HELP THEMSELVES
I1 Importance of aid to blacks issue to R"
I1 Aid to blacks Placement: GW Bush"
I1 Aid to blacks Placement: Kerry"
I1 Aid to blacks Placement: Dem party"
I1 Aid to blacks Placement: Rep party"
I2 Women's role - 7-point scale self-placement" C WOMEN AND MEN SHOULD HAVE EQUAL ROLES -- A WOMAN'S PLACE IS IN THE HOME
I1 How important is the issue of women's equal role"
I1 Women's role - GW Bush placement"
I1 Women's role - Kerry placement"
I1 Women's role - Dem party placement"
I1 Women's role - Rep party placement"
I2 Age (18 - 90, 00, 98, 99 missing)
I1 Education (1=1-8, 2=9-11, 3=HS, 4=SC, 5=2YR degree, 6=BA, 7=Advanced, 0,8,9=Missing) {end of 2nd line of format statement}
I2 Income -- 01. None or less than $2,999
02. $3,000 - $4,999
03. $5,000 - $6,999
04. $7,000 - $8,999
05. $9,000 - 10,999
06. $11,000- $12,999
07. $13,000- $14,999
08. $15,000- $16,999
09. $17,000- $19,999
10. $20,000- $21,999
11. $22,000- $24,999
12. $25,000- $29,999
13. $30,000- $34,999
14. $35,000- $39,999
15. $40,000- $44,999
16. $45,000- $49,999
17. $50,000- $59,999
18. $60,000- $69,999
19. $70,000- $79,999
20. $80,000- $89,999
21. $90,000-$104,999
22. $105,000-$119,000
23. $120,000 and over
00 and > 24 missing
I2 Race 10=Black (12,13,14,15, mixed Race)
20=Asian (23,24,25, mixed Race)
30=Native American (34,35, mixed Race)
40=Hispanic (45, mixed Race)
50=White
70=Other
88, 89, and all else missing
I1 Voted?? (1=Voter, 2=Nonvoter Registered, 3=Nonvoter not Registered)
0,4,5,6,7,8,9 Missing
I1 Who Voted For (1=Kerry, 3=Bush, 5=Nader, 7,8,9,0=Missing)
I3 Feeling Thermometer: Hispanics (Hispanic-Americans)"
I3 Feeling Thermometer: Christian Fundamentalists"
I3 Feeling Thermometer: Catholics"
I3 Feeling Thermometer: Feminists"
I3 Feeling Thermometer: Federal Government in Washington"
I3 Feeling Thermometer: Jews"
I3 Feeling Thermometer: Liberals"
I3 Feeling Thermometer - middle class people"
I3 Feeling Thermometer: Labor Unions"
I3 Feeling Thermometer: Poor people"
I3 Feeling Thermometer: The Military"
I3 Feeling Thermometer: Big Business"
I3 Feeling Thermometer: People on welfare"
I3 Feeling Thermometer: Conservatives"
I3 Feeling Thermometer: working class people"
I3 Feeling Thermometer: Older people (the elderly)"
I3 Feeling Thermometer: environmentalists"
I3 Feeling Thermometer: U.S. Supreme Court"
I3 Feeling Thermometer: Gay Men and Lesbians"
I3 Feeling Thermometer: Asian Americans"
I3 Feeling Thermometer: Congress"
I3 Feeling Thermometer: Blacks"
I3 Feeling Thermometer - Southerners"
I3 Feeling Thermometer - men"
I3 Feeling Thermometer - young people"
I3 Feeling Thermometer - illegal immigrants"
I3 Feeling Thermometer - rich people"
I3 Feeling Thermometer - women"
I3 Feeling Thermometer - business people"
I3 Feeling Thermometer - the Catholic Church"
I3 Feeling Thermometer: Whites"
I3 Feeling Thermometer: Israel"
I3 Feeling Thermometer: Muslims" {end of 3rd line of format statement}
Here is what UNFOLD_ELEC2004.CTL looks like:
ELEC2004_CLASS_2007.DAT
14 2 2 10 0 0
1 1 0 4 3
.001 -0.02 2.0 2.0 1.5 0.0 100.0
(1X,4A1,18X,14F3.0)
777888889
BUSH
KERRY
NADER
CHENEY
EDWARDS
LBUSH
HCLINTON
BCLINTON
POWELL
ASHCROFT
MCCAIN
DEMPARTY
REPPARTY
REAGAN
Run MLSMU6.EXE and get the FORT.22 file. It should
look something like this: BUSH 0.8395 0.0904 143.8029 0.7938 1206.0000
KERRY -0.8458 -0.1105 97.3078 0.7064 1191.0000
NADER 0.0661 -1.0345 113.3308 0.4341 980.0000
CHENEY 0.9213 0.1963 113.1749 0.6971 1140.0000
EDWARDS -0.7610 -0.1811 98.1149 0.6153 1050.0000
LBUSH 0.5832 0.0236 124.4988 0.5795 1163.0000
HCLINTON -0.7467 0.2587 173.7597 0.6788 1199.0000
BCLINTON -0.7000 0.2009 165.1246 0.7122 1201.0000
POWELL 0.4295 -0.0694 131.6980 0.4189 1146.0000
ASHCROFT 0.9192 0.1832 110.4639 0.5283 880.0000
MCCAIN 0.2068 -0.5522 120.2369 0.2059 952.0000
DEMPARTY -0.7143 0.0638 104.9413 0.6232 1178.0000
REPPARTY 0.8382 0.1690 99.2522 0.7099 1175.0000
REAGAN 0.4458 0.0982 167.1927 0.5139 1179.0000
1 0.3104 0.4809 2.8357 0.2346 10.0000
2 -0.3240 -0.0737 0.1357 0.8775 12.0000
3 0.4764 -0.0300 1.2478 0.6949 14.0000
4 -0.1122 0.0961 2.0479 0.1886 12.0000
5 0.9288 -0.0233 0.8175 0.9325 14.0000
6 0.0950 -0.9896 2.9318 0.4070 14.0000
7 0.6283 -0.3523 0.6773 0.8000 14.0000
8 -0.2821 -0.0468 1.9598 0.4556 14.0000
etc etc etc
1199 0.3730 0.4604 0.6818 0.6601 10.0000
1200 -0.7644 -0.1435 2.4428 0.6588 14.0000
1201 0.1755 -0.2540 1.6449 0.2266 14.0000
1202 0.4377 0.3387 1.0074 0.7127 14.0000
1203 0.2686 -0.2037 1.8730 0.4177 14.0000
1204 0.0097 0.0557 0.3978 0.7199 13.0000
1205 0.3809 0.6947 4.8357 0.3221 14.0000
1206 -0.8871 0.1691 2.4404 0.7014 14.0000
1207 -0.1712 0.5016 1.2004 0.4825 14.0000
1208 -0.8464 0.7091 1.4672 0.6645 14.0000
1209 0.1076 0.2542 2.0291 0.0559 11.0000
1210 0.5555 0.6831 1.1999 0.6638 14.0000
1211 0.7287 -0.2093 1.1761 0.8419 14.0000
1212 0.1481 -0.2675 1.0090 0.3703 11.0000
1213 0.1815 0.1990 2.0853 0.6266 14.0000
ELEC2004_CLASS_2007.DAT
DECOMPOSITION OF 2004 LIBERAL-CONSERVATIVE 7-POINT SCALE
2 5 3 Number Basic Dimensions to Estimate; Number Simuli; Number of Missing Data Values
0 8 9 Missing Data Values
(1X,I4,4X,59X,5I1) Format to Read ELEC2004_CLASS_2007.DAT
BUSH
KERRY
NADER
DEMPTY
REPPTY
BLACKBOX_TRANSPOSE produces three output files: BLACKT23.DAT shows
the statistics of the estimation including the overall fit statistics (see
"How to Use the Black Box" for an example);
BLACKT24.DAT has the n by s matrix Y of
coordinates of the stimuli on the basic dimensions with the estimation of the one-dimensional scaling
stacked on top of the two-dimensional scaling, and so on, where n is the number of stimuli;
and BLACKT28.DAT is the output
file containing the m by s matrix W of weights, and c is a vector of constants of
length m, where m is the number of respondents.BUSH -0.564 KERRY 0.389 NADER 0.317 DEMPTY 0.387 REPPTY -0.529 BUSH -0.481 0.315 KERRY 0.061 -0.510 NADER 0.796 0.394 DEMPTY -0.013 -0.582 REPPTY -0.362 0.383Combine this file with the coordinates estimated by the Aldrich-McKelvey Scaling in (4) above and place the file in STATA (reverse the coordinate signs on the first dimension(s)) and run the folowing regressions:
NES1968.DAT
DECOMPOSITION OF 1968 THERMOMETER SCALE
4 12 2
98 99
(4X,I4,925X,12I2)
GEORGE WALLACE
HUBERT HUMPHREY
RICHARD NIXON
EUGENE MCCARTHY
RONALD REAGAN
NELSON ROCKEFELLER
LYNDON JOHNSON
GEORGE ROMNEY
ROBERT KENNEDY
ED MUSKIE
SPIRO AGNEW
CURTIS LEMAY
GEORGE WAL 0.594 HUBERT HUM -0.364 RICHARD NI 0.013 EUGENE MCC -0.048 RONALD REA 0.198 NELSON ROC -0.035 LYNDON JOH -0.283 GEORGE ROM 0.058 ROBERT KEN -0.396 ED MUSKIE -0.260 SPIRO AGNE 0.140 CURTIS LEM 0.381 GEORGE WAL 0.615 -0.296 HUBERT HUM -0.329 -0.340 RICHARD NI -0.100 0.682 EUGENE MCC -0.056 0.104 RONALD REA 0.193 0.221 NELSON ROC -0.040 0.129 LYNDON JOH -0.239 -0.330 GEORGE ROM 0.075 0.019 ROBERT KEN -0.400 -0.115 ED MUSKIE -0.244 -0.136 SPIRO AGNE 0.118 0.269 CURTIS LEM 0.407 -0.207 GEORGE WAL 0.655 -0.318 0.015 HUBERT HUM -0.299 -0.386 0.032 RICHARD NI -0.016 0.373 -0.741 EUGENE MCC -0.150 0.337 0.411 RONALD REA 0.155 0.277 0.023 NELSON ROC -0.109 0.322 0.336 LYNDON JOH -0.199 -0.424 -0.081 GEORGE ROM 0.031 0.125 0.216 ROBERT KEN -0.361 -0.216 -0.215 ED MUSKIE -0.251 -0.098 0.119 SPIRO AGNE 0.131 0.182 -0.212 CURTIS LEM 0.414 -0.175 0.097 GEORGE WAL 0.728 0.050 0.206 0.144 HUBERT HUM -0.202 0.239 -0.244 0.364 RICHARD NI -0.336 -0.556 0.494 0.092 EUGENE MCC -0.018 0.238 -0.044 -0.590 RONALD REA 0.051 -0.272 -0.045 -0.161 NELSON ROC -0.111 -0.033 -0.257 -0.424 LYNDON JOH -0.156 0.097 -0.253 0.513 GEORGE ROM 0.014 -0.110 -0.263 -0.098 ROBERT KEN -0.201 0.573 0.627 -0.019 ED MUSKIE -0.186 0.154 -0.236 0.050 SPIRO AGNE -0.031 -0.354 0.044 0.043 CURTIS LEM 0.447 -0.026 -0.029 0.086Rotate the BLACKBOX_TRANSPOSE two-dimensional coordinates listed above so that they best match the Metric Scaling coordinates from homework 5 question 4 using the method shown in detail in Problem 2.g of Homework 7. Report the Pearson r-squares before and after rotating.
NES1992.DAT
DECOMPOSITION OF 15 1992 SCALES
4 15 5 8
(6X,I4,807X,I1,31X,2I1,6X,2I1,4X,I1,26X,I1,733X,I1,12X,I1,729X,I1,5X,I1,10X,I1,13X,I1,13X,I1,4X,I1)
LIBERAL/CONSERVATIVE
0 8 9
WOMENS EQUAL ROLE
0 8 9
DEFENSE SPENDING
0 8 9
GOVT JOBS/STND LIV
0 8 9
GOVT HELP BLACKS
0 8 9
GOVT PROVIDE SERVICES
0 8 9
ABORTION
0 6 7 8 9
LIBERAL/CONSERVATIVE
0 8 9
DEFENSE SPENDING
0 8 9
GOVT PROVIDE SERVICES
0 8 9
DEFENSE SPENDING
0 8 9
GOVT JOBS/STND LIV
0 8 9
ABORTION
0 6 7 8 9
URBAN UNREST
0 8 9
WOMENS EQUAL ROLE
0 8 9