def testEmpiricalUnimodalHpd1(self): # Normal[mu=100, sd=1) v = [100.93356, 100.66576, 99.44097, 100.60761, 103.65723, 101.15563, 99.09657, 100.39654, 98.77339, 101.13712, 99.33979, 99.99060, 100.39395, 101.68240, 100.99664, 99.17798, 100.83020, 98.90373, 100.30441, 99.49553, 100.52652, 99.76291, 99.95605, 99.63605, 99.21535, 100.51619, 100.55036, 101.21747, 101.04181, 97.76084, 100.19069, 99.46182, 100.47579, 99.56889, 100.23977, 101.22907, 97.85931, 100.86051, 99.56121, 100.44109, 100.02328, 98.62446, 100.11008, 100.12700, 99.27087, 100.72895, 99.06796, 99.38019, 99.79908, 100.82761, 101.26901, 99.88911, 98.09761, 99.16706, 98.98752, 100.10088, 100.58883, 99.42982, 101.90322, 101.22817, 101.36052, 97.70629, 100.15950, 99.39458, 100.19414, 103.43317, 100.32429, 98.90429, 101.28049, 99.82948, 100.96041, 99.46024, 98.22509, 101.63878, 100.66998, 101.82238, 99.49847, 100.41055, 98.71792, 99.66001, 98.53177, 99.11997, 100.14802, 98.96423, 101.93145, 100.09478, 100.85930, 99.82181, 101.50284, 99.93301, 99.57168, 98.19978, 100.90708, 99.25086, 101.74170, 99.86034, 99.85785, 99.89154, 99.62313, 99.41994,] #==> 101.82238 97.70629 #==> 101.90322 97.76084 #==> 101.93145 97.85931 #==> 103.43317 98.09761 #==> 103.65723 98.19978 #n= 100 #nn= 5 #xx= [4.11609, 4.142380000000003, 4.0721400000000045, 5.335560000000001, 5.457449999999994] #m= 4.07214 #nnn= 100 #(97.85931, 101.93145) c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 97.85931) self.assertAlmostEqual(c2, 101.93145)
def testEmpiricalUnimodalHpd3(self): # Gamma(shape=5.5, rate=100) v = [ 0.0380707918890542, 0.0613501755118962, 0.0349990175822757, 0.0619137725677135, 0.07861308334536, 0.0480553266749484, 0.062862553519841, 0.0682992193072175, 0.0498105967259703, 0.0391473475922808, 0.0814239076471267, 0.0622768940091115, 0.0278766690168117, 0.0317487156549716, 0.0586667309884353, 0.0610901783693829, 0.0614272435233303, 0.0467353725415623, 0.0235002000890242, 0.085772673901534, 0.0556214310452847, 0.0670344572022403, 0.0544400125583679, 0.0538488966212504, 0.05294861204774, 0.0487265157882631, 0.0319744057916896, 0.0727994868817337, 0.0406117459082881, 0.0411118268978343, 0.0500761307970585, 0.0308194535724841, 0.0657552493534245, 0.100523723943228, 0.0465808929090943, 0.0460932186699443, 0.0561270845816648, 0.0600098984413655, 0.039155736440776, 0.0477087458173384, 0.0662527620357706, 0.0259218058062224, 0.0240999453565313, 0.0403149976175261, 0.0397058239610132, 0.080726331847454, 0.084357840225122, 0.0469807175107997, 0.0629060978549567, 0.0815708340371883, 0.0662480716451838, 0.0291424513010887, 0.0423492520899737, 0.0400760974537379, 0.0988931209604346, 0.0334625360347498, 0.0481980311926021, 0.0326792585090408, 0.0454491423001323, 0.020993064627905, 0.0435735408306696, 0.0408747071998941, 0.0152619235644154, 0.0749659776042904, 0.0568986969556779, 0.0238240850033704, 0.0546832244279347, 0.0793788099421741, 0.0366737460311167, 0.0122826115173667, 0.0542719395504513, 0.0426583849776426, 0.0211571623626521, 0.097984660746214, 0.0909562231889738, 0.0317473196033018, 0.0683970866878872, 0.0249627875602813, 0.081633395263259, 0.050187713841904, 0.09452301382497, 0.0832417097555666, 0.0784842034909532, 0.0329463277742707, 0.134071786835307, 0.0672633924985841, 0.0492264776710421, 0.0346193998786818, 0.0608703914888914, 0.0479141586724897, 0.0653849788769291, 0.0363831431722953, 0.0978132293790966, 0.0663011935255327, 0.0245590323775349, 0.0438722027031532, 0.0294721189654155, 0.0482169372325583, 0.0372503987850244, 0.049380448859450 ] # n= 100 # nn= 5 # P1= 0.09781323 0.09798466 0.09889312 0.1005237 0.1340718 # P2= 0.01228261 0.01526192 0.02099306 0.02115716 0.0235002 # xx= 0.08553062 0.08272274 0.07790006 0.07936656 0.1105716 # m= 0.07790006 # nnn= 3 # FINAL = 0.02099306 0.09889312 # [1] 0.02099306 0.09889312 c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 0.02099306) self.assertAlmostEqual(c2, 0.09889312)
def testEmpiricalUnimodalHpd2(self): # Exp(rate=0.2) v = [3.27592276968062, 0.471030483022332, 8.69292160732502, 5.31655522508031, 11.6689748180798, 3.74156305545426, 0.930466635618359, 4.02394197251564, 0.0273082678142286, 2.19627505168319, 11.2686246344702, 3.12780772801489, 16.3526409110966, 1.03131624741206, 4.43873460812746, 1.16054141893983, 1.37002475326881, 4.03690286425358, 2.75003841612488, 0.247246073558927, 2.97294339863583, 9.91361622656596, 1.40643152873963, 5.06202565485096, 2.56700876867399, 5.10566710939115, 8.30197051456789, 0.439280721062038, 11.3532735680448, 1.46181986900046, 11.1246174474465, 2.24797004368156, 1.79919427493587, 8.79207140509944, 4.81857897692776, 2.30751369846985, 0.589188064119702, 3.36240844568238, 9.85515167894673, 13.7341997859286, 3.04674943210557, 10.2497380129517, 15.3365677214208, 0.322058985475451, 2.13952575810254, 8.7431202231924, 9.48776975232077, 0.437449288806399, 2.91444693226367, 0.234506344422698, 2.30315598892048, 11.9319818628238, 1.30209191970236, 1.34823656175286, 25.9922393489827, 9.88916845991366, 4.32954248951232, 0.748464160133153, 1.30975685780868, 10.16635726164, 12.2592059050905, 0.469188864149385, 1.23079363489524, 40.8792947675279, 5.14233190545297, 6.33412759730077, 4.14186116397752, 0.811017339583486, 2.73471124237403, 9.42033216315222, 6.48358419050878, 3.18536503706127, 3.99172384842717, 0.936779121402651, 9.05760801355255, 5.50938969922668, 1.06717714807019, 8.42135253320348, 3.84890870635814, 0.382886157387499, 6.31485156693912, 0.300180648919195, 0.8748722959183, 1.82131360052153, 3.14994857879356, 0.281196870910665, 7.2329476564647, 2.68667792435735, 0.364864277653396, 0.757411941885948, 5.50616672241545, 4.88404127282506, 0.167293788399547, 8.03142971525326, 10.5768193447809, 14.8404745685177, 1.30770040210336, 25.8265917826642, 1.59898946760222, 4.81477369067675,] # n= 100 # nn= 5 # P1= 15.33657 16.35264 25.82659 25.99224 40.87929 # P2= 0.02730827 0.1672938 0.2345063 0.2472461 0.2811969 # xx= 15.30926 16.18535 25.59209 25.74499 40.5981 # m= 15.30926 # nnn= 1 # FINAL = 0.02730827 15.33657 # [1] 0.02730827 15.33656772 c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 0.02730827) self.assertAlmostEqual(c2, 15.33656772)
def testEmpiricalUnimodalHpd3(self): # Gamma(shape=5.5, rate=100) v = [0.0380707918890542, 0.0613501755118962, 0.0349990175822757, 0.0619137725677135, 0.07861308334536, 0.0480553266749484, 0.062862553519841, 0.0682992193072175, 0.0498105967259703, 0.0391473475922808, 0.0814239076471267, 0.0622768940091115, 0.0278766690168117, 0.0317487156549716, 0.0586667309884353, 0.0610901783693829, 0.0614272435233303, 0.0467353725415623, 0.0235002000890242, 0.085772673901534, 0.0556214310452847, 0.0670344572022403, 0.0544400125583679, 0.0538488966212504, 0.05294861204774, 0.0487265157882631, 0.0319744057916896, 0.0727994868817337, 0.0406117459082881, 0.0411118268978343, 0.0500761307970585, 0.0308194535724841, 0.0657552493534245, 0.100523723943228, 0.0465808929090943, 0.0460932186699443, 0.0561270845816648, 0.0600098984413655, 0.039155736440776, 0.0477087458173384, 0.0662527620357706, 0.0259218058062224, 0.0240999453565313, 0.0403149976175261, 0.0397058239610132, 0.080726331847454, 0.084357840225122, 0.0469807175107997, 0.0629060978549567, 0.0815708340371883, 0.0662480716451838, 0.0291424513010887, 0.0423492520899737, 0.0400760974537379, 0.0988931209604346, 0.0334625360347498, 0.0481980311926021, 0.0326792585090408, 0.0454491423001323, 0.020993064627905, 0.0435735408306696, 0.0408747071998941, 0.0152619235644154, 0.0749659776042904, 0.0568986969556779, 0.0238240850033704, 0.0546832244279347, 0.0793788099421741, 0.0366737460311167, 0.0122826115173667, 0.0542719395504513, 0.0426583849776426, 0.0211571623626521, 0.097984660746214, 0.0909562231889738, 0.0317473196033018, 0.0683970866878872, 0.0249627875602813, 0.081633395263259, 0.050187713841904, 0.09452301382497, 0.0832417097555666, 0.0784842034909532, 0.0329463277742707, 0.134071786835307, 0.0672633924985841, 0.0492264776710421, 0.0346193998786818, 0.0608703914888914, 0.0479141586724897, 0.0653849788769291, 0.0363831431722953, 0.0978132293790966, 0.0663011935255327, 0.0245590323775349, 0.0438722027031532, 0.0294721189654155, 0.0482169372325583, 0.0372503987850244, 0.049380448859450] # n= 100 # nn= 5 # P1= 0.09781323 0.09798466 0.09889312 0.1005237 0.1340718 # P2= 0.01228261 0.01526192 0.02099306 0.02115716 0.0235002 # xx= 0.08553062 0.08272274 0.07790006 0.07936656 0.1105716 # m= 0.07790006 # nnn= 3 # FINAL = 0.02099306 0.09889312 # [1] 0.02099306 0.09889312 c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 0.02099306) self.assertAlmostEqual(c2, 0.09889312)
def testEmpiricalUnimodalHpd1(self): # Normal[mu=100, sd=1) v = [ 100.93356, 100.66576, 99.44097, 100.60761, 103.65723, 101.15563, 99.09657, 100.39654, 98.77339, 101.13712, 99.33979, 99.99060, 100.39395, 101.68240, 100.99664, 99.17798, 100.83020, 98.90373, 100.30441, 99.49553, 100.52652, 99.76291, 99.95605, 99.63605, 99.21535, 100.51619, 100.55036, 101.21747, 101.04181, 97.76084, 100.19069, 99.46182, 100.47579, 99.56889, 100.23977, 101.22907, 97.85931, 100.86051, 99.56121, 100.44109, 100.02328, 98.62446, 100.11008, 100.12700, 99.27087, 100.72895, 99.06796, 99.38019, 99.79908, 100.82761, 101.26901, 99.88911, 98.09761, 99.16706, 98.98752, 100.10088, 100.58883, 99.42982, 101.90322, 101.22817, 101.36052, 97.70629, 100.15950, 99.39458, 100.19414, 103.43317, 100.32429, 98.90429, 101.28049, 99.82948, 100.96041, 99.46024, 98.22509, 101.63878, 100.66998, 101.82238, 99.49847, 100.41055, 98.71792, 99.66001, 98.53177, 99.11997, 100.14802, 98.96423, 101.93145, 100.09478, 100.85930, 99.82181, 101.50284, 99.93301, 99.57168, 98.19978, 100.90708, 99.25086, 101.74170, 99.86034, 99.85785, 99.89154, 99.62313, 99.41994, ] #==> 101.82238 97.70629 #==> 101.90322 97.76084 #==> 101.93145 97.85931 #==> 103.43317 98.09761 #==> 103.65723 98.19978 #n= 100 #nn= 5 #xx= [4.11609, 4.142380000000003, 4.0721400000000045, 5.335560000000001, 5.457449999999994] #m= 4.07214 #nnn= 100 #(97.85931, 101.93145) c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 97.85931) self.assertAlmostEqual(c2, 101.93145)
def testEmpiricalUnimodalHpd2(self): # Exp(rate=0.2) v = [ 3.27592276968062, 0.471030483022332, 8.69292160732502, 5.31655522508031, 11.6689748180798, 3.74156305545426, 0.930466635618359, 4.02394197251564, 0.0273082678142286, 2.19627505168319, 11.2686246344702, 3.12780772801489, 16.3526409110966, 1.03131624741206, 4.43873460812746, 1.16054141893983, 1.37002475326881, 4.03690286425358, 2.75003841612488, 0.247246073558927, 2.97294339863583, 9.91361622656596, 1.40643152873963, 5.06202565485096, 2.56700876867399, 5.10566710939115, 8.30197051456789, 0.439280721062038, 11.3532735680448, 1.46181986900046, 11.1246174474465, 2.24797004368156, 1.79919427493587, 8.79207140509944, 4.81857897692776, 2.30751369846985, 0.589188064119702, 3.36240844568238, 9.85515167894673, 13.7341997859286, 3.04674943210557, 10.2497380129517, 15.3365677214208, 0.322058985475451, 2.13952575810254, 8.7431202231924, 9.48776975232077, 0.437449288806399, 2.91444693226367, 0.234506344422698, 2.30315598892048, 11.9319818628238, 1.30209191970236, 1.34823656175286, 25.9922393489827, 9.88916845991366, 4.32954248951232, 0.748464160133153, 1.30975685780868, 10.16635726164, 12.2592059050905, 0.469188864149385, 1.23079363489524, 40.8792947675279, 5.14233190545297, 6.33412759730077, 4.14186116397752, 0.811017339583486, 2.73471124237403, 9.42033216315222, 6.48358419050878, 3.18536503706127, 3.99172384842717, 0.936779121402651, 9.05760801355255, 5.50938969922668, 1.06717714807019, 8.42135253320348, 3.84890870635814, 0.382886157387499, 6.31485156693912, 0.300180648919195, 0.8748722959183, 1.82131360052153, 3.14994857879356, 0.281196870910665, 7.2329476564647, 2.68667792435735, 0.364864277653396, 0.757411941885948, 5.50616672241545, 4.88404127282506, 0.167293788399547, 8.03142971525326, 10.5768193447809, 14.8404745685177, 1.30770040210336, 25.8265917826642, 1.59898946760222, 4.81477369067675, ] # n= 100 # nn= 5 # P1= 15.33657 16.35264 25.82659 25.99224 40.87929 # P2= 0.02730827 0.1672938 0.2345063 0.2472461 0.2811969 # xx= 15.30926 16.18535 25.59209 25.74499 40.5981 # m= 15.30926 # nnn= 1 # FINAL = 0.02730827 15.33657 # [1] 0.02730827 15.33656772 c1, c2 = statistics.empirical_hpd(v) self.assertAlmostEqual(c1, 0.02730827) self.assertAlmostEqual(c2, 15.33656772)