Sampling functions

Population and sample histograms

 

Sample without replacement:

//Take a 100 observation sample from 'x'
//without replacement
sample = sampleData(x, 100);

Sample with replacement:

replace = 1;
//Take a 100 observation sample from 'x'
//WITH replacement
sample = sampleData(x, 100, replace);

Create training set and test set.

n = rows(x);

//Create indices for training set
idx_train = sampleData(seqa(1,1,n), 0.75 * n);

//Extract training set
x_train = x[idx_train];

//Remove (or delete) training set rows from 'x'
//to create test set 
x_test = delrows(x, idx_train);

Create random indices to draw from multiple variables:

//Create random integers from between 1 and 1000
range = { 1, 1000 };
idx = rndi(50, 1, range);

//Sample same observations from 'x' and 'y'
x_sample = x[idx,.];
y_sample = y[idx];

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.