stats::sample

Domain of statistical samples

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

stats::sample([[a1, 1, a1, 2, …], [a2, 1, a2, 2, …], …])
stats::sample([a1, 1, a2, 1, …])

Description

sample represents a collection of statistical data, organized as a matrix. Usually, each row refers to an individual of the population described by the sample. Each column represents an attribute.

stats::sample( [[a1, 1, …, a1, n], …, [am, 1, …, am, n]] ) creates a sample with m rows and n columns, ai, j being the entry in the i-th row, j-th column.

stats::sample( [a1, 1, …, am, 1] ) creates a sample with m rows and one column.

Each row [ai, 1, …, ai, n] must contain the same number of entries.

Elements of domain type DOM_COMPLEX, DOM_EXPR, DOM_FLOAT, DOM_IDENT, DOM_INT, or DOM_RAT are regarded as “data” and are stored in a sample as on input. All other types of input parameters are converted to strings (DOM_STRING).

If one element in a column is a string or is converted to a string, then all elements of that column are converted to strings.

This produces two kinds of columns: data columns and string columns.

Superdomain

Dom::BaseDomain

Categories

Cat::Set

Examples

Example 1

A sample is created from a list of rows:

stats::sample([[5, a], [b, 7.534], [7/4, c+d]])
  5      a
  b  7.534
7/4  c + d

For a sample with only one column one can use a flat list instead of a list of rows:

stats::sample([5, 3, 8])
5
3
8

Example 2

The following input creates a small sample with columns for “gender”, “age” and “height”, respectively:

stats::sample([["m", 26, 180], ["f", 22, 160], 
               ["f", 48, 155], ["m", 30, 172]])
"m"  26  180
"f"  22  160
"f"  48  155
"m"  30  172

Note that all entries in a column are automatically converted to strings, if one entry of that column is a string:

stats::sample([[m, 26, 180], [f, 22, 160], 
               ["f", 48, 155], [m, 30, 172]])
"m"  26  180
"f"  22  160
"f"  48  155
"m"  30  172

Example 3

The functions float, has, map, nops, op, and subsop are overloaded to work on samples as on lists of lists:

s := stats::sample([[a, 1], [b, 2], [c, 3]])
a  1
b  2
c  3
float(s), has(s, a), map(s, list -> [list[1], list[2]^2]),
nops(s), subsop(s, 1 = [d, 4]), op(s, [1, 2])
a  1.0          a  1       d  4
b  2.0  , TRUE, b  4  , 3, b  2  , 1
c  3.0          c  9       c  3

Indexing works like on arrays:

s[1, 2] := x : s
a  x
b  2
c  3
delete s:

Example 4

The dot operator may be used to concatenate samples and lists (regarded a samples with one row):

s := stats::sample([[1, a], [2, b]]): s.[X, Y].s
1  a
2  b
X  Y
1  a
2  b
delete s:

Parameters

a1, 1, a1, 2, …

Arithmetical expressions or strings.

Methods

expand all

Mathematical Methods

equal(s1, s2)

Conversion Methods

convert(x)

convert_to(s, T)

expr(s)

Access Methods

size(s)

col2list(s, c, …)

append(s, row)

_concat(s, s1, …)

delCol(s, c)

delRow(s, r)

float(s)

has(s, e)

If e is a list or a set, then this method tests, whether at least one of its elements is among the entries of s.

_index(s, i, j)

Indexed calls such as s[i, j] call this method.

set_index(s, i, j, x)

This method is called by indexed assignments of the form s[i, j] := x.

map(s, f)

nops(s)

op(s, i)

op(s, [i, j])

subsop(s, i = newrow, …)

row2list(s, r, …)

Technical Methods

print(s)

fastprint(s)