Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - Русский

Change language to:
English - Français - 日本語 - Português -

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Справка Scilab >> Statistics > Sampling > samplef

samplef

sample values with replacement from a population with given frequencies.

Syntax

s = samplef(n,X,f,orient)

Arguments

n

positive integer (size of sample)

X

matrix. Population, samples are extracted from this matrix

f

matrix of positive real values. Indicates the corresponding frequencies of the values in X.

orient

Optional parameter. Admissible values are {'*'}, 1, 2, 'r' or 'c'. The orientation to sample rows or columns. See Description below.

s

vector or matrix containing the sampled values of X at frequencies f.

Description

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.

Random number generator

samplef is based on grand for generating the random samples. Use grand("setsd", seed) to change the seed for samplef.

seed = getdate("s");
grand("setsd", seed); //sets the seed to current date

seed = 0;
grand("setsd", seed); //sets the seed to default value

Examples

X = [3 7 9; 22 4 2];
f1 = [10 1 1 1 1 1];
f2 = [1 ; 15];
f3 = [10 1 1];
s=samplef(20, X, f1)      //the first value of matrix X will be chosen with frequency 10/15
s=samplef(20, X, f2, 'r') //the second row of matrix a will be chosen with frequency  15/16
s=samplef(20, X, f3, 'c') //the first column of matrix a will be chosen with frequency 10/12

See also

  • sample — Sampling with replacement
  • samwr — Sampling without replacement
  • grand — Случайные числа
Report an issue
<< sample Sampling samwr >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:05:02 CET 2019