Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot curve with multiple parameters

I want to make a plot using curve for multiple parameters.

For example, say I have the following distribution function for the binomial distribution:

enter image description here

I can plot curve for a probability mass function likeso:

curve(factorial(10)/(factorial(5)*factorial(5))*y^5*(1-y)^5, from=0, to = 1)

Because we want 0 < y < 1, however this won't work for multiple variables as from = 0, to = 1 will only apply for a single variable.

So - how can I get curve to work for something like:

curve(factorial(10)/(factorial(10-x)*factorial(x))*y^x*(1-y)^{10-x}, from=0, to = 1)

But also to indicate the the distribution function for x is less than or equal to 5, so from = 0, to = 5?

like image 940
dollar bill Avatar asked Mar 10 '26 19:03

dollar bill


1 Answers

I guess you can use dbinom directly

curve(dbinom(5, 10, y), xname = "y")

enter image description here

or if you need to vary x, you can try

sapply(0:10, function(k) curve(dbinom(k, 10, y), xname = "y", add = TRUE, ylim = c(0, 1)))

enter image description here

like image 104
ThomasIsCoding Avatar answered Mar 13 '26 08:03

ThomasIsCoding