# # # normal_2.r -- Test of Shepard_Ennis_Nofosky model of Stimulus # Comparison # # Exemplars have bivariate normal distributions. One point is # drawn from each distribution and the distance computed. # This distance is then exponentiated -- exp(-d) -- and # this process is repeated m times to get a E[exp(-d)]. # # Note that when STDDEVX is set very low then this is equivalent # to a legislator's ideal point so that the stimulus comparison # is between the ideal point and the momentary draw from the # Exemplar distribution. # # Set Means and Standard Deviations of Two Bivariate Normal Distributions # # Remove all objects just to be safe # rm(list=ls(all=TRUE)) # STDDEVX <- .001 STDDEVY <- .4 XMEAN <- 0 YMEAN <- 0 # # Set Number of Draws to Get Expected Value # m <- 10000 # # Set Number of Points # n <- 40 # # Set Increment for Distance Between Two Bivariate Normal Distributions # XINC <- 0.05 # x <- NULL y <- NULL z <- NULL xdotval <- NULL ydotval <- NULL zdotval <- NULL iii <- 0 while (iii <= n) { x <- 0 i <- 0 iii <- iii + 1 while (i <= m) { # # Draw points from the two bivariate normal distributions # xdotval <- c(rnorm(2,XMEAN,STDDEVX)) ydotval <- c(rnorm(2,YMEAN,STDDEVY)) # # Compute distance Between two randomly drawn points # zdotval <- sqrt((xdotval[1]-ydotval[1])**2 + (xdotval[2]-ydotval[2])**2) # # Exponentiate the distance # zdotval <- exp(-zdotval) # # Compute Expected Value # x <- x + zdotval/m i <- i + 1 } # # Store Expected Value and Distance Between Means of Two Distributions # y[iii] <- x z[iii] <- sqrt(2*YMEAN^2) YMEAN <- YMEAN + XINC } # # The type="n" tells R to not display anything # plot(z,y,xlim=c(0,3),ylim=c(0,.7),type="n", main="", xlab="", ylab="",font=2) # # Another Way of Doing the Title # #title(main="Test of Shepard-Ennis-Nofosky, .001, .4\nTest of Ideal Point vs. Outcome Model") # Main title mtext("Test of Shepard-Ennis-Nofosky, .001, .4\nTest of Ideal Point vs. Outcome Model",side=3,line=1.00,cex=1.2,font=2) # x-axis title mtext("True Distance Between Stimuli",side=1,line=2.75,font=2,cex=1.2) # y-axis title mtext("Expected Value of Observed Similarity",side=2,line=2.75,font=2,cex=1.2) ## # An Alternative Way to Plot the Points and the Lines # points(z,y,pch=16,col="blue",font=2) lines(z,y,lty=1,lwd=2,font=2,col="red")