[R] Dunif and Punif

R. Michael Weylandt michael.weylandt at gmail.com
Mon Nov 7 18:08:07 CET 2011

In short, the unif() distribution corresponds to the continuous
uniform distribution, not the discrete.

Longer: dDIST() doesn't give a pmf so summing it isn't what you are
looking for: it gives a pdf. For punif() consider P\{X <= 1\} when X
is distributed on [1, 10]. Clearly this has probability zero because
it can only occur for one out of uncountably many values -- though
this notion should be made more precise using a little bit of measure


On Mon, Nov 7, 2011 at 11: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?
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

More information about the R-help mailing list