[R] CDF plot
Douglas Bates
dmbates at gmail.com
Thu Jul 7 04:07:36 CEST 2005
On 7/6/05, huang min <minhuangr at gmail.com> wrote:
> Dear all,
>
> I have define a discrete distribution P(y_i=x_i)=p_i, which I want to
> plot a CDF plot. However, I can not find a function in R to draw it
> for me after searching R and R-archive. I only find the one for the
> sample CDF instead my theoretical one.
>
> I find stepfun can do it for me, however, I want to plot some
> different CDF with same support x in one plot. I can not manage how to
> do it with stepfun.
>
> Is there any existing function in R to draw the theoretical CDF plot?
> Or how to abline other step functions in stepfun? Thanks.
The type = 's' option to the plot function is used to create the
"stairstep" plot of a cumulative distribution function. Try
> x <- 0:10
> Pr <- pbinom(x, size = 10, prob = 0.314)
> data.frame(x = x, Pr = Pr)
x Pr
1 0 0.02308028
2 1 0.12872474
3 2 0.34632766
4 3 0.61193435
5 4 0.82469072
6 5 0.94155166
7 6 0.98612689
8 7 0.99778589
9 8 0.99978712
10 9 0.99999068
11 10 1.00000000
> plot(c(-0.3, x), c(0, Pr), type = "s", xlab = "x", ylab = "P", main = "Cumulative distribution function", las = 1)
More information about the R-help
mailing list