Skip to contents

Draws a random (sub)sample from a multinomial distribution.

Usage

resample_multinomial(object, ...)

# S4 method for class 'numeric'
resample_multinomial(object, n, size = sum(object), ...)

Arguments

object

A length-\(k\) integer vector, specifying the probability for the \(k\) classes; is internally normalized to sum to 1.

...

Currently not used.

n

A non-negative integer specifying the number of random vector to draw.

size

A non-negative integer specifying the sample size.

Value

A numeric matrix with n rows and k columns.

See also

stats::rmultinom()

Other resampling methods: bootstrap(), jackknife(), resample_uniform()

Author

N. Frerebeau

Examples

## Uniform distribution
x <- rnorm(20)
resample_uniform(x, n = 10)
#>              [,1]       [,2]       [,3]        [,4]        [,5]       [,6]
#>  [1,]  1.60877501 -1.0915715  0.9864177  1.15119402  0.50365091 -0.1031018
#>  [2,]  0.84824048  0.5036509  1.1252749 -0.09823232  1.60877501 -1.3538170
#>  [3,] -0.02931659  1.1511940  1.1252749 -0.65159647 -0.09823232  1.6087750
#>  [4,] -0.65159647  1.1252749 -1.3538170 -1.09157153  2.03635806  0.2859314
#>  [5,] -0.09823232  0.2859314 -1.3538170 -0.65159647 -0.10310177  0.6504066
#>  [6,] -1.35381698 -0.3645642 -0.3180002  0.50365091  1.12527487 -0.1031018
#>  [7,] -0.09823232  0.5717264 -0.1031018 -0.36456419  0.50365091  0.8482405
#>  [8,]  0.65040660  2.0363581 -1.3538170 -0.36456419  1.12527487 -0.2043277
#>  [9,] -0.09823232 -0.3645642  0.5717264 -0.20432766  1.60877501  1.1252749
#> [10,]  2.03635806 -1.0915715 -1.3538170 -0.36456419  0.84824048  0.2859314
#>              [,7]       [,8]        [,9]       [,10]      [,11]       [,12]
#>  [1,] -0.02931659  2.0363581  1.12527487 -0.20432766  0.8482405 -0.09823232
#>  [2,]  0.65040660 -0.3180002 -0.10310177 -0.65159647  0.2859314 -0.02931659
#>  [3,]  0.98641772  0.8482405  0.65040660 -1.35381698 -0.8807304  0.28593139
#>  [4,]  0.65040660 -0.2043277  0.98641772 -0.10310177 -0.8807304 -0.36456419
#>  [5,]  0.84824048 -1.0915715 -0.02931659  1.12527487  0.9864177  0.57172643
#>  [6,]  0.98641772  0.8482405  0.65040660 -0.88073038  1.6087750 -0.65159647
#>  [7,]  0.28593139 -0.6515965  0.98641772 -0.88073038 -1.3538170 -0.02931659
#>  [8,]  1.60877501 -1.0915715 -0.65159647 -0.10310177  0.5036509  0.98641772
#>  [9,] -0.10310177 -0.3180002  0.28593139 -0.65159647  2.0363581 -0.88073038
#> [10,]  0.65040660  1.1252749 -0.65159647 -0.02931659  0.9864177  0.57172643
#>             [,13]       [,14]      [,15]       [,16]       [,17]       [,18]
#>  [1,] -0.31800023  0.57172643  0.6504066 -1.35381698 -0.88073038 -0.65159647
#>  [2,] -0.36456419  2.03635806 -1.0915715  0.57172643  0.98641772  1.15119402
#>  [3,] -0.10310177 -1.09157153 -0.2043277  0.57172643 -0.31800023  0.50365091
#>  [4,] -0.09823232  1.60877501  0.8482405  0.57172643 -0.02931659  0.50365091
#>  [5,] -0.31800023  1.15119402 -0.2043277 -0.36456419  2.03635806  1.60877501
#>  [6,] -0.09823232 -0.02931659 -1.0915715  2.03635806 -0.20432766  0.28593139
#>  [7,] -0.31800023  1.15119402 -1.0915715  2.03635806  1.12527487  0.65040660
#>  [8,]  0.57172643  0.84824048  1.1511940 -0.02931659 -0.88073038 -0.09823232
#>  [9,]  0.84824048  1.15119402  0.6504066 -1.35381698 -1.09157153  0.50365091
#> [10,] -0.10310177 -0.20432766  1.1511940 -0.09823232 -0.88073038  0.50365091
#>             [,19]      [,20]
#>  [1,]  0.28593139 -0.3645642
#>  [2,] -0.20432766 -0.8807304
#>  [3,]  2.03635806 -0.3645642
#>  [4,] -0.31800023  1.1511940
#>  [5,]  0.50365091 -0.8807304
#>  [6,]  1.15119402  0.5717264
#>  [7,]  1.60877501 -0.2043277
#>  [8,] -0.31800023  0.2859314
#>  [9,] -0.02931659  0.9864177
#> [10,]  1.60877501 -0.3180002

## Multinomial distribution
x <- sample(1:100, 20, TRUE)
resample_multinomial(x, n = 10)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]   60   54   38  106   62   41   65   38   63    37    95    11    63
#>  [2,]   67   68   36  102   67   47   77   44   64    35    76    16    50
#>  [3,]   67   57   43  104   63   46   63   31   58    28    92    17    69
#>  [4,]   66   60   35  103   67   45   82   43   56    23    87    13    65
#>  [5,]   75   68   42   90   43   43   69   38   70    30    86    10    56
#>  [6,]   69   53   41   91   58   51   54   33   64    33    88    15    74
#>  [7,]   73   70   32   72   65   42   77   40   72    35    82    12    58
#>  [8,]   83   70   38  105   60   41   69   41   60    23    93    15    56
#>  [9,]   68   71   37  101   65   31   68   27   56    32   108    13    63
#> [10,]   59   54   48  101   57   46   91   38   56    32    94    16    67
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20]
#>  [1,]    12    36    67     9    86     1    23
#>  [2,]    20    32    76     8    65     1    16
#>  [3,]    11    45    63    12    68     1    29
#>  [4,]    14    21    72    12    79     1    23
#>  [5,]     5    54    68    13    78     0    29
#>  [6,]    12    42    82    10    77     1    19
#>  [7,]     6    44    82    11    64     2    28
#>  [8,]     6    35    72     7    66     4    23
#>  [9,]     7    33    74     9    68     0    36
#> [10,]     8    27    72    11    67     1    22