# 2.13.2.1 Descriptive statistics

Origin provides several X-Functions to compute descriptive statistics, some of the most common are:

Name Brief Description
colstats Columnwise statistics
corrcoef
(Pro Only)
Correlation Coefficient
freqcounts Frequency counts of a data set.
mstats
(Pro Only)
Compute descriptive statistics on a matrix
rowstats Statistics of a row of data
stats Treat selected columns as a complete dataset; compute statistics of the dataset.

For a full description of each of these X-Functions and its inputs and outputs, please see the Descriptive Statistics.

## Descriptive Statistics on Columns and Rows

The colstats X-Function can perform statistics on columns. By default, it outputs the mean, the standard deviation, the number of data points and the median of each input column. But you can customize the output by assigning different values to the variables. In the following example, colstats is used to calculate the means, the standard deviations, the standard errors of the means, and the medians of four columns.

//Import a sample data with four columns
newbook;
fname$= system.path.program$ + "Samples\Statistics\nitrogen_raw.txt";
impasc;

//Perform statistics on column 1 to 4
colstats irng:=1:4 sem:=<new> n:=<none>;

The rowstats X-Function can be used in a similar way. The following example calculates the means of the active worksheet; the results are placed in a new added column at the first of the worksheet.

 Note: mean and sd are defaulted to be in output, if not needed, set to .
newbook;
fname$= system.path.program$ + "Samples\Statistics\engine.txt";
impasc; //Import a sample data

wunstackcol irng1:=1 irng2:=2; //Unstack columns
wtranspose type:=all ow:=<new>; //Transpose worksheet
range rr1 = 1:2;
delete rr1;
range rr2 = 2;
delete rr2; //delete empty columns
int nn = wks.ncols;
wks.col$(nn+1).lname$ = Mean;
wks.col$(nn+1).index = 2; //Add mean column wks.addcol(); wks.col$(nn+2).lname$= Sum; wks.col$(nn+2).index = 3; //Add sum column

//Row statistics to get sum and average, saved to corresponding column.
rowstats irng:=4[1]:end[end] sum:=3 mean:=2 sd:=<none>;

## Frequency Count

If you want to calculate the frequency counts of a range of data, use the freqcounts X-Function.

//Open a sample workbook
%a = system.path.program$+ "Samples\Statistics\Body.ogw"; doc -a %a; //Count the frequency of the data in column 4 freqcounts irng:=4 min:=35 max:=75 stepby:=increment intervals:=5; ## Correlation Coefficient corrcoef X-Function can be used to compute the correlation coefficient between two datasets. //import a sample data newbook; fname$ = system.path.program\$ + "Samples\Statistics\automobile.dat";
impasc;

//Correlation Coefficient
corrcoef irng:= (col(c):col(g)) rt:= <new name:=corr>