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,]  2.34400339 -0.66750902  0.5277432  0.1169515 -0.31385587  0.4791398
#>  [2,]  0.11695150  0.52774319 -0.5715427  0.1296863  0.01879218 -0.6863439
#>  [3,] -0.31385587 -0.68634388 -0.5715427  0.1169515  1.38700704  0.8474670
#>  [4,] -0.57154269 -0.18183487 -0.3008754  0.3100714  0.52774319  1.3870070
#>  [5,] -0.31385587  1.24879410  1.3870070 -0.1818349  0.31007138  0.2039750
#>  [6,]  0.84746696  0.01879218 -0.5715427 -0.1818349  0.52774319  0.3452646
#>  [7,] -0.31385587 -0.18183487  1.2487941  0.3452646  0.47913980  0.5277432
#>  [8,]  0.01879218  0.12968631 -0.5715427 -0.1818349  0.20397498 -0.6863439
#>  [9,]  0.84746696  2.34400339 -1.2917085  0.3100714 -0.30087541  0.3452646
#> [10,] -0.30087541  0.20397498 -0.1818349  0.4791398  0.12968631  0.3452646
#>             [,7]        [,8]        [,9]      [,10]       [,11]      [,12]
#>  [1,]  0.5469201  0.20397498  0.84746696 -0.5715427 -1.29170853 -0.6863439
#>  [2,]  0.8474670  0.34526460  0.54692012  1.3870070 -1.29170853 -0.1818349
#>  [3,]  0.2039750  0.12968631  2.34400339  0.5277432  0.54692012  1.2487941
#>  [4,]  0.5469201  0.20397498  0.84746696 -1.2917085  0.47913980  0.1169515
#>  [5,] -0.6863439  0.11695150  0.54692012 -1.2917085 -0.57154269  2.3440034
#>  [6,]  0.4791398  0.12968631  0.11695150  1.3870070  0.31007138  0.5469201
#>  [7,]  1.3870070 -0.30087541 -0.68634388  0.1169515  0.01879218 -1.2917085
#>  [8,]  0.8474670  0.52774319  0.11695150  2.3440034  0.54692012  1.2487941
#>  [9,] -0.6675090  0.54692012  0.01879218 -0.3138559 -0.18183487  0.5277432
#> [10,] -0.6675090  0.01879218 -0.57154269  0.8474670 -0.31385587  1.2487941
#>            [,13]      [,14]      [,15]       [,16]       [,17]      [,18]
#>  [1,]  1.3870070  0.1296863  0.3452646  1.24879410 -0.30087541  0.3100714
#>  [2,] -0.3138559  0.4791398  0.2039750  1.24879410  2.34400339  0.3100714
#>  [3,] -0.3008754 -0.6675090  0.3452646 -0.18183487  0.01879218  0.4791398
#>  [4,] -0.3138559  2.3440034  0.1296863  0.01879218  0.34526460 -0.6863439
#>  [5,] -0.3008754 -0.6675090  0.1296863  0.01879218  0.52774319  0.8474670
#>  [6,]  1.2487941  0.2039750 -0.6675090  2.34400339 -1.29170853 -0.3138559
#>  [7,]  0.2039750 -0.6675090  0.8474670 -0.57154269  0.12968631  0.3100714
#>  [8,]  1.3870070  0.3452646 -0.6675090 -0.31385587 -1.29170853  0.3100714
#>  [9,]  1.2487941  0.4791398 -0.5715427  0.11695150  0.20397498  0.1296863
#> [10,] -1.2917085  0.1169515  0.3100714  0.54692012  1.38700704  0.5277432
#>             [,19]      [,20]
#>  [1,]  0.01879218 -0.1818349
#>  [2,] -0.30087541 -0.6675090
#>  [3,]  0.31007138 -1.2917085
#>  [4,] -0.66750902  1.2487941
#>  [5,]  0.47913980  0.3452646
#>  [6,] -0.30087541 -0.6863439
#>  [7,]  2.34400339  0.5469201
#>  [8,]  0.47913980 -0.3008754
#>  [9,] -0.68634388  1.3870070
#> [10,]  2.34400339 -0.6863439

## 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,]   58    6    8   50   61   70   39   94   42    33    88    70     2
#>  [2,]   60    3    9   46   80   71   37   77   28    25    78    83     1
#>  [3,]   60    4   10   57   77   62   41   82   25    22    90    81     2
#>  [4,]   51    6   11   57   70   46   33   83   36    19    79    81     0
#>  [5,]   57    3    6   44   79   67   36   93   40    33    81    73     0
#>  [6,]   65    5    7   58   68   49   40   89   21    26    74    88     1
#>  [7,]   68    4   10   45   72   64   32   92   32    29    86    83     0
#>  [8,]   76    5    7   50   67   54   26   78   38    29    96    84     1
#>  [9,]   62    8   13   55   66   65   43   85   25    26    82    82     0
#> [10,]   68    5    8   55   60   75   46   83   40    26    80    78     1
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20]
#>  [1,]    54    88    14    42    90    39    53
#>  [2,]    60    92    26    52    94    32    47
#>  [3,]    56    94    12    49    87    30    60
#>  [4,]    64    79    20    48    96    50    72
#>  [5,]    60    86    12    46    81    37    67
#>  [6,]    78    94    14    47    76    43    58
#>  [7,]    59    79    22    44    95    30    55
#>  [8,]    68    83    19    46    76    39    59
#>  [9,]    66    83    22    50    81    36    51
#> [10,]    71    78    10    40    93    27    57