[R] cdf in R give probability of random variable
pdalgd at gmail.com
Fri Oct 21 20:23:42 CEST 2016
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 . <ragia11 at hotmail.com> wrote:
> Dear Grooup
> 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:
> 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
> [[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
Office: A 4.23
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help