R/plotOnlyExternalCost.R

#' plotOnlyExternalCost
#' 
#' Plots the welfare loss measures for the voters of interest, in the round the proposal passed, for each of the kMajority rules.
#' @param outputDataList The output data list of summaries, that is generated by the iterations() function
#' @return A plot of the mean, across all iterations, of the external cost incurred for each k-majority rule.
#'  @export
plotOnlyExternalCost <- function(outputDataList){
  x_axislabels <- seq(0,nrow(outputDataList$externalCost),by=10) 
  y_axislabels <- seq(0,1,by=.1)
  numberOfKMajorities <- nrow(outputDataList$externalCost)
  xRange <- range(c(1:numberOfKMajorities))
  yRange <- c(0,1)
  plot(xRange, yRange, type="n", xlab="k-majority", ylab="External Cost", axes=FALSE, frame=TRUE)
  axis(side=1, at=x_axislabels)
  axis(side=2, at=y_axislabels)
  lines(c(1:numberOfKMajorities),outputDataList$externalCost$meanOfMeanVotersExternalCostEachIteration, col = "Black", lwd = 2, lty = "solid")
  lines(c(1:numberOfKMajorities),outputDataList$externalCost$meanOfworstOffGroupsMeanExternalCostEachIteration, col = "Black", lwd = 2, lty = "dotted")
  lines(c(1:numberOfKMajorities),outputDataList$externalCost$meanOfbestOffGroupsMeanExternalCostEachIteration, col = "Black", lwd = 2, lty = "dotdash")
  mtext(text=paste("Group Sizes:", paste(outputDataList$theInputParameters$groupSize, collapse=", ")),side=3,line=2.540,cex=.8,font=1)
  mtext(text=paste("Utility:", paste(toupper(substring(outputDataList$allGroups[[1]]$utilityDistribution,1,1)),"(",outputDataList$allGroups[[1]]$utilityDistributionParam1,",",outputDataList$allGroups[[1]]$utilityDistributionParam2,")", collapse=", ", sep="")),side=3,line=1.50,cex=.8,font=1)
  mtext(text=paste("Error:", paste(toupper(substring(outputDataList$allGroups[[1]]$errorDistribution,1,1)),"(",outputDataList$allGroups[[1]]$errorDistributionParam1,",",outputDataList$allGroups[[1]]$errorDistributionParam2,")", collapse=", ", sep="")),side=3,line=.5,cex=.8,font=1)
  legend(70,1, # places a legend at the appropriate place 
         c("Mean Voter","Worst Group", "Best Group"), # puts text in the legend 
         lty=c("solid", "dotted", "dotdash"), # gives the legend appropriate symbols (lines)
         lwd=c(2,2,2),col=c("Black","Black","Black")) # gives the legend lines the correct color and width
}
codeForReviewer/kMajorityRule documentation built on May 13, 2019, 8:47 p.m.