[R] Dunif and Punif
Peter Langfelder
peter.langfelder at gmail.com
Mon Nov 7 18:13:05 CET 2011
On Mon, Nov 7, 2011 at 8:49 AM, michele donato <michele.donato at wayne.edu> wrote:
> Hi,
> I am trying to use dunif and runif
> however, I have two problems:
> if I do
>
> dunif(1:10, min=1, max=10)
>
> I get 10 values, which summed give me 1.1111
> I understand that the probability is computed as f(x) = 1 / (max-min)
> but in this case it looks wrong: I have 10 values, each one
> equiprobable, and the probability for each one should be 0.1 and not
> 0.11111 (which is, consistently with the definition, 1/9)
>
> It looks like one of the extremes is not considered in the computation
> of the probability, but then it's assigned a probability anyway.
>
> Similar problem with punif.
>
> if I do
> punif(1, min=1, max=10)
> I get 0 as result, as if the lower extreme is not considered, which is
> not consistent with the description where min <= x <= max
> If the lower extreme is not considered because cdf(x) = p(X<x) {and
> not p(X<=x)} the problem stands in p(X<11) which should be the sum of
> everything. ( P(1) + P(2) + ... + P(10) )
>
> What is happening here?
The uniform distribution is continuous.
Your interval has length 9 (10-1 = 9), so the density 1/9. Multiplied
by 10 it gives you your answer. Same for the cumulative probability
distribution (punif) - it is zero at x=1 because that's where your
interval starts.
Peter
More information about the R-help
mailing list