2

I am struggling to create a continuous density curve in R for the below pdf:

{ 3x(1-x)^2     0 < x < 1

f(x) = { 3(2-x)(1-x)^2  1 ≤ x  < 2

{ 0              otherwise

Using the curve function, I can plot the two functions separately but not together:

curve(3*x*(1-x)^2,0,1)

curve(3*(2-x)*(1-x)^2,1,2)

Any help would be appreciated?

Banana
  • 2,435
  • 7
  • 34
  • 60
Apple_Tree
  • 49
  • 6

1 Answers1

3

You can start with an empty graph and then put together these pieces with add=TRUE.

plot(NULL, xlim=c(0,2), ylim=c(0,0.5))
curve(3*x*(1-x)^2,0,1, add=TRUE)
curve(3*(2-x)*(1-x)^2,1,2, add=TRUE)

Two curves

G5W
  • 36,531
  • 10
  • 47
  • 80