#' plotExpectedUtilityDecCostTotalUtil
#'
#' Plots the Total Cost, Decision Cost and Expected Utility 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
#' @param plotMeanEU if TRUE plot the costs for the Mean Group
#' @param plotBestEU if TRUE plot the costs for the Best Group
#' @param plotWorstEU if TRUE plot the costs for the Worst Group
#' @return A plot of the mean, across all iterations, of the decision cost, expected utility and total cost incurred for each k-majority rule.
#' @export
plotExpectedUtilityDecCostTotalUtil <- function(outputDataList,plotMeanEU,plotBestEU,plotWorstEU){
#Extract Expected Utility
meanExpectedUtility <- outputDataList$expectedUtility$meanOfMeanVotersExpectedUtilityEachIteration
bestExpectedUtility <- outputDataList$expectedUtility$meanOfbestOffGroupsMeanExpectedUtilityEachIteration
worstExpectedUtility <- outputDataList$expectedUtility$meanOfworstOffGroupsMeanExpectedUtilityEachIteration
# Calculate Decision Cost
decisionCost <- outputDataList$rounds$meanNumberOfProposalsConsideredEachIteration * outputDataList$theInputParameters$perProposalDecisionCost
# Calculate Total Cost for Mean, Highest and Lowest groups
meanTotalCost <- meanExpectedUtility - decisionCost
bestTotalCost <- bestExpectedUtility - decisionCost
worstTotalCost <- worstExpectedUtility - decisionCost
# Store a few parameters for use in plots
parameters <- outputDataList$theInputParameters
numK <- nrow(outputDataList$expectedUtility)
K <- seq(1:numK)
xTicks <- floor(numK/10)
# PLOTS
xRange <- c(0,numK)
yRange <- c(-1,1)
x_axislabels <- seq(0,numK,by=10)
y_axislabels <- seq(-1,1,by=.1)
plot(xRange, yRange, type="n", main="", xlab="K-Majority Rule", ylab="Expected Utility", ylim=c(-1,1), font=2, axes=FALSE, frame=TRUE)
axis(side=1, at=x_axislabels)
axis(side=2, at=y_axislabels)
lines(K,decisionCost,lty=1,lwd=3,col='black')
lineNames <- c("decision costs") # For the Legend
lineLty <- c(1) # For the Legend
lineLwd <- c(3) # For the Legend
lineCol <- c("black")
if (plotMeanEU==TRUE){
lines(K,meanExpectedUtility,lty=1,lwd=1,col='black')
lines(K,meanTotalCost,lty=2,lwd=3,col='black')
lineNames <- c(lineNames, "mean group e.u.", "mean group t.u.")
lineLty <- c(lineLty,1,2) # For the Legend
lineLwd <- c(lineLwd,1,3) # For the Legend
lineCol <- c(lineCol,"black")
}
if (plotBestEU==TRUE){
lines(K,bestExpectedUtility,lty=1,lwd=1,col='black')
lines(K,bestTotalCost,lty=2,lwd=3,col='black')
lineNames <- c(lineNames, "best group e.u.", "best group e.u.")
lineLty <- c(lineLty,1,2) # For the Legend
lineLwd <- c(lineLwd,1,3) # For the Legend
lineCol <- c(lineCol,"black")
}
if (plotWorstEU==TRUE){
lines(K,worstExpectedUtility,lty=1,lwd=1,col='black')
lines(K,worstTotalCost,lty=2,lwd=3,col='black')
lineNames <- c(lineNames, "worst group e.u.", "worst group t.u.")
lineLty <- c(lineLty,1,2) # For the Legend
lineLwd <- c(lineLwd,1,3) # For the Legend
lineCol <- c(lineCol,"black")
}
mtext(text=paste("Group Size:", paste(outputDataList$theInputParameters$groupSize, collapse=", ")),
side=3,
line=1.50,
adj=0,
cex=1.1,
font=2)
mtext(text=paste("Initial Utility:", paste(
toupper(
substring(
outputDataList$allGroups[[1]]$utilityDistribution,1,1)),
"(",
sub('^(-)?0[.]', '\\1.', outputDataList$allGroups[[1]]$utilityDistributionParam1),
",",
sub('^(-)?0[.]', '\\1.',outputDataList$allGroups[[1]]$utilityDistributionParam2),
")",
collapse=", ", sep="")),
side=3,
line=1.50,
adj=1,
cex=1.1,
font=2)
mtext(text=paste("Group Error:", paste(
toupper(
substring(
outputDataList$allGroups[[1]]$errorDistribution,1,1)),
"(",
sub('^(-)?0[.]', '\\1.', outputDataList$allGroups[[1]]$errorDistributionParam1),
",",
sub('^(-)?0[.]', '\\1.',outputDataList$allGroups[[1]]$errorDistributionParam2),
")",
collapse=", ", sep="")),
side=3,
line=.25,
adj=0,
cex=1.1,
font=2)
mtext(text=paste("Change Mean Utility:", paste(outputDataList$theInputParameters$groupPostFailingProposalMeanUiIncrease, collapse=", ")),
side=3,
line=.25,
adj=1,
cex=1.1,
font=2)
mtext(text=paste("Per Round Decision Cost:", paste(outputDataList$theInputParameters$perProposalDecisionCost, collapse=", ")),
side=1,
line=2.00,
adj=0,
cex=1.1,
font=2)
legend(5,1, # places a legend at the appropriate place
lineNames, # puts text in the legend
lty=lineLty, # gives the legend appropriate symbols (lines)
lwd=lineLwd, # gives the legend the appropriate weight
col=lineCol # gives the legend the appropriate color
) #
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.