1

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.

Alex
  • 2,603
  • 4
  • 40
  • 73

2 Answers2

4

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))
G5W
  • 36,531
  • 10
  • 47
  • 80
1

G5w's answer is better for this question. In general, though you can use integrate to get the area under functions for specific intervals. For instance, for dbeta between 0.2 and0.3, you could use

integrate(dbeta, .2, .3, shape1=.25, shape2=.43)
0.05982106 with absolute error < 6.6e-16

To get this for each interval of width 0.1 from 0 to 1, put this into an sapply.

myAreas <- sapply(seq(0, .9, .1),
                  function(x) integrate(dbeta, x, x+.1, shape1=.25, shape2=.43)[[1]])

This results in a vector of these values

and compare the results to G5W's suggestion.

all.equal(pbeta(0.1, 0.25,0.43) - pbeta(0, 0.25,0.43), myAreas[1])
lmo
  • 37,904
  • 9
  • 56
  • 69