Distribution when only quantiles are known
Imagine that you have a credible interval (0.01, 0.3) for (0.025, 0.975) probabilities for one proportion value and you would like to use this variable. The solution is to search for the beta distribution that gives this credible interval:
library("HelpersMG")
best <- fitdistrquantiles(quantiles = c(0.01, 0.3), probs=c(0.025, 0.975), scaled=FALSE, distribution = "beta")
Then it is possible to try the result:
rd10000 <- rbeta(10000, shape1 = best["shape1"], shape2 = best["shape2"])
quantile(rd10000, probs=c(0.025, 0.975))
It works !
This function can fit also more than 2 quantiles and can be used for gamma and normal distributions.
Now let do a simple exercise
Let p and q two independent proportions being known only from their confidence interval and median:
p <- c("2.5%"=0.012, "50%"=0.14, "97.5%"=0.25)
q <- c("2.5%"=0.37, "50%"=0.52, "97.5%"=0.75)
I want the confidence interval of the product p * q (it is important that p ad q are independent) :
p <- c("2.5%"=0.012, "50%"=0.14, "97.5%"=0.25)
q <- c("2.5%"=0.37, "50%"=0.52, "97.5%"=0.75)
library(HelpersMG)
beta_p <- fitdistrquantiles(quantiles = p, scaled=FALSE, distribution = "beta")
beta_q <- fitdistrquantiles(quantiles = q, scaled=FALSE, distribution = "beta")
rd10000_p <- rbeta(10000, shape1 = beta_p["shape1"], shape2 = beta_p["shape2"])
rd10000_q <- rbeta(10000, shape1 = beta_q["shape1"], shape2 = beta_q["shape2"])
quantile(rd10000_p*rd10000_q, probs = c(0.025, 0.5, 0.975))
2.5% 50% 97.5%
4.005872e-23 1.263933e-05 1.322566e-01
When the option scaled=FALSE, it used the criteria:
sum ((observed quantile - theoretical quantile) ^2)
When the option scaled=TRUE, it used the criteria:
sum (((observed quantile - theoretical quantile) ^2)/ theoretical quantile)
This option is not recommended for proportions because values close to 0 will have an exaggerated importance. It can be used rather with normal distribution.
> N <- c("2.5%"=17.2, "50%"=28.3, "97.5%"=42.7)
> library(HelpersMG)
> fitdistrquantiles(quantiles = N, scaled=FALSE, distribution = "normal")
mean sd
29.400000 6.505222
> fitdistrquantiles(quantiles = N, scaled=TRUE, distribution = "normal")
mean sd
29.361315 6.291785
By default, scaled=FALSE is selected.
Commentaires
Enregistrer un commentaire