I want to calculate a quantile of a specific distribution. Therefore I need the cdf. My distribution is a standardized Student's-t distribution, this can be written as \begin{align*} f(l|\nu) =(\pi (\nu-2))^{-\frac{1}{2}}\Gamma \left(\frac{\nu}{2} \right)^{-1} \Gamma \left(\frac{\nu+1}{2} \right) \left(1+\frac{l^2}{\nu-2} \right)^{-\frac{1+\nu}{2}} \end{align*}

This can be implemented in R with:


Where pinumber is the value for pi and param is the $\nu$. Lets say $\nu=5$. Then I can get the probability by just inserting a certain value for my l. But I want to have the cumulative density, since I later want to compute the quantile. I thought about something like


to give me the cumulative value up to 5.

But obviously this does not work. How can I get the cumulative probability and later on the quantile?

EDIT: OK, I found a first improvement:


would be a good starting point, but how to do the other thing?

  • 2
    $\begingroup$ Are you aware that R has the density, cumulative and quantile functions for a t-distribution already implemented (dt, pt and qt)? Or do you simply want to be able to do this for other distributions? $\endgroup$ – Nick Sabbe Apr 25 '13 at 15:10
  • $\begingroup$ @NickSabbe the implemented distribution is NOT the same. I use a different one and later on, I also want to do this for other distributions. (R has the standard Student's-t distribution, but not the standardized Student's-t distribution, this is a difference) $\endgroup$ – Stat Tistician Apr 25 '13 at 15:30
  • $\begingroup$ You don't need a variable to hold the value of $\pi$. In R this is built in as pi. $\endgroup$ – Glen_b -Reinstate Monica Apr 25 '13 at 23:33

CDF and quantile functions of this (extremely restrictive) distribution are straightforward to obtain in R, using that this is a Student-t distribution with a particular scale parameter:





This looks like a duplicate of your previous question: quantile transformation with t distribution (sorry, you have to use the monotonic transformation ;) )


Extending your own suggestion of using numerical integration, you can invert the function by using nonlinear equation solving. I've not tested this through, so there may be errors, but something like this should work:

dens<-function(x, nu)

cum<-function(x, nu)
    integrate(dens,-Inf,x, nu=nu)

quant<-function(p, nu)
    #maybe format the result somewhat better
    nleqslv(0, function(x){cum(x, nu)-p} )

cum(0.05, 3)

It should not be too hard to generalize this so you can pass in any density function and parameters, but there are some conditions for the integration and inversion to work. Neither can I say something on the precision (the result shows a standard error, but this does not take the error in integrating into account).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.