# # basicspace_AM_L-R_2009_France_bootstrap.r # # ANALYZING SPATIAL MODELS OF CHOICE AND JUDGMENT WITH R # Dave Armstrong, Ryan Bakker, Royce Carroll, Christopher Hare, Keith T. Poole, and Howard Rosenthal # http://voteview.com/asmcjr.asp # # # Remove all objects just to be safe. rm(list=ls(all=TRUE)) # library(basicspace) # load(url("ftp://voteview.com/wf1/franceEES2009.rda")) # Ntrials <- 100 result <- vector("list", Ntrials) for(i in 1:Ntrials){ result[[i]] <- aldmck(franceEES2009[sample(1:nrow(franceEES2009), nrow(franceEES2009),replace=TRUE),],respondent=1,polarity=2, missing=c(77,88,89,99),verbose=TRUE)} original <- aldmck(franceEES2009,respondent=1,polarity=2, missing=c(77,88,89,99),verbose=TRUE) final <- matrix(NA,nrow=length(result[[1]]$stimuli),ncol=Ntrials) for(i in 1:Ntrials){ final[,i] <- result[[i]]$stimuli} boot.sd <- apply(final,1,sd) names(boot.sd) <- names(original$stimuli) boot.sd <- as.matrix(boot.sd) # out <- cbind(original$stimuli,boot.sd,(original$stimuli-boot.sd*1.96),(original$stimuli+boot.sd*1.96)) colnames(out) <- c("point","sd","lower","upper") # out <- out[order(out[,1]), ] library(lattice) dotplot(~out[,1], xlab="Location", main="Stimuli with Standard Errors", panel = function(x,y,subscripts,lower, upper){ panel.points(x,y, pch=16, col="black", cex=.5) panel.segments(out[,3], y, out[,4], y) }) #