transform(deprecated)/apply - Help

stats[transform, apply]

apply a function to each item of a statistical list

 Calling Sequence stats[transform, apply[fctn]](data) transform[apply[fctn]](data)

Parameters

 fctn - function data - statistical list

Description

 • Important: The stats package has been deprecated. Use the superseding package Statistics instead.
 • The function apply of the subpackage stats[transform, ...] applies the requested function to the given data.
 • It is much easier to analyze the relationship between two sets of data when the relationship is linear. It may very well be, though, that the relationship is not linear. For example, one set of data could be made of points that are the square of the corresponding points in the other set of data. In that case, a linear relation is obtained between the square root of the first set and the original second set. The map() function can be useful in that regard, but it does not behave correctly with respect to weighted data, classes and missing data. The apply() function handles correctly the various stats data types.
 • Another common use of data transformation is to make the distribution more symmetric. This makes it easier to do the comparison with theoretical distributions such as the normal distribution. Transformations such as raising to a power greater than one increases the skewness to the right (in other words spreads the data towards the right), whereas a power lower than one increases the skewness to the left (the data is spread towards the left). Refer to describe[skewness] for more information on the skewness.
 • The requested function is applied at each boundary points of classes. To ensure correct subsequent results, the requested function must preserve the order of the boundary points. For example, the transformation $\mathrm{expr}$ does not preserve the order; therefore, the transformation $\mathrm{expr}$ is preferred.
 • The functions transform[divideby] and transform[remove] are specialized versions of transform[apply]. They might be more appropriate to your particular requirements.
 • Missing items remain unchanged.

Examples

Important: The stats package has been deprecated. Use the superseding package Statistics instead.

 > $\mathrm{with}\left(\mathrm{stats}\right):$

First set of data

 > $\mathrm{data1}≔\left[1,4,9,16,25\right]$
 ${\mathrm{data1}}{:=}\left[{1}{,}{4}{,}{9}{,}{16}{,}{25}\right]$ (1)

skew to the left

 > $\mathrm{transform}[\mathrm{apply}[x→\sqrt{x}]]\left(\mathrm{data1}\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}\right]$ (2)

Second set of data

 > $\mathrm{data2}≔\left[1,\sqrt{2},\sqrt{3},2\right]:$$\mathrm{evalf}\left(\right)$
 $\left[{1.}{,}{2.}{,}{3.}{,}{4.}{,}{5.}\right]$ (3)

skew to the right

 > $\mathrm{transform}[\mathrm{apply}[x→{x}^{2}]]\left(\mathrm{data2}\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}\right]$ (4)

with weighted data and classes.

 > $\mathrm{data3}≔\left[\mathrm{Weight}\left(3,10\right),\mathrm{missing},4,\mathrm{Weight}\left(11..12,3\right)\right]$
 ${\mathrm{data3}}{:=}\left[{\mathrm{Weight}}{}\left({3}{,}{10}\right){,}{\mathrm{missing}}{,}{4}{,}{\mathrm{Weight}}{}\left({11}{..}{12}{,}{3}\right)\right]$ (5)
 > $\mathrm{transform}[\mathrm{apply}[x→-\frac{1}{x}]]\left(\mathrm{data3}\right)$
 $\left[{\mathrm{Weight}}{}\left({-}\frac{{1}}{{3}}{,}{10}\right){,}{\mathrm{missing}}{,}{-}\frac{{1}}{{4}}{,}{\mathrm{Weight}}{}\left({-}\frac{{1}}{{11}}{..}{-}\frac{{1}}{{12}}{,}{3}\right)\right]$ (6)

Here are two sets of data which are not in linear relationship.

 > $\mathrm{data4}≔\left[0,1,3,7\right]$
 ${\mathrm{data4}}{:=}\left[{0}{,}{1}{,}{3}{,}{7}\right]$ (7)
 > $\mathrm{data5}≔\left[1,8,64,512\right]$
 ${\mathrm{data5}}{:=}\left[{1}{,}{8}{,}{64}{,}{512}\right]$ (8)

However, taking the cube root of data5 gives a linear relationship with data4.

Compare

 > $\mathrm{transform}[\mathrm{apply}[x→x+1]]\left(\mathrm{data4}\right)$
 $\left[{1}{,}{2}{,}{4}{,}{8}\right]$ (9)

with

 > $\mathrm{transform}[\mathrm{apply}[x→\mathrm{simplify}\left({x}^{\frac{1}{3}}\right)]]\left(\mathrm{data5}\right)$
 $\left[{1}{,}{2}{,}{4}{,}{8}\right]$ (10)