0

A mixed distribution where cumulative probability distribution function (CDF) is given by

G(x)= (1-p)H(x)+pF(x)

where, p=0.2 (assumed in this case as it ranges from 0-1),
H(x)= 0 when x=0 else 1, and
F(x) is a two-parameter gamma distribution.
How can I get quantiles for y =c(0.2,0.5,1) for a given gamma parameters say shape=3.5 and scale=1.5 ?

Note: I triedqgamma(y, shape, rate=scale, lower.tail = TRUE,log.p = FALSE) for gamma distributions only but I am not able to incorporate for the first term in the given CDF.

b_takhel
  • 1
  • 1
  • 1
    If $H(x)$ is a CDF, do you mean it is $0$ when $x < 0$ and $1$ otherwise? It has to be càdlàg – Henry May 06 '21 at 01:45

1 Answers1

2

Your distribution has probability $1-p$ of being $0$ and probability $p$ of following the gamma distribution (so positive)

so you could set up the CDF and its inverse as

pG <- function(x, p, scale, shape){
  ifelse(x < 0, 0, 1-p + p * pgamma(x, shape=shape, scale=scale))
  }
qG <- function(x, p, scale, shape){
  ifelse(x >= 0 & x <= 1-p, 0, qgamma(1-(1-x)/p, shape=shape, scale=scale))
  }

and your particular example gives the unhelpful but correct

qG(c(0.2, 0.5, 1), p=0.2, shape=3.5, scale=1.5) 
#   0   0 Inf 

plus a warning you could suppress. It might be better to think about something like

qG(c(0.2, 0.5, 0.9), p=0.75, shape=3.5, scale=1.5) 
# 0.000000 3.708802 8.342423
pG(c(0.000000, 3.708802, 8.342423), p=0.75, shape=3.5, scale=1.5) 
# 0.25 0.50 0.90

and why the first term from pG() is not 0.2

Henry
  • 30,848
  • 1
  • 63
  • 107
  • Thank you so much @henry, If I estimate pG first then qG results are fine.i.e. ```pp=pG(c(0.2,3.790746, 8.342423), p=0.75, shape=3.5, scale=1.5) qG(pp, p=0.75, shape=3.5, scale=1.5)```. However, as you have mentioned pG for 0.2 comes with 0.25 which is true for all x <1-p making the result wrong. I'm not sure whether I can assume 0 for x<1-p. – b_takhel May 06 '21 at 21:31
  • @b_takhel "assume" is the wrong word. If $p=0.75$ then $pG(0)=1-p=0.25$. It does not matter how you got the $0$. These things always happen with discrete distributions or the discrete parts of distributions. Try for example `qpois(0.3,4)` giving `3` but `ppois(3,4)` giving `0.4334701` rather than `0.3` – Henry May 06 '21 at 23:33