rmvhyper: Random generation for the multivariate hypergeometric...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/rmhyper.q View source: R/rmhyper.q

Description

Generates a single random deviate from a multivariate hypergeometric distribution.

Usage

1
rmvhyper(Mk, m)

Arguments

Mk

A numeric vector describing the population from which the sub-sample will be drawn.

m

Number of elements to be drawn from the population

Details

The multivariate hypergeometric distribution is for sampling without replacement from a population with a finite number of element types. The number of element types is given by the length of the vector Mk.

Value

A numeric vector of elements, totally to m, drawn without replacement from the population described by Mk.

Author(s)

Sebastien Haneuse

See Also

rhyper.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
##
rmvhyper(c(1000, 500, 200, 50), 200)

## Check the properties (first two moments) of the generated deviates
##
M  <- 100
Qx <- c(0.7, 0.15, 0.1, 0.05)
temp <- matrix(NA, nrow=10000, ncol=length(Qx))
for(i in 1:nrow(temp)) temp[i,] <- rmvhyper(M*Qx, 1)

##
rbind(Qx, apply(temp, 2,  mean))
rbind(sqrt(Qx * (1-Qx)), apply(temp, 2, sd))

Example output

[1] 121  49  26   4
     [,1]   [,2]   [,3]   [,4]
Qx 0.7000 0.1500 0.1000 0.0500
   0.6965 0.1516 0.1027 0.0492
          [,1]      [,2]      [,3]      [,4]
[1,] 0.4582576 0.3570714 0.3000000 0.2179449
[2,] 0.4597922 0.3586507 0.3035818 0.2162962

osDesign documentation built on Nov. 16, 2020, 9:09 a.m.

Related to rmvhyper in osDesign...