Re: [R] cdf in R give probability of random variable
> peter dalgaard> on Fri, 21 Oct 2016 22:10:22 +0200 writes: >> On 21 Oct 2016, at 20:23 , peter dalgaard >> wrote: >> >> In both cases it works out nicer if you do >> >> names(px) <- x >> barplot(px) > Um, unless of course you want the cdf as a step function, > in which case check the help page for plot for possible > values of the type= argument. and if it is not homework, (or even then ;-) just use plot(ecdf(x)) Martin Maechler, ETH Zurich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cdf in R give probability of random variable
> On 21 Oct 2016, at 20:23 , peter dalgaardwrote: > > In both cases it works out nicer if you do > > names(px) <- x > barplot(px) > Um, unless of course you want the cdf as a step function, in which case check the help page for plot for possible values of the type= argument. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cdf in R give probability of random variable
This looks like homework, but doing it in R might not be, so I'll give you the benefit of doubt... > On 21 Oct 2016, at 18:30 , Ragia .wrote: > > > Dear Grooup > > kindly > > how can I plot these graphs in R.. > > > Suppose that X is a discrete random variable with P(X = 0) = .25, P(X = 1) = > .125, P(X = 2) = .125, and P(X = 3) = .5. Graph the frequency function and > the cumulative distribution function of X. > > > > my solution was: > > x=c(0,1,3) > px=c(.25,.125,.5) > plot( x,px ,type="h" ) # to plot the frequency , is it correct > You forgot X=2 in there (check the sum). > how to plot the cdf? > cumsum() is your friend. In both cases it works out nicer if you do names(px) <- x barplot(px) -pd > [[alternative HTML version deleted]] Notice that plain text posting is strongly preferred in here. HTML messes up code badly sometimes. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] cdf in R give probability of random variable
Dear Grooup kindly how can I plot these graphs in R.. Suppose that X is a discrete random variable with P(X = 0) = .25, P(X = 1) = .125, P(X = 2) = .125, and P(X = 3) = .5. Graph the frequency function and the cumulative distribution function of X. my solution was: x=c(0,1,3) px=c(.25,.125,.5) plot( x,px ,type="h" ) # to plot the frequency , is it correct how to plot the cdf? thanks in advance Ragia [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.