Skip to contents

Draws a random (sub)sample (with or without replacement).

Usage

resample_uniform(object, ...)

# S4 method for class 'numeric'
resample_uniform(object, n, size = length(object), replace = FALSE, ...)

Arguments

object

A numeric vector.

...

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.

replace

A logical scalar: should sampling be with replacement?

Value

A numeric matrix with n rows and size columns.

See also

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

Author

N. Frerebeau

Examples

## Uniform distribution
x <- rnorm(20)
resample_uniform(x, n = 10)
#>              [,1]        [,2]        [,3]        [,4]        [,5]        [,6]
#>  [1,]  0.03688103 -1.47855323  0.12524893 -0.04787012 -1.69616120 -2.72527788
#>  [2,]  1.06197512 -0.53746204  0.08197536  1.10331728 -0.03352687  0.94398055
#>  [3,] -0.34560366  0.03688103 -0.04787012  1.59039312 -0.20107488  0.48966148
#>  [4,]  0.08197536  0.03052902 -1.47855323 -0.34560366  1.59039312 -2.72527788
#>  [5,]  0.48966148 -0.03352687  1.06197512  0.12524893 -0.04787012 -1.47855323
#>  [6,]  0.48966148  1.06197512  0.03688103  1.59039312 -0.53746204 -0.20107488
#>  [7,] -0.34560366  0.03688103  0.94398055 -0.11695822 -0.03352687 -0.53746204
#>  [8,] -0.53746204  1.06197512  1.10331728  0.03052902  0.03688103 -0.04787012
#>  [9,]  0.08197536 -0.53746204  0.94398055  1.59039312  0.79560748 -2.72527788
#> [10,] -0.34560366  0.03052902 -0.53746204 -0.04787012  0.79560748  1.10331728
#>              [,7]        [,8]        [,9]       [,10]      [,11]       [,12]
#>  [1,]  0.48966148 -0.11695822 -0.79489264 -0.20107488 -0.5374620 -0.03352687
#>  [2,]  0.48966148  1.59039312  0.03688103 -1.69616120 -0.2010749 -2.72527788
#>  [3,] -2.72527788  0.79560748  0.08197536 -0.53746204  0.1252489 -1.69616120
#>  [4,]  1.06197512 -0.79489264  0.03688103  0.94398055  0.4896615  0.12524893
#>  [5,]  0.03052902 -0.11695822  1.10331728 -1.69616120  1.5903931  0.94398055
#>  [6,] -0.04787012  0.79560748 -1.69616120 -0.34560366 -0.7948926  0.03052902
#>  [7,]  0.48966148  0.08197536  1.10331728 -2.72527788  0.7956075  1.59039312
#>  [8,]  0.12524893 -0.11695822 -0.34560366 -2.72527788  0.9439805 -0.79489264
#>  [9,] -1.47855323  0.48966148 -1.69616120 -0.04787012 -0.7948926 -0.03352687
#> [10,] -0.20107488  0.03688103 -1.47855323 -0.79489264  1.5903931 -0.11695822
#>             [,13]       [,14]       [,15]       [,16]       [,17]      [,18]
#>  [1,]  1.06197512  0.94398055 -0.34560366  0.03052902  0.79560748  1.5903931
#>  [2,]  0.79560748 -0.79489264 -0.04787012  0.12524893  0.03052902 -0.1169582
#>  [3,] -0.03352687 -1.47855323  1.10331728  0.94398055  1.06197512 -0.1169582
#>  [4,] -0.11695822 -0.20107488  1.10331728 -0.03352687  0.79560748 -0.5374620
#>  [5,] -2.72527788 -0.34560366 -0.20107488  0.79560748 -0.79489264 -0.5374620
#>  [6,] -0.03352687 -1.47855323  0.94398055  1.10331728  0.12524893 -2.7252779
#>  [7,] -0.04787012 -0.20107488 -0.79489264 -1.47855323  0.12524893  1.0619751
#>  [8,]  0.08197536  0.48966148 -1.47855323  1.59039312  0.79560748 -0.2010749
#>  [9,] -0.20107488  0.03688103  1.06197512 -0.11695822  0.12524893 -0.3456037
#> [10,]  0.94398055  1.06197512  0.48966148 -0.03352687 -1.69616120  0.1252489
#>             [,19]       [,20]
#>  [1,]  1.10331728  0.08197536
#>  [2,] -0.34560366 -1.47855323
#>  [3,] -0.79489264  0.03052902
#>  [4,] -0.04787012 -1.69616120
#>  [5,]  0.08197536  0.03688103
#>  [6,]  0.08197536 -0.11695822
#>  [7,] -1.69616120  0.03052902
#>  [8,] -0.03352687 -1.69616120
#>  [9,]  1.10331728  0.03052902
#> [10,]  0.08197536 -2.72527788

## 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   96   90   86   41   65    2   95   98    72    62    75    93
#>  [2,]   45   80  105   79   50   81    5   80   97    70    66    72    99
#>  [3,]   48   78   99   76   59   94    0   87   93    51    56    76   109
#>  [4,]   53   68   91  105   51   65    4  106   92    66    55    71    94
#>  [5,]   48   87  103   78   43   69    7  100   99    64    60    74    94
#>  [6,]   51   81   91   80   55   89    4   87   82    58    66    78    89
#>  [7,]   49   69   97   78   43   94    5  101   96    62    74    78    94
#>  [8,]   47   86  103   83   46   74    6  100  106    68    60    69    82
#>  [9,]   61   80   97   94   49   79    3   91   82    50    71    72    97
#> [10,]   54   81  101   81   37   87    2  102   95    72    68    71    88
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20]
#>  [1,]   104    22    60    52   112    44    20
#>  [2,]   104    21    55    51   101    58    30
#>  [3,]   112    18    73    32    93    68    27
#>  [4,]   115    18    71    52    93    56    23
#>  [5,]   116    20    77    46    93    51    20
#>  [6,]   116    19    66    56    96    56    29
#>  [7,]   108    17    74    52    91    47    20
#>  [8,]    86    21    76    42    94    74    26
#>  [9,]   103    30    64    51    92    52    31
#> [10,]   103    23    80    35    92    47    30