I thought I was wrong, but I was mistaken about that

Post date: Jun 13, 2015 12:48:9 AM

The example R script below illustrates what looks like inconsistency because the histogram (red) of a data set is not entirely within the nextvalue.nonparametric c-box (blue) for the same data set.  The inconsistency is due to the approximate nature of Monte Carlo simulations, which the free c-box software uses.  The details of the inconsistency vary when different Monte Carlo simulations are run, and the inconsistency decreases when the constant many is set to a higher value.

# THE RED HISTOGRAM SHOULD BE ENTIRELY WITHIN THE BLUE C-BOX

many = 1000  # increase for more accuracy

histogram <- function(x) x[trunc(runif(many)*length(x))+1]

nextvalue.nonparametric <- function(x) return(env(histogram(c(x, Inf)), histogram(c(x, -Inf))))

env <- function(x,y) c(x,y)

plotbox <- function(b,new=TRUE,col='blue',lwd=2,xlim=range(b[is.finite(b)]),ylim=c(0,1),xlab='',ylab='Prob',...) {

  edf <- function (x, col, lwd, ...) {

      n <- length(x)

      s <- sort(x)

      lines(c(s[[1]],s[[1]]),c(0,1/n),lwd=lwd,col=col,...)

      for (i in 2:n) lines(c(s[[i-1]],s[[i]],s[[i]]),c(i-1,i-1,i)/n,col=col,lwd=lwd,...)

      }

  b = ifelse(b==-Inf, xlim[1] - 10, b)

  b = ifelse(b==Inf, xlim[2] + 10, b)

  if (new) plot(NULL, xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab)

  if (length(b) < many) edf(b,col,lwd) else

  edf(c(min(b),max(b),b[1:min(length(b),many)]),col,lwd)

  if (many < length(b)) edf(c(min(b),max(b),b[(many+1):length(b)]),col,lwd)

  }

ef =

c(0.045469137, 0.034777044, 0.02, 0.021945104, 0.023627759, 0.02,

0.02181376, 0.02, 0.02168727, 0.023424004, 0.020684727, 0.023729972,

0.02078138, 0.021772973, 0.021850449, 0.02182746, 0.02, 0.020845971,

0.022993897, 0.022750023, 0.022641774, 0.020878047, 0.021364691,

0.022389472, 0.022037912, 0.021742971, 0.021997324, 0.039707593,

0.022608603, 0.039367754, 0.04202387, 0.042247571, 0.022032352,

0.02, 0.02, 0.02117249, 0.02, 0.02, 0.023181619, 0.022899264,

0.023960245, 0.02035322, 0.022977017, 0.02285905, 0.02, 0.02140222,

0.022045746, 0.02, 0.02, 0.02, 0.023164181, 0.02, 0.037397577,

0.024147124, 0.02, 0.02, 0.024686086, 0.035696735, 0.023965298,

0.037146275, 0.023088916, 0.023701246, 0.02, 0.027006772, 0.024566071,

0.024583555, 0.02299251, 0.025859907, 0.023038223, 0.022599406,

0.044555834, 0.027406871, 0.02, 0.02, 0.024073994, 0.024086519,

0.02081772, 0.027016804, 0.026434117, 0.025514728, 0.024369322,

0.025203264, 0.024535602, 0.028186482, 0.024829175, 0.022289089,

0.024120506, 0.024718335, 0.027059956, 0.042441219, 0.02, 0.032128256,

0.02, 0.02, 0.032948784, 0.02, 0.02, 0.023063462, 0.025188917,

0.023899146, 0.023917923, 0.02, 0.036640326, 0.024177482, 0.022801845,

0.02, 0.078869226, 0.022307934, 0.02, 0.02, 0.021853863, 0.02,

0.02, 0.021763922, 0.025081515, 0.02, 0.022785479, 0.024593651,

0.024529599, 0.02, 0.02, 0.02, 0.023149769, 0.033576765, 0.0241103,

0.02, 0.036956668, 0.022041992, 0.024557746, 0.024333639, 0.024397995,

0.03748688, 0.024016841, 0.024384148, 0.026865832, 0.02, 0.02,

0.023777382, 0.02364656, 0.037915938, 0.02, 0.023831312, 0.048190507,

0.025233409, 0.027960629, 0.024662509, 0.024497555, 0.025366611,

0.026485085, 0.020819757, 0.023827394, 0.023914177, 0.02, 0.023596704,

0.02, 0.02688172, 0.025818378, 0.049888344, 0.026245066, 0.024201824,

0.037100268, 0.029192819, 0.02, 0.02, 0.024281599, 0.024053958,

0.02, 0.02, 0.02, 0.023314915, 0.035953031, 0.030656979, 0.023196743,

0.02, 0.082748919, 0.025349587, 0.022497821, 0.024289236, 0.02,

0.023735914, 0.024357569, 0.029109221, 0.025309119, 0.025437234,

0.036831327, 0.025503698, 0.038203615, 0.027267757, 0.025025244,

0.036514874, 0.025228825, 0.025721802, 0.02, 0.027640267, 0.025056502,

0.025754875, 0.049461549, 0.02233918, 0.024581379, 0.023628917,

0.024133079, 0.044721869, 0.024514866, 0.024022855, 0.029838217,

0.021820721, 0.026276202, 0.048105949, 0.024969958, 0.046386519,

0.02, 0.052254385, 0.02, 0.02, 0.022441022, 0.021304768, 0.023016416,

0.02, 0.044996502, 0.020035061, 0.02, 0.023673402, 0.022305869,

0.02359008, 0.023407966, 0.024301632, 0.04797256, 0.048260918,

0.09809283, 0.02, 0.02, 0.025854324, 0.025801208, 0.02, 0.02,

0.02, 0.02, 0.02, 0.024261598, 0.02, 0.02, 0.024583555, 0.02,

0.02, 0.02, 0.02, 0.089865292, 0.02, 0.028920436, 0.036725887,

0.025379007, 0.023203135, 0.024760535, 0.02, 0.026238266, 0.02855556,

0.02, 0.02, 0.02535423, 0.024434748, 0.036088511, 0.031716933,

0.049877177, 0.027582935, 0.034525916, 0.027108352, 0.023308258,

0.023785738, 0.02, 0.023319944, 0.022923687, 0.072009145, 0.02364765,

0.035289177, 0.050695639, 0.025669657, 0.02, 0.024233348, 0.025140725,

0.026514649, 0.020125614, 0.033283408, 0.023341145, 0.02, 0.02,

0.03296821, 0.02, 0.035215236, 0.02, 0.034296689, 0.028294146,

0.023899831, 0.023245786, 0.042183413, 0.062955721, 0.033821891,

0.027903343, 0.02241273, 0.027646457, 0.052963963, 0.041151812,

0.027078036, 0.022692718, 0.023392948, 0.02, 0.030954961, 0.043290043,

0.024336585, 0.023703423, 0.024612083, 0.023978515, 0.022455069,

0.023312034, 0.02, 0.023735168, 0.024962556, 0.03610847, 0.023357391,

0.024943876, 0.078183638, 0.023738309, 0.050478791, 0.02, 0.02,

0.026272992, 0.079127696, 0.032763816, 0.025108926, 0.027889335,

0.026465056, 0.029577595, 0.055283744, 0.028380187, 0.025721802,

0.028258167, 0.024759447, 0.021290503, 0.02420528, 0.024802079,

0.024895625, 0.023321684, 0.107884046, 0.02, 0.024710852, 0.024431554,

0.025425205, 0.021494629, 0.02358759, 0.024199247, 0.056888452,

0.023006964, 0.039478645, 0.028072539, 0.026229766, 0.045288214,

0.027988567, 0.027594733, 0.024991253, 0.038879493, 0.037831021,

0.047340247, 0.047703779, 0.023653593, 0.024459955, 0.024604846,

0.022987237, 0.039550495, 0.022648005, 0.024215127, 0.023950561,

0.022925461, 0.02, 0.02, 0.023682106, 0.03433164, 0.024661369,

0.021830153, 0.02536021, 0.046365845, 0.036725887, 0.080372838,

0.033997763, 0.047491414, 0.114985784, 0.04572296, 0.02, 0.02,

0.036542028, 0.024414659, 0.023011517, 0.02277252, 0.02, 0.02,

0.023217155, 0.032676838, 0.021339991, 0.029047981, 0.058408417,

0.059042612, 0.02, 0.02380057, 0.035184941, 0.024010411, 0.023471782,

0.022415921, 0.044663743, 0.02, 0.02, 0.082676352, 0.021550702,

0.0241103, 0.033510754, 0.02, 0.02, 0.02, 0.026946188, 0.024618233,

0.024856871, 0.107457323, 0.022930047, 0.02817076, 0.027372363,

0.040467398, 0.027779225, 0.025436943, 0.09115978, 0.024881842,

0.024101336, 0.037793871, 0.025057287, 0.026353899, 0.044368082,

0.02, 0.038397149, 0.02, 0.02, 0.02, 0.088205645, 0.02, 0.02,

0.099223576, 0.02, 0.046300691, 0.02, 0.02, 0.02, 0.162756632,

0.072959416, 0.037864541, 0.022841428, 0.023741268, 0.022997784,

0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.049265938, 0.02,

0.021597164, 0.02, 0.023217802, 0.025278059, 0.026120027, 0.02259088,

0.025018968, 0.035142056, 0.063505611, 0.022647428, 0.033329223,

0.049808765, 0.036396724, 0.033962585, 0.025807534, 0.084081307,

0.065789474, 0.033896007, 0.022670275, 0.024739095, 0.034369478,

0.023010088, 0.035737685, 0.024154589, 0.036709282, 0.025183192,

0.02479882, 0.039210612, 0.036575642, 0.027587729, 0.025457924,

0.025912308, 0.067542011, 0.023824655, 0.021282301, 0.024635927,

0.051146317, 0.024981795, 0.025018968, 0.033733184, 0.028058361,

0.02667869, 0.026749268, 0.0373599, 0.036295401, 0.037315104,

0.024550646, 0.034392685, 0.194594174, 0.03748688, 0.023582472,

0.08942959, 0.129997173, 0.02329075, 0.023815478, 0.02, 0.02,

0.02, 0.023687365, 0.024950131, 0.142722576, 0.031127193, 0.024410234,

0.026035056, 0.028032405, 0.026191037, 0.0264381, 0.036184687,

0.02, 0.02, 0.02, 0.02342683, 0.023600212, 0.023823137, 0.02,

0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,

0.02, 0.02, 0.026214519, 0.024535753, 0.02476193, 0.02, 0.02,

0.02, 0.022109342, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,

0.024719923, 0.024213075, 0.024876086, 0.02, 0.02, 0.026509589,

0.021772452, 0.02, 0.021138878, 0.02, 0.02, 0.02, 0.02, 0.02,

0.02, 0.02, 0.024850771, 0.02, 0.024565075, 0.024227932, 0.02,

0.02, 0.023779912, 0.02, 0.024243379, 0.022849022, 0.024199232,

0.02, 0.021744567, 0.02, 0.02, 0.020223306, 0.02, 0.02, 0.024945805,

0.02, 0.020978192, 0.023586213, 0.024357094, 0.02, 0.02, 0.024441706,

0.03470487, 0.036652122, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,

0.02, 0.02, 0.02, 0.02, 0.02, 0.035545024, 0.02, 0.024676369,

0.02, 0.02, 0.02, 0.02, 0.02, 0.024534338, 0.035623636, 0.02,

0.023581708, 0.022147033, 0.022196031, 0.021616317, 0.02, 0.023112022,

0.02, 0.023843714, 0.02, 0.02, 0.02, 0.02, 0.02, 0.023836397,

0.02404229, 0.02, 0.02416063, 0.022968534, 0.022658422, 0.02,

0.02, 0.027452805, 0.035589722, 0.02, 0.025277292, 0.02, 0.02,

0.02, 0.02, 0.02, 0.023756073, 0.024844566, 0.02, 0.024404113,

0.035685737, 0.024300392, 0.02327633, 0.022423071, 0.02, 0.05,

0.034, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,

0.02, 0.02, 0.02, 0.037, 0.02, 0.022738642, 0.02, 0.02, 0.02,

0.02, 0.02, 0.02, 0.046081144, 0.024308307, 0.024632969, 0.027812543,

0.02463916, 0.023661191, 0.022127884, 0.02)

 

compare = function(ef,Many) {

  many <<- Many

  u = histogram(ef)

  w = nextvalue.nonparametric(ef)

  plotbox(u,col=2)

  title(paste('many =',many))

  plotbox(w,new=FALSE)

  }

par(mfcol=c(3,2))

compare(ef,200)

compare(ef,500)

compare(ef,1000)

compare(ef,2000)

compare(ef,10000)

compare(ef,100000)