R uniform distribution


runif() generates random deviates of uniform distribution, dunif() performs the density analysis, punif() gives the distribution function and qunif() gives the quantile function.

runif(n, min = 0, max = 1)
dunif(x, min = 0, max = 1, log = FALSE)
punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)
qunif(p, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)


x, q: vector of quantiles.
p: vector of probabilities.
n: number of observations. If length(n) > 1, the length is taken to be the number required.
min, max: lower and upper limits of the distribution. Must be finite.
log, log.p: logical; if TRUE, probabilities p are given as log(p).
lower.tail: logical; if TRUE (default), probabilities are P[X ≤ x], otherwise, P[X > x].

> runif(20,min=-1,max=2)
 [1] -0.907921619  0.009767967  0.331209081 -0.242364699  0.444335947
[6]  1.991711407 -0.812969660  1.237642935 -0.088655771  0.519129887
[11]  0.590708634  0.743662685  0.964670761  0.179365808  0.439812715
[16]  0.140639431 -0.518143212  0.007242380 -0.291944764  0.213176991

For 0 <= x <= 1, dunif(x)=1; for x < 0 and x > 1, dunif(x) = 0;

> dunif(0)
[1] 1
> dunif(1)
[1] 1
> x <- seq(-1,2,by=0.01)
> y <- dunif(x)
> plot(x,y,col="green", type="l")

For 0 <= x <= 1, punif(x)=x; for x < 0, dunif(x) = 0; for x > 1, dunif(x) = 1;

> punif(0)
[1] 0
> punif(1)
[1] 1
> x <- seq(-1,2,by=0.001)
> y <- punif(x)
> plot(x,y,col="green", type="l")

> qunif(c(0.05,0.25,0.5,0.75))
[1] 0.05 0.25 0.50 0.75







endmemo.com © 2025  | Terms of Use | Privacy | Home