Search code examples
rdistributionbeta-distribution

Calculate Areas of breaks under a beta distribution in r


Given the following beta distribution

x <- seq(0,1,length=100)
db <- dbeta(x, .25, .43)
ggplot() + geom_line(aes(x,db))+scale_x_continuous(breaks = seq(0,1,by=.1))

how can I find the area under breaks 0 to 1 by 0.1 intervals. Not cumulative area just area for that specific break. For example the break 0.2 to 0.3 would have only that area inclusive and not previous areas.


Solution

  • The area between the breaks is the difference between the cumulative area for the two endpoints. So that for example, the area between 0 and 0.1 is

    pbeta(0.1, 0.25,0.43) - pbeta(0, 0.25,0.43)
    

    To get all of the areas, just apply this to the list of breaks

    breaks = seq(0,1,by=.1)
    sapply(1:10, function(i) pbeta(breaks[i+1], 0.25,0.43) - pbeta(breaks[i], 0.25,0.43))