sample values with replacement from a population with given frequencies.
s = samplef(n,X,f,orient)
positive integer (size of sample)
matrix. Population, samples are extracted from this matrix
matrix of positive real values. Indicates the corresponding frequencies of the values in X
.
Optional parameter. Admissible values are {'*'}, 1, 2, 'r'
or 'c'
. The orientation to sample rows or columns. See Description below.
vector or matrix containing the sampled values of X
at frequencies f
.
This function returns s
, a vector of length n
. It contains
a sample of n
extractions, with replacement, from the
vector (or matrix) X
, each element counted with the
frequency given by the corresponding value in vector f
.
s=samplef(n,X,f)
(or
s=samplef(n,X,f,'*')
) returns a
vector s
whose values are a random sample of n values from
X
, each value with a probability to be sampled
proportional to the corresponding value of f
, extracted
with replacement, from X
. f
must have same length than X
.
s=samplef(n,X,f,'r')
(or, equivalently,
s=samplef(n,X,f,1))
returns a matrix of type
size(X,'r') * n
. It contains a random sample of n
rows from
X
, each row with a probability to be sampled proportional
to the corresponding value of f
, extracted with
replacement, from the rows of X
. The length of f
must be
equal to the number of rows of X
.
s=samplef(n,X,f,'c')
(or, equivalently,
s=samplef(n,X,f,2))
returns a matrix of type
n * size(X,'c')
. It contains a random sample of n
columns
from X
, each column with a probability to be sampled
proportional to the corresponding value of f
, extracted
with replacement, from the columns of X
. The length of f
must be equal to the number of columns of X
.
samplef
is based on grand for generating the random samples. Use grand("setsd", seed)
to change the seed for samplef
.