是否可以使用cdf在一个图中绘制多个ecdf和cdf?

时间:2019-03-26 07:22:33

标签: r cdf ecdf

我正在为数据集x,y和z制作cdf。如何将它们放置在一个图中?

我使用fitdist获得x,y和z的ecdf和cdf。

  ## Say if we have 
  x=runif(30)
  y=runif(30) 
  z=runif(30)

  ## To fit the distribution I used fitdist 
   a=fitdist(x, "norm")
   b=fitdist(y, "norm")
   c=fitdist(z, "norm")

   par(mfcol=c(1,3))
   cdfcomp(a, xlab="yield loss", ylab="probability", main="1st Stage",      datacol="black", fitcol="green")
   cdfcomp(b, xlab="yield loss", ylab="probability", main="2nd Stage",datacol="gray", fitcol="blue")
   cdfcomp(c, xlab="yield loss", ylab="probability",main="3rd Stage",datacol="navy", fitcol="red")

这些代码给出了三个单独的图。有没有办法把它们放在同一块土地上?

我尝试做

    cdfcomp(list(a,b, c), horizontals = FALSE)

但它给出以下消息

   "Error in FUN(X[[i]], ...) : 
    All compared fits must have been obtained with the same dataset."

我该怎么办?

1 个答案:

答案 0 :(得分:0)

可以使用add = TRUE

library(fitdistrplus)
x=runif(30)
y=runif(30) 
z=runif(30)
a=fitdist(x, "norm")
b=fitdist(y, "norm")
c=fitdist(z, "norm")
cdfcomp(a, xlab="yield loss", ylab="probability", datacol="black", fitcol="green")
cdfcomp(b, datacol="gray", fitcol="blue", add = TRUE)
cdfcomp(c, datacol="navy", fitcol="red", add = TRUE)

enter image description here