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,] -2.06991393 -0.4365199  1.28670524  0.06931626 -1.2046064  1.1456325
#>  [2,]  0.11491376  1.1456325  0.06931626 -1.20460638 -0.1646107  0.0199721
#>  [3,]  0.01997210  1.1686415 -1.31716424  1.01909699  0.1149138 -1.2046064
#>  [4,]  0.06931626 -1.4785532  1.00179059 -0.52874430  1.0016327 -1.3171642
#>  [5,]  0.06931626  1.0017906 -0.95685271  0.11491376 -2.0699139  1.1456325
#>  [6,]  1.01909699 -0.9568527 -0.43651990  0.63281310 -1.4785532 -2.0699139
#>  [7,] -2.06991393  1.0017906  1.28670524  1.16864147 -0.9568527  1.0016327
#>  [8,]  0.01997210 -2.0699139 -0.43651990  0.11491376 -0.1646107 -1.2046064
#>  [9,]  1.01909699  1.1686415 -2.06991393  1.00163270 -0.1646107  1.2867052
#> [10,] -1.31716424 -1.4785532  1.16864147  0.11491376  1.1456325 -1.2046064
#>              [,7]        [,8]       [,9]       [,10]       [,11]      [,12]
#>  [1,] -1.47855323 -1.85149913  1.0190970  0.01997210 -0.52874430 -1.1695096
#>  [2,]  1.00163270 -0.43651990 -2.0699139 -0.52874430  1.28670524 -1.1695096
#>  [3,]  1.00179059 -1.85149913 -0.9568527 -0.43651990  0.06931626 -0.5287443
#>  [4,]  1.16864147  0.63281310  1.2867052 -1.16950957  0.11491376 -0.4365199
#>  [5,]  1.00163270 -0.16461072 -1.1695096  1.01909699 -1.85149913  1.1686415
#>  [6,]  0.06931626  0.01997210  1.2867052 -1.20460638 -0.16461072  0.1149138
#>  [7,] -0.52874430  0.63281310  1.0190970 -1.20460638 -0.43651990 -1.8514991
#>  [8,] -1.31716424  0.06931626 -1.1695096  1.00163270 -1.85149913 -1.4785532
#>  [9,]  1.14563254 -0.95685271 -1.3171642 -1.85149913  0.11491376  0.6328131
#> [10,]  1.00163270 -2.06991393 -1.1695096  0.06931626  1.01909699 -0.4365199
#>            [,13]       [,14]       [,15]      [,16]      [,17]      [,18]
#>  [1,] -0.1646107  1.16864147 -1.31716424  0.6328131  1.0017906 -0.9568527
#>  [2,] -1.4785532  1.01909699 -1.31716424  1.1686415  1.0017906  0.6328131
#>  [3,]  0.6328131  1.14563254  1.28670524 -1.4785532 -0.1646107 -2.0699139
#>  [4,] -1.2046064  1.01909699  1.14563254 -0.1646107 -1.8514991 -2.0699139
#>  [5,] -1.4785532 -1.31716424 -0.43651990  1.2867052 -0.5287443 -1.2046064
#>  [6,]  1.0016327  1.14563254 -1.85149913 -1.3171642 -0.5287443  1.0017906
#>  [7,]  0.0199721  0.06931626 -1.31716424  0.1149138 -0.1646107  1.1456325
#>  [8,]  1.1456325 -0.95685271  1.00179059  0.6328131 -0.5287443  1.0190970
#>  [9,] -0.4365199  1.00179059  0.06931626 -1.4785532 -1.1695096 -0.5287443
#> [10,] -0.5287443 -0.16461072 -0.95685271  1.2867052  0.0199721  1.0017906
#>            [,19]      [,20]
#>  [1,]  1.0016327  0.1149138
#>  [2,] -1.8514991 -0.9568527
#>  [3,]  1.0016327 -1.1695096
#>  [4,]  0.0199721 -0.9568527
#>  [5,]  0.0199721  0.6328131
#>  [6,] -1.1695096  1.1686415
#>  [7,] -1.4785532 -1.1695096
#>  [8,]  1.2867052  1.1686415
#>  [9,]  0.0199721 -1.2046064
#> [10,] -1.8514991  0.6328131

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