'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:
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?
Solution 1:[1]
You could loop over a sequence from 0 to 5.
curve(factorial(10)/(factorial(5)*factorial(5))*x^5*(1-x)^5, from=0, to=1,
ylim=c(0, 1), type='n')
invisible(lapply(seq.int(.005, 5, .005), \(y)
curve(factorial(10)/(factorial(10 - x)*factorial(x))*y^x*(1 - y)^{10 - x},
add=TRUE))
)
The invisible avoids cluttering of the console.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


