# # # # basicspace_AM.r -- Does Aldrich-McKelvey Scaling of 1968 Urban Unrest # 7-Point Scale # # &&&&&&&&& STIMULI &&&&&&&& # # 1968 7-POINT URBAN UNREST SCALE # # VAR00460 LOC 907 WIDTH 1 PBM URBAN UNREST-JHNSN # VAR00461 LOC 908 WIDTH 1 PBM URBAN UNREST-HHH # VAR00462 LOC 909 WIDTH 1 PBM URBAN UNREST-NIXON # VAR00463 LOC 910 WIDTH 1 PBM URBAN UNREST-WALLA # VAR00464 LOC 911 WIDTH 1 PBM URBAN UNREST-R # CAND(1)= 'LYNDON JOHNSON ' # CAND(2)= 'HUBERT HUMPHREY ' # CAND(3)= 'RICHARD NIXON ' # CAND(4)= 'GEORGE WALLACE ' # CAND(5)= 'INDIVIDUAL ' # rm(list=ls(all=TRUE)) # library(MASS) library(foreign) library(basicspace) setwd("C:/uga_course_homework_2_2015") data <- read.dta("nes1968_first_11.dta") attach(data,warn.conflicts = FALSE) # T <- cbind(VAR00460,VAR00461,VAR00462,VAR00463,VAR00464) TT <- T mode(TT) <- "double" colnames(TT) <- c("Johnson","Humphrey","Nixon","Wallace","Self") VOTE <- cbind(VAR00316) # 11. VOTED FOR HUBERT HUMPHREY # 23. VOTED FOR RICHARD NIXON # 34. VOTED FOR GEORGE WALLACE # # Note that polarity=1 selects Lyndon Johnson -- The Respondent Self Placement # is in the last column -- respondent=5 # result <- aldmck(TT,polarity=1,respondent=5,missing=c(0,8,9),verbose=TRUE) # # # ---- Useful Commands To See What is in an Object # # > length(result) # [1] 8 # > class(result) # [1] "aldmck" # > names(result) # [1] "stimuli" "respondents" "eigenvalues" "AMfit" "R2" # [6] "N" "N.neg" "N.pos" # # > names(result$respondents) # [1] "intercept" "weight" "idealpt" "R2" "selfplace" "polinfo" # # > summary(result) -- shows everything # > plot(result) -- shows basic graphs of the results # windows() plot(result) idealpoints1 <- ifelse(is.na(result$respondents$weight),99,result$respondents$weight) idealpoints2 <- ifelse(is.na(result$respondents$idealpt),99,result$respondents$idealpt) humphrey.voters <- result$respondents$idealpt[idealpoints1>0 & idealpoints2!=99 & VOTE==11] nixon.voters <- result$respondents$idealpt[idealpoints1>0 & idealpoints2!=99 & VOTE==23] wallace.voters <- result$respondents$idealpt[idealpoints1>0 & idealpoints2!=99 & VOTE==34] humphreyShare <- length(humphrey.voters)/(length(humphrey.voters)+length(nixon.voters)+length(wallace.voters)) nixonShare <- length(nixon.voters)/(length(humphrey.voters)+length(nixon.voters)+length(wallace.voters)) wallaceShare <- length(wallace.voters)/(length(humphrey.voters)+length(nixon.voters)+length(wallace.voters)) humphreydens <- density(humphrey.voters) humphreydens$y <- humphreydens$y*humphreyShare nixondens <- density(nixon.voters) nixondens$y <- nixondens$y*nixonShare wallacedens <- density(wallace.voters) wallacedens$y <- wallacedens$y*wallaceShare # ymax1 <- max(humphreydens$y) ymax2 <- max(nixondens$y) ymax3 <- max(wallacedens$y) ymax <- 1.1*max(ymax1,ymax2,ymax3) # windows() # # plot(humphreydens,xlab="",ylab="", main="", xlim=c(-2.0,2.0),ylim=c(0,ymax),type="l",lwd=3,col="red",font=2) lines(humphreydens,lwd=3,col="red") lines(nixondens,lwd=3,col="blue") lines(wallacedens,lwd=3,col="green") # # Main title mtext("Aldrich-McKelvey Scaling 1968 Urban Unrest Scale\nHumphrey (red), Nixon (blue), Wallace (green)",side=3,line=1.50,cex=1.2,font=2) # x-axis title mtext("Liberal - Conservative",side=1,line=2.75,cex=1.2) # y-axis title mtext("Density",side=2,line=2.5,cex=1.2) # text(-1.5,ymax,paste("Humphrey Voters ", 100.0*round(humphreyShare, 3),"%"),col="red",font=2) text(-1.5,0.9*ymax,paste("N = ", 1.0*round(length(humphrey.voters), 7)),col="red",font=2) text( 1.5,ymax,paste("Nixon Voters ", 100.0*round(nixonShare, 3),"%"),col="blue",font=2) text( 1.5,0.9*ymax,paste("N = ", 1.0*round(length(nixon.voters), 7)),col="blue",font=2) text( 1.5,0.8*ymax,paste("Wallace Voters ", 100.0*round(wallaceShare, 3),"%"),col="green",font=2) text( 1.5,0.7*ymax,paste("N = ", 1.0*round(length(wallace.voters), 7)),col="green",font=2) # # arrows(result$stimuli[2], 0.05,result$stimuli[2],0.0,length=0.1,lwd=3,col="red4") text(result$stimuli[2],.075,"Humphrey",col="red4",font=2) arrows(result$stimuli[3], 0.05,result$stimuli[3],0.0,length=0.1,lwd=3,col="blue4") text(result$stimuli[3],.075,"Nixon",col="blue4",font=2) arrows(result$stimuli[4], 0.05,result$stimuli[4],0.0,length=0.1,lwd=3,col="green4") text(result$stimuli[4],.10,"Wallace",col="green4",font=2) # # detach(data)