Dear All,
Apologies for not providing a reproducible example, but if I could, then I would be able to answer myself my question. Essentially, I am trying to fit a very complicated custom probability distribution to some data. Fitdistrplus does in principle everything which I need, but if require me to specify not only the density function d, but also the cumulative p and and inverse cumulative function q (see for instance http://www.stat.umn.edu/geyer/old/5101/rlook.html to understand what these quantities are in the case of a normal distribution). The analytical calculation of p and q is a big task in my case, so my question is if there is a workaround for this, i.e. a way to fit the unknown parameters of my probability distribution without specifying (at least analytically) p and q, but only the density d. Many thanks Lorenzo [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Why not define your own functions based on d?
e.g. myCumDist <- function(x) { integrate(d, lower=-Inf, upper=x)$value } myQuantile <- function(x) { uniroot(f=function(y) { h(y) - x }, interval=c(-5,5)) } # limits -5,5 should be replaced by your own which might require some fiddling e.g. d <- function(x) { exp(-x^2/2)/(sqrt(2*pi)) } # just an example for you to test with; use your own density d(x) in your case Then define myCumDist, myQuantile as above and compare with pnorm, qnorm. HTH, Eric On Tue, Nov 7, 2017 at 4:22 PM, Lorenzo Isella <[hidden email]> wrote: > Dear All, > Apologies for not providing a reproducible example, but if I could, then I > would be able to answer myself my question. > Essentially, I am trying to fit a very complicated custom probability > distribution to some data. > Fitdistrplus does in principle everything which I need, but if require me > to specify not only the density function d, but also the cumulative p and > and inverse cumulative function q (see for instance > > http://www.stat.umn.edu/geyer/old/5101/rlook.html > > to understand what these quantities are in the case of a normal > distribution). > > The analytical calculation of p and q is a big task in my case, so my > question is if there is a workaround for this, i.e. a way to fit the > unknown parameters of my probability distribution without specifying (at > least analytically) p and q, but only the density d. > Many thanks > > Lorenzo > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
> On Nov 7, 2017, at 6:58 AM, Eric Berger <[hidden email]> wrote: > > Why not define your own functions based on d? > e.g. > myCumDist <- function(x) { integrate(d, lower=-Inf, upper=x)$value } > myQuantile <- function(x) { uniroot(f=function(y) { h(y) - x }, > interval=c(-5,5)) } # limits -5,5 should be replaced by your own which > might require some fiddling My test gave an error regarding a missing `h` function. Perhaps you meant something like: myQuantile <- function(x) { uniroot(f=function(y) { myCumDist(y)-x }, interval=c(-5,5))$root } I added the $root extraction so it now returns a numeric value instead of a list. I wondered if that might be somewhat slow, and considered the possibility of building a close aproximation that didn't require a combined integration and rootfinding operation for every value using approxfun() on a suitable range of p-values in the range [0,1] -- David. > > e.g. > d <- function(x) { exp(-x^2/2)/(sqrt(2*pi)) } # just an example for you to > test with; use your own density d(x) in your case > > Then define myCumDist, myQuantile as above and compare with pnorm, qnorm. > > HTH, > Eric > > > > > On Tue, Nov 7, 2017 at 4:22 PM, Lorenzo Isella <[hidden email]> > wrote: > >> Dear All, >> Apologies for not providing a reproducible example, but if I could, then I >> would be able to answer myself my question. >> Essentially, I am trying to fit a very complicated custom probability >> distribution to some data. >> Fitdistrplus does in principle everything which I need, but if require me >> to specify not only the density function d, but also the cumulative p and >> and inverse cumulative function q (see for instance >> >> http://www.stat.umn.edu/geyer/old/5101/rlook.html >> >> to understand what these quantities are in the case of a normal >> distribution). >> >> The analytical calculation of p and q is a big task in my case, so my >> question is if there is a workaround for this, i.e. a way to fit the >> unknown parameters of my probability distribution without specifying (at >> least analytically) p and q, but only the density d. >> Many thanks >> >> Lorenzo >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/ >> posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble | Edit this page |