:78 Function create_function() is deprecated [8192]

adding more features to the plotting fn: convergence line and histogram

Marcelo Ponce [2018-10-18 16:09:04]
adding more features to the plotting fn: convergence line and histogram
Filename
plottingTools.R
diff --git a/plottingTools.R b/plottingTools.R
index 02603b0..264af76 100644
--- a/plottingTools.R
+++ b/plottingTools.R
@@ -6,12 +6,40 @@
 # containing the sample sizes and probabilities values

 # function to generate a semi-log plot of two vectors with connecting lines
-plotMC <- function(NS,probs) {
+plotMC <- function(NS,probs, wHist=T) {
+	# obtain lenght of vectors
+	lNS <- length(NS)
+	lprobs <- length(probs)
+
 	# check that the arguments have matching dimensions
-	if (length(NS)!=length(probs)) {
-		stop("The function requires two vectors with the same number of eleemnts!")
+	if (lNS != lprobs) {
+		stop("This function requires two vectors with the same number of elements!")
 	}

+	# set up figure canvas
+	par(fig = c(0,1,0,1))
+
 	# semi-log plot of probs vs NS with connecting lines
 	plot(log(NS),probs,'b')
+
+	# determine values to consider for computing convergent prob.
+	i0 <- 2*lprobs/3
+	i1 <- lprobs
+	convP <- mean(probs[i0:i1])
+	# add line to display convergent value of P
+	abline(v=0,h=convP, col='red', lw=2, lt=2)
+
+	# add inset figure with a histogram
+	if (wHist) {
+		# figure out where to place inset
+		if ( (convP-probs[1]) < 0 ) {
+			# mean below 1st value, inset above
+			par(fig = c(0.47,1, 0.5, 1), new = T)
+		} else {
+			# mean above 1st value, inset below
+			par(fig = c(0.47,1, 0.07, 0.5), new = T)
+			}
+		hist(probs, col='grey')
+	}
+
 }
ViewGit