beta reg inv
Inverse of the incomplete (regularized) beta integral.
Controller: CodeCogs
Dependents
Interface
C++
Beta Reg Inv
doublebeta_reg_inv( | double | y | |
double | a | ||
double | b | ||
bool | upper = false | ||
double | eps = 1e-10 | ) |
beta_reg(x, a, b, upper) = yAn illustration of the shape of this function is:
There is an error with your graph parameters for beta_reg_inv with options y=0:1 a=3 b=2:7:3 .size=medium
The solution is computed using a good first initial prediction, followed by a number of corrections using a modified Newton solver, until the required accuracy is achieved.
This method we believe to be the fastest known method, with good accuracy down to 1e-150.
See also Maths/Special/Gamma/Beta_RegError Message:Function beta_reg_inv failed. Ensure that: Invalid C++
Example 1
- Imagine you have two types of events that cause a financial loss that are 100% correlated.
For example, the damange due to some weather event (perhaps excess rain) has been shown to damage your crop of potatoes and carrots. Although the intensity of rain experienced
by each plant type is 100% correlated (the plants are next door to each other), the damage that occurs fit different beta distributions.
Lets say the potatoes are fairly sensative to rain, with a lot of loss occuring with a small amount of rain, i.e. Potatoes. While the carrots are more resilliant, i.e. Carrots. Next assume that if all your carrots are destroyed you lose £5, while all your potatoes would lose you £2 and that you have one extreme rain event a year.
With the following code we can compute a histogram of likely losses over a million years.
#include <codecogs/maths/special/gamma/beta_reg_inv.h> #include <codecogs/statistics/random/mersenne.h> #include <codecogs/statistics/moments/frequency.h> int main(int argc, char* argv[]) { Stats::Random::Mersenne UniformGen((int)time(0)/MERSENNEDIV); Stats::Moments::Frequency bins(20,0,7); for(int i=0;i<1000000;i++) { double percentile = UniformGen.genReal(); double val = 2.0*Maths::Special::Gamma::beta_reg_inv(percentile, 0.5, 1.5, false, 1e-10) + 5.0*Maths::Special::Gamma::beta_reg_inv(percentile, 4, 2, false, 1e-10); bins.add(val); } double sum=0; for(int i=0;i<22;i++) { printf("\n%d %lf %d %lf ",i, bins.get_x(i), bins.get_count(i), bins.get_freq(i)); sum+=bins.get_x(i)*bins.get_freq(i); } printf("\n Mean Annual loss=%lf",sum); }
Output:0 -0.175000 0 0.000000 1 0.175000 127 0.000127 2 0.525000 1589 0.001589 3 0.875000 6511 0.006511 4 1.225000 15616 0.015616 5 1.575000 29847 0.029847 6 1.925000 47600 0.047600 7 2.275000 66050 0.066050 8 2.625000 81293 0.081293 9 2.975000 90582 0.090582 10 3.325000 92933 0.092933 11 3.675000 91748 0.091748 12 4.025000 87134 0.087134 13 4.375000 79734 0.079734 14 4.725000 71898 0.071898 15 5.075000 63944 0.063944 16 5.425000 54870 0.054870 17 5.775000 45694 0.045694 18 6.125000 36053 0.036053 19 6.475000 25289 0.025289 20 6.825000 11488 0.011488 21 7.175000 0 0.000000 Mean Annual loss=3.831951
Therefore you would only expect to loose you entire crop about once every ninty years (=1/0.011349) And annually you should expect to loos ~£3.83.
Parameters
y a percentile in the range 0<=y<=1 a first shape paramter, a>0 b second shape parameter, b>0 upper if true probabilites are P[X<=x], otherwise P[X>x]. Default value = false eps Level of accuracy. Default value=1e-10
Authors
- Alex Karakulov and Will Bateman
Source Code
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
Beta Reg Inv Series
doublebeta_reg_inv_series( | double | y | |
double | a | ||
double | b | ||
double | logBeta | )[inline] |
Parameters
y a percentile in the range 0<=y<=1 a first shape paramter, a>0 b second shape parameter, b>0 logBeta for performance we also compute the complete log Beta(a,b) and pass in, see logBeta.
Source Code
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.