[R] calculate quantiles of a custom function

Albyn Jones jones at reed.edu
Thu Jan 5 00:13:36 CET 2012


FWIW, the integral of a mixture density is the same mixture of the  
CDFs, so you can use the pbeta functions:

  pcustom <- function(x) (pbeta(x,2,6) + pbeta(x,6,2))/2

albyn

Quoting Gerhard <feldspat at gmx.net>:

> Am Dienstag, 3. Januar 2012, 19:51:36 schrieb Prof. Dr. Matthias Kohl:
>> D <- AbscontDistribution(d = function(x) dbeta(x, 2, 6) + dbeta(x,6,2),
>> low = 0, up = 1, withStand = TRUE)
>
> Dear all,
>
> thank you all again for your help.
>
> So, summing up, (in case this might be useful to other beginners - like me)
> this is how it can be done:
>
> ############################
> library(distr)
>
> dcustom <- function(x) {
>   (dbeta(x,2,6) + dbeta(x,6,2))/2 	 # I need to divide by 2 to get 1 as
>                                  				 # result of integration;
> }
>
> pcustom <- function(x) {
>   integrate(dmyspeaker,0,x)$value
> }
>
> D <- AbscontDistribution(d = dcustom, low = 0, up = 1, withStand = TRUE)
>
> qcustom <- function(x){
>   q(D)(x)
> }
> ############################
>
> Best,
>
> Gerhard
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
>



More information about the R-help mailing list