[R] Dunif and Punif

michele donato michele.donato at wayne.edu
Mon Nov 7 17:49:43 CET 2011

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?

More information about the R-help mailing list