### B.9 Statistical functions, summing, rounding & sorting

The following statemens are used to summarize, sum, round or sort the data contained in a matrix or dataset.

 Syntax Arguments and performed function W = mean(X $\left[$, d$\right]$); W is a matrix with entries equal to the sample mean of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the mean is computed. The default value for d is 1, for which the mean is calculated over rows. W = var(X $\left[$, d$\right]$); W is a matrix with entries equal to the sample variance of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the mean is computed. The default value for d is 1, for which the variance is calculated over rows. W = sd(X $\left[$, d$\right]$); W is a matrix with entries equal to the sample standard deviation of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the standard deviation is computed. The default value for d is 1, for which the standard deviation is calculated over rows. W = min(X $\left[$, d$\right]$); W is a matrix with entries equal to the minimum of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the minimum is computed. The default value for d is 1, for which the minimum is calculated over rows. W = max(X $\left[$, d$\right]$ ); W is a matrix with entries equal to the maximum of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the maximum is computed. The default value for d is 1, for which the maximum is calculated over rows. W = median(X $\left[$ ,d$\right]$); W is a matrix with entries equal to the median of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the median is computed. The default value for d is 1, for which the median is calculated over rows. W = tabulate(v $\left[$ ,m$\right]$); W is a matrix that contains information on the distribution of the values in vector v. W has three columns: the ﬁrst column contains the unique values of v, sorted from smallest to largest the second column lists the number of times each corresponding unique value in the ﬁrst column appears in v the third column lists the number of entries in v smaller than or equal to the corresponding value in the ﬁrst column (cumulative sum of the second column) m is an optional argument, specifying the maximum number of unique values in v beyond which an error is produced. v must be a vector or a dataset with a single row or column m must a positive integer. The default value for m is 20. W = cov(X $\left[$, d$\right]$ ); W is the sample covariance matrix of the variables contained in X, with the variables organized across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension according to which the variables in X are organized. The default value for d is 1, in which case each column of X is treated as a variable. W = corr(X $\left[$, d$\right]$ ); W is the sample correlation matrix of the variables contained in X, with the variables organized across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension according to which the variables in X are organized. The default value for d is 1, in which case each column of X is treated as a variable. W = ceil(X); W is a matrix with dimensions equal to those of X and entries obtained by rounding oﬀ the entries of X upwards to the nearest integer. The function works element-wise. X must be a matrix or dataset W = ﬂoor(X); W is a matrix with dimensions equal to those of X and entries obtained by rounding oﬀ the entries of X downwards to the nearest integer. The function works element-wise. X must be a matrix or dataset W = round(X); W is a matrix with dimensions equal to those of X and entries obtained by rounding oﬀ the entries of X to the nearest integer. The function works element-wise. X must be a matrix or dataset W = sort(X  $\left[$, d$\right]$); W is a matrix with dimensions equal to those of X and entries obtained by sorting, in ascending order, the values of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the sorting should be done. The default value for d is 1, for which the entries of each column of X are sorted in ascending order. see also sortrows and sortd W = sortrows(X  $\left[$, d$\right]$); W is a matrix with dimensions equal to those of X and entries obtained by sorting the rows of X, in ascending order, according to the values contained in the columns, the indices of which are provided in vector d. X must be a matrix or dataset d must be vector of integers with maximum value not greater than the number of columns of X. The default value for d is 1, for which the rows of of X are sorted in ascending order according to the values contained in the ﬁrst column. If d contains more than one index, then the rows of X are sorted ﬁrst according to the ﬁrst index, and in case of duplicate values in the respective column, according to second index, and so on. see also sort and sortd W = sum(X  $\left[$, d$\right]$); W is a matrix with entries equal to the sum of the entries of X across dimension d. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the sum is computed. The default value for d is 1, for which the sum is calculated over rows. W = logsumexp(X  $\left[$, d$\right]$); W is a matrix with entries equal to the logarithm of the sum of the exponential of the entries of X across dimension d: ${\mathtt{W}}_{j}=log{\sum }_{i}exp\left\{{\mathtt{X}}_{ij}\right\}$ when d is one (or not provided). The function is provided to guard against overﬂow when calculating quantities of this form, which appear frequently in the calculation of log-marginal likelihoods. X must be a matrix or dataset d must be either 1 or 2, indicating the dimension across which the sum is computed. The default value for d is 1, for which the sum is calculated over rows.