Density, distribution function, quantile function and random generation for the positive-geometric distribution.

dposgeom(x, prob, log = FALSE)
pposgeom(q, prob)
qposgeom(p, prob)
rposgeom(n, prob)

Arguments

x, q

vector of quantiles.

p

vector of probabilities.

n

number of observations. Fed into runif.

prob

vector of probabilities of success (of an ordinary geometric distribution). Short vectors are recycled.

log

logical.

Details

The positive-geometric distribution is a geometric distribution but with the probability of a zero being zero. The other probabilities are scaled to add to unity. The mean therefore is \(1/prob\).

As \(prob\) decreases, the positive-geometric and geometric distributions become more similar. Like similar functions for the geometric distribution, a zero value of prob is not permitted here.

Value

dposgeom gives the density, pposgeom gives the distribution function, qposgeom gives the quantile function, and rposgeom generates random deviates.

Author

T. W. Yee

Examples

prob <- 0.75; y <- rposgeom(n = 1000, prob)
table(y)
#> y
#>   1   2   3   4   5   6 
#> 772 174  37  10   5   2 
mean(y)  # Sample mean
#> [1] 1.308
1 / prob  # Population mean
#> [1] 1.333333

(ii <- dposgeom(0:7, prob))
#> [1] 0.0000000000 0.7500000000 0.1875000000 0.0468750000 0.0117187500
#> [6] 0.0029296875 0.0007324219 0.0001831055
cumsum(ii) - pposgeom(0:7, prob)  # Should be 0s
#> [1] 0 0 0 0 0 0 0 0
table(rposgeom(100, prob))
#> 
#>  1  2  3 
#> 78 17  5 

table(qposgeom(runif(1000), prob))
#> 
#>   1   2   3   4   5   6   7 
#> 749 197  39  10   2   2   1 
round(dposgeom(1:10, prob) * 1000)  # Should be similar
#>  [1] 750 188  47  12   3   1   0   0   0   0

if (FALSE) { # \dontrun{
x <- 0:5
barplot(rbind(dposgeom(x, prob), dgeom(x, prob)),
        beside = TRUE, col = c("blue", "orange"),
        main = paste("Positive geometric(", prob, ") (blue) vs",
        " geometric(", prob, ") (orange)", sep = ""),
        names.arg = as.character(x), las = 1, lwd = 2) } # }