Emy
Emy

Reputation: 977

Find y-value given x-value on a beta distribution

I am trying to find the y-values of points on a beta curve.

This is my beta; let's say I would like to find the point whose x-value is 0.6, for example:

x=seq(0,1,length=100)
y=dbeta(x,7,2)
plot(x,y, type="l", col="blue")
abline(v=0.6)

enter image description here

I have tried to add the corresponding point, but for some reason it does not work:

points(0.6, beta(7, 2), cex=3, pch=20, col="black")

enter image description here

Once fixed this problem, how can I find the y-value? I looked online; I found some examples using approxfun but I don't know how to apply it to this problem.

Upvotes: 0

Views: 224

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226162

You need to use dbeta() instead of beta() (assuming that's not a typo), and specify all three of x, shape1, and shape2. I think you want

points(0.6, dbeta(0.6, shape1=7, shape2=2), 
   cex=3, pch=20, col="black")

If you want to store the actual y-value in a variable, use

bval <- dbeta(0.6, shape1=7, shape2=2)

Upvotes: 2

Related Questions