Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# stats::moment

The K-th moment of a data sample

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```stats::moment(k, X, x1, x2, …)
stats::moment(k, X, [x1, x2, …])
stats::moment(k, X, s, <c>)
```

## Description

stats::moment(k, X, [x1, x2, …, xn]) returns the k-th moment

of the data xi centered around X.

If k is an integer, rational or float, and all data X, x1, x2, … are floating-point numbers, then the moment is returned as a floating-point number. For symbolic data, a symbolic expression is returned.

The column index c is optional if the data are given by a stats::sample object containing only one non-string column.

External statistical data stored in an ASCII file can be imported into a MuPAD® session via import::readdata. In particular, see Example 1 of the corresponding help page.

## Environment Interactions

The function is sensitive to the environment variable DIGITS which determines the numerical working precision.

## Examples

### Example 1

We calculate the third moment of some data centered around 0:

`stats::moment(3, 0, 2, 33/7, 21/9, PI)`

Alternatively, the data may be passed as a list:

`data := [2, 33/7, 21/9, PI]: stats::moment(3, 0, data)`

If all data are floating-point numbers, the result is a float:

`data := float(data): stats::moment(3, 0, data)`

We use stats::moment to compute the variance of the data:

```m := stats::mean(data):
stats::moment(2, m, data) = stats::variance(data, Population)```

`delete data, m:`

### Example 2

We create a sample of type stats::sample:

`s := stats::sample([[22, 4, 1], [9, 8/3, 1], [0.1, 2, 3]])`
``` 22    4  1
9  8/3  1
0.1    2  3
```

The fourth moment around a symbolic center X is computed for all columns in the sample:

`stats::moment(4, X, s, i) \$ i = 1..3`

`delete s:`

### Example 3

For symbolic arguments, the moment is returned as a symbolic expression:

`stats::moment(k, X, [x1, x2, x3, x4])`

## Parameters

 k X The center: an arithmetical expression x1, x2, … The statistical data: arithmetical expressions s A sample of domain type stats::sample c A column index of the sample s: a positive integer. This column provides the data x1, x2, ….