def boot_mednfrac(vector, centwin=0.90, confdeg=0.90, nsamples=None, \ printns=False): """ boot_mednfrac computes symmetric confidence limits for a median-fractile estimate for confidence degree 'confdeg' using mednfrac and bootstrapping. Lower and upper limit of 1) the median, 2) the lower fractile and 3) the upper fractile for confidence degree 'confdeg'. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ assert 0.0 <= centwin and centwin <= 1.0, \ "Fractile interval must be in [0.0, 1.0] in boot_mednfrac!" assert 0.0 <= confdeg and confdeg <= 1.0, \ "Confidence degree must be in [0.0, 1.0] in boot_mednfrac!" length = len(vector) if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_mednfrac should\n" wtxt2 = "be at least 101 (101 samples will be used)" warn(wtxt1+wtxt2) median = [] lower = [] upper = [] rstream = GeneralRandomStream() for k in range(0, nsamples): bootv = [vector[rstream.runif_int0N(length)] for v in vector] med, low, upp = mednfrac(bootv, centwin) median.append(med) lower.append(low) upper.append(upp) med, lowmed, uppmed = mednfrac(median, confdeg) med, lowlow, upplow = mednfrac(lower, confdeg) med, lowupp, uppupp = mednfrac(upper, confdeg) if printns and nsamples != None: print("(number of bootstrap samples used in boot_mednfrac = " + \ str(nsamples) + ")") return lowmed, uppmed, lowlow, upplow, lowupp, uppupp
def boot_mednfrac(vector, centwin=0.90, confdeg=0.90, nsamples=None, \ printns=False): """ boot_mednfrac computes symmetric confidence limits for a median-fractile estimate for confidence degree 'confdeg' using mednfrac and bootstrapping. Lower and upper limit of 1) the median, 2) the lower fractile and 3) the upper fractile for confidence degree 'confdeg'. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ assert 0.0 <= centwin and centwin <= 1.0, \ "Fractile interval must be in [0.0, 1.0] in boot_mednfrac!" assert 0.0 <= confdeg and confdeg <= 1.0, \ "Confidence degree must be in [0.0, 1.0] in boot_mednfrac!" length = len(vector) if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_mednfrac should\n" wtxt2 = "be at least 101 (101 samples will be used)" warn(wtxt1 + wtxt2) median = [] lower = [] upper = [] rstream = GeneralRandomStream() for k in range(0, nsamples): bootv = [vector[rstream.runif_int0N(length)] for v in vector] med, low, upp = mednfrac(bootv, centwin) median.append(med) lower.append(low) upper.append(upp) med, lowmed, uppmed = mednfrac(median, confdeg) med, lowlow, upplow = mednfrac(lower, confdeg) med, lowupp, uppupp = mednfrac(upper, confdeg) if printns and nsamples != None: print("(number of bootstrap samples used in boot_mednfrac = " + \ str(nsamples) + ")") return lowmed, uppmed, lowlow, upplow, lowupp, uppupp
def boot_ratio(vnumer, vdenom, confdeg=0.90, nsamples=None, printns=False): """ boot_ratio computes symmetric confidence limits for a ratio of a sum to another sum for confidence degree 'confdeg' using bootstrapping. The sums are defined by the two input sequences (lists/'d' arrays/tuples). Lower and upper limit are returned. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ length = len(vnumer) assert len(vdenom) == length, \ "lengths of numerator and denominator must be equal in boot_ratio!" if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_ratio should be\n" wtxt2 = "at least 101 (101 samples will be used)" warn(wtxt1+wtxt2) ratio = [] rstream = GeneralRandomStream() for k in range(nsamples): sumd = 0.0 sumn = 0.0 indexv = [rstream.runif_int0N(length) for n in vnumer] for i in indexv: sumn += vnumer[i] sumd += vdenom[i] rate = sumn / float(sumd) # Safety first - input could be ranks... ratio.append(rate) median, conflow, confupp = mednfrac(ratio, confdeg) if length <= 1: confupp = conflow = None if printns and nsamples != None: print("(number of bootstrap samples used in boot_ratio = " +\ str(nsamples) + ")") return conflow, confupp
def boot_ratio(vnumer, vdenom, confdeg=0.90, nsamples=None, printns=False): """ boot_ratio computes symmetric confidence limits for a ratio of a sum to another sum for confidence degree 'confdeg' using bootstrapping. The sums are defined by the two input sequences (lists/'d' arrays/tuples). Lower and upper limit are returned. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ length = len(vnumer) assert len(vdenom) == length, \ "lengths of numerator and denominator must be equal in boot_ratio!" if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_ratio should be\n" wtxt2 = "at least 101 (101 samples will be used)" warn(wtxt1 + wtxt2) ratio = [] rstream = GeneralRandomStream() for k in range(nsamples): sumd = 0.0 sumn = 0.0 indexv = [rstream.runif_int0N(length) for n in vnumer] for i in indexv: sumn += vnumer[i] sumd += vdenom[i] rate = sumn / float(sumd) # Safety first - input could be ranks... ratio.append(rate) median, conflow, confupp = mednfrac(ratio, confdeg) if length <= 1: confupp = conflow = None if printns and nsamples != None: print("(number of bootstrap samples used in boot_ratio = " +\ str(nsamples) + ")") return conflow, confupp
def boot_aritmean(vector, confdeg=0.90, nsamples=None, printns=False): """ boot_aritmean computes symmetric confidence limits around an arithmetic mean estimate for confidence degree 'confdeg' using bootstrapping. Lower and upper limit are returned. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ assert 0.0 <= confdeg and confdeg <= 1.0, \ "Confidence degree must be in [0.0, 1.0] in boot_aritmean!" length = len(vector) if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_aritmean should\n" wtxt2 = "be at least 101 (101 samples will be used)" warn(wtxt1+wtxt2) ratio = [] rstream = GeneralRandomStream() for k in range(0, nsamples): bootv = [vector[rstream.runif_int0N(length)] for v in vector] rate = fsum(bootv) / length # Will be a float... ratio.append(rate) median, conflow, confupp = mednfrac(ratio, confdeg) if length <= 1: confupp = conflow = None if printns and nsamples != None: print("(number of bootstrap samples used in boot_aritmean = " +\ str(nsamples) + ")") return conflow, confupp
def boot_aritmean(vector, confdeg=0.90, nsamples=None, printns=False): """ boot_aritmean computes symmetric confidence limits around an arithmetic mean estimate for confidence degree 'confdeg' using bootstrapping. Lower and upper limit are returned. When the number of bootstrap samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will be used. For printns=True the number of bootstrap samples used are printed to stdout. For more general bootstrap sampling needs the methods 'bootvector' and 'bootindexvector' of the RandomStructure class may be used as a basis. """ assert 0.0 <= confdeg and confdeg <= 1.0, \ "Confidence degree must be in [0.0, 1.0] in boot_aritmean!" length = len(vector) if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1 if nsamples < 101: nsamples = 101 wtxt1 = "Number of samples in the bootstrap in boot_aritmean should\n" wtxt2 = "be at least 101 (101 samples will be used)" warn(wtxt1 + wtxt2) ratio = [] rstream = GeneralRandomStream() for k in range(0, nsamples): bootv = [vector[rstream.runif_int0N(length)] for v in vector] rate = fsum(bootv) / length # Will be a float... ratio.append(rate) median, conflow, confupp = mednfrac(ratio, confdeg) if length <= 1: confupp = conflow = None if printns and nsamples != None: print("(number of bootstrap samples used in boot_aritmean = " +\ str(nsamples) + ")") return conflow, confupp