0

Given

 p<-function(x){if ( x==-4) {
    0.1
  } else if (x==-1 ) {
   0.2
  } else if ( x==1) {
    0.6
  } else if (x==2 ) {
    0.1
  } else {
   0
  }

How would I plot the PMF and CDF. No distribution is specified so I cant use the build in commands. What would be the best way to plot these

2 Answers2

0

Easy and simple solution:

### support
x = seq(-4,2,1)
### PDF
plot(x,sapply(x,p),ylab="PDF")
### CDF
plot(x,cumsum(sapply(x,p)),ylab="CDF")
0

Try this for PMF

df <- data.frame(x = c(-4, -1, 1, 2), p = c(.1, .2, .6, .1))
plot(df, type = "l")
points(df)

enter image description here


For CDF, you can try a similar one

plot(df_cdf <- transform(df, p = cumsum(p)), type = "l")
points(df_cdf)

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81