--- myst: substitutions: titre: "computeQuantile" bloc: python: 2,3,12-21 cpp: 8-14 bloc2: python: 1-8,14-44 cpp: 4,7-35 console: python: 11-16 cpp: 13-18 --- ```{include} /../core/dataserver/statistics/quantile_computation/compute_quantile.md ``` The way $k$ is computed is discussed later on, as a parameter of the functions. The implementation and principle has slightly changed in order to be able to cope with vectors (even though the previous logic has been kept for consistency and backward compatibility). Let's start with an example of the way it was done with the two main methods whose name are the same but differ by their signature. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/dataserver/statistics/" + language + "/compute_quantile." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc[language] + "\n" + "```" }} Description of the methods and results 1. This function takes here three mandatory arguments: the attribute name, the value of the chosen probability and a double whose value will be changed in the function to the estimated result. 2. This function takes here four mandatory arguments: the attribute name, the number $N_{q}$ of calculation to be done, the values of the chosen probability transmitted as an array of size $N_{q}$ and another array of size $N_{q}$ whose value will be changed in the function to the estimated results. 3. This line shows the results of the three previous computations. This implementation has been slightly modified for two reasons: to adapt the method to the case of vectors and to store easily the results and prevent from recomputing already existing results. Even though the previous behaviour is still correct, the information is now stored in the attribute itself, as a vector of map. For every element of a vector, a map of format `map` is created: the first double is the key, meaning the value of probability provided by the user, while the second double is the results. It is now highly recommended to use the method of the `TAttribute`, that gives access to these maps for two reasons: the results provided by the methods detailed previously are only correct for the last element of a vector, and the vector of map just discussed here is cleared as soon as the general selection is modified (as for the elementary statistical-vectors discussed in [](#dataserver_statistics_computing_elementary)). The next example uses the following input file, named `aTDSWithVectors.dat`: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/references/dataserver/aTDSWithVectors.dat\n" + ":language: none\n" + "```" }} From this file, the following code (that can be find in [](#use_case_python_macro_dataserver_compute_quantile_vec) shows the different methods created in the attribute class in order for the user to get back the computed values: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/dataserver/use_cases/" + language + "/dataserverComputeQuantileVec." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc2[language] + "\n" + "```" }} Description of the methods and results 1. This method changes the value of nbquant to the number of already computed and stored values of quantiles. A second argument can be provided to state which element of the vector is concerned (if the attribute under study is a vector, the default value being 0). 2. This method changes the value of aquant to the quantile value corresponding to a given probability aproba. A second argument can be provided to state which element of the vector is concerned (if the attribute under study is a vector, the default value being 0). 3. As previously, this method changes the values of thequant to the quantile values corresponding to given probabilities stores in theproba. A second argument can be provided to state which element of the vector is concerned (if the attribute under study is a vector, the default value being 0). Warning: the size of both arrays has to be carefully set. It is recommended to use the `getQuantilesSize` method ahead of this one. 4. This method fills the provided vector allquant with the quantile value of all element of the attribute under study corresponding to a given probability aproba. The results of this example are shown below: {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/dataserver/use_cases/" + language + "/dataserverComputeQuantileVec.log\n" + ":language: none\n" + ":lines: " + console[language] + "\n" + "```" }} ```{admonition} Summary: computeQuantile - `computeQuantile`(__const char\*__ attName, **Double_t** proba, **Double_t&** quantile, **Int_t** type = 7); - `computeQuantile`(__const char\*__ attName, **Int_t** nProba, __Double_t\*__ proba, __Double_t\*__ quantile, **Int_t** type = 7); The methods are discussed above. The last parameter determines how $k$ is computed. For discontinuous cases: 1. $k=\lfloor p\times N \rfloor; \; {\rm if} \; p \times N = k,\; q = x_k. \; q=x_{k+1} \; {\rm otherwise.}$ 2. $k=\lfloor p\times N \rfloor; \; {\rm if} \; p \times N = k,\; q = 1/2 \times (x_k+x_{k+1}). \; q=x_{k+1} \; {\rm otherwise.}$ 3. $k=\lfloor p \times N - 0.5 \rfloor; \; {\rm if} \; p \times N -0.5 = k \; {\rm and} \; k \; {\rm is \; even},\; q = x_k. \; q=x_{k+1} \; {\rm otherwise.}$, default in SAS. For piece-wise linear interpolations: 4. $k=\lfloor p \times N\rfloor$ 5. $k=\lfloor p \times N - 0.5\rfloor$ 6. $k=\lfloor p \times (N + 1) \rfloor$, default in Minitab and SPSS. 7. $k=\lfloor p \times (N - 1) + 1 \rfloor$, default in ROOT, S and R. 8. $k=\lfloor p \times (N + 1/3) + 1/3 \rfloor$, approximately median unbiased. 9. $k=\lfloor p \times (N + 1/4) + 3/8 \rfloor$, approximately unbiased if $x$ is normally distributed. ```