Differences between revisions 4 and 5
Revision 4 as of 2022-02-04 22:03:30
Size: 8638
Comment:
Revision 5 as of 2022-03-16 16:31:50
Size: 8776
Comment:
Deletions are marked like this. Additions are marked like this.
Line 37: Line 37:
The `ABS` function returns the absolute value of any numeric expression. The '''`ABS`''' function returns the absolute value of any numeric expression.
Line 45: Line 45:
The `ARSIN` function returns the inverse sine of any numeric expression. '''This value is not allowed to be greater than 1 or less than -1.''' The returned value is expressed in radians. The '''`ARSIN`''' function returns the inverse sine of any numeric expression. '''This value is not allowed to be greater than 1 or less than -1.''' The returned value is expressed in radians.
Line 53: Line 53:
The `ARTAN` function returns the inverse tangent of any numeric expression. The returned value is expressed in radians. The '''`ARTAN`''' function returns the inverse tangent of any numeric expression. The returned value is expressed in radians.
Line 61: Line 61:
The `CFVAR` function returns the coefficient of variance among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`CFVAR`''' function returns the coefficient of variance among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 71: Line 71:
The `COS` function returns the cosine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians. The '''`COS`''' function returns the cosine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.
Line 79: Line 79:
The `EXP` function returns `e` raised to the power of any numeric expression. The '''`EXP`''' function returns `e` raised to the power of any numeric expression.
Line 87: Line 87:
The `LG10` function returns the base-10 logarithm of any numeric expression. '''This value is not allowed to be 0 or less.''' The '''`LG10`''' function returns the base-10 logarithm of any numeric expression. '''This value is not allowed to be 0 or less.'''
Line 95: Line 95:
The `LN` function returns the natural logarithm of any numeric expression. '''This value is not allowed to be 0 or less.''' The '''`LN`''' function returns the natural logarithm of any numeric expression. '''This value is not allowed to be 0 or less.'''
Line 103: Line 103:
The `LNGAMMA` function returns the logarithm of the complete Gamma function of any numeric expression. '''This value is not allowed to be 0 or less.''' The '''`LNGAMMA`''' function returns the logarithm of the complete Gamma function of any numeric expression. '''This value is not allowed to be 0 or less.'''
Line 111: Line 111:
The `MAX` function returns the maximum value among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`MAX`''' function returns the maximum value among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 121: Line 121:
The `MIN` function returns the minimum value among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`MIN`''' function returns the minimum value among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 131: Line 131:
The `MEAN` function returns the average value among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`MEAN`''' function returns the average value among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 141: Line 141:
The `MEDIAN` function returns the median value among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`MEDIAN`''' function returns the median value among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 151: Line 151:
The `MOD` function returns the remainder from a division of any two numeric expressions. The first value is the dividend and the second is the divisor. '''The divisor is not allowed to be 0.''' The '''`MOD`''' function returns the remainder from a division of any two numeric expressions. The first value is the dividend and the second is the divisor. '''The divisor is not allowed to be 0.'''
Line 159: Line 159:
The `RANGE` function takes a variable and 1 or more pairs of low-high value pairs. It returns 1 for all cases with a value within the '''inclusive''' range of low to high. The '''`RANGE`''' function takes a variable and 1 or more pairs of low-high value pairs. It returns 1 for all cases with a value within the '''inclusive''' range of low to high.
Line 187: Line 187:
The `RND` function rounds any numeric expression to the nearest integer. In all cases, rounding ties are broken away from 0. The '''`RND`''' function rounds any numeric expression to the nearest integer. In all cases, rounding ties are broken away from 0.
Line 217: Line 217:
The `SD` function returns the standard deviation among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`SD`''' function returns the standard deviation among 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 227: Line 227:
The `SIN` function returns the sine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians. The '''`SIN`''' function returns the sine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.
Line 235: Line 235:
The `SQRT` function returns the square root of any numeric expression. '''This value is not allowed to be negative.''' The '''`SQRT`''' function returns the square root of any numeric expression. '''This value is not allowed to be negative.'''
Line 243: Line 243:
The `SUM` function returns the sum of 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`SUM`''' function returns the sum of 2 or more numeric expressions. '''Invalid values are ignored silently.'''
Line 253: Line 253:
The `TRUNC` function floors any numeric expression to the next integer toward 0. The '''`TRUNC`''' function floors any numeric expression to the next integer toward 0.
Line 279: Line 279:
The `UNIFORM` function selects from a random uniform distribution from 0 to N. Note that a random seed must be set first. The '''`UNIFORM`''' function selects from a random uniform distribution from 0 to N. Note that a random seed must be set first.
Line 297: Line 297:
The `VARIANCE` function returns the variance among 2 or more numeric expressions. '''Invalid values are ignored silently.''' The '''`VARIANCE`''' function returns the variance among 2 or more numeric expressions. '''Invalid values are ignored silently.'''

SPSS Numeric Functions

Apart from arithmetic operators, SPSS also offers a library of built-in numeric functions.

To clarify, these functions operate at case level. They do not perform higher-level computations.


General Syntax

Arguments

Most numeric functions take a singular argument. The exceptions are:

  • MOD (which takes 2 arguments)

  • RND and TRUNC (which has optional 2nd and 3rd arguments)

  • CFVAR, MAX, MEAN, MEDIAN, MIN, SD, SUM, and VARIANCE (which take 2 or more arguments)

For the statistical functions (i.e. CFVAR, MAX, MEAN, MEDIAN, MIN, SD, SUM, and VARIANCE), variable lists are also a valid way to specify the multiple arguments.

.N Suffix

Statistical functions (i.e. CFVAR, MAX, MEAN, MEDIAN, MIN, SD, SUM, and VARIANCE) silently ignore invalid values. One option for mitigation of programming errors is to require some number of the arguments be valid. These functions can all be called with a .N suffix that specifies this number.

CFVAR, SD, and VARIANCE each already require 2 valid values. All other statistical functions have an effective default of 1.


Abs

The ABS function returns the absolute value of any numeric expression.


Arsin

The ARSIN function returns the inverse sine of any numeric expression. This value is not allowed to be greater than 1 or less than -1. The returned value is expressed in radians.


Artan

The ARTAN function returns the inverse tangent of any numeric expression. The returned value is expressed in radians.


CfVar

The CFVAR function returns the coefficient of variance among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as CFVAR.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


Cos

The COS function returns the cosine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.


Exp

The EXP function returns e raised to the power of any numeric expression.


Lg10

The LG10 function returns the base-10 logarithm of any numeric expression. This value is not allowed to be 0 or less.


Ln

The LN function returns the natural logarithm of any numeric expression. This value is not allowed to be 0 or less.


LnGamma

The LNGAMMA function returns the logarithm of the complete Gamma function of any numeric expression. This value is not allowed to be 0 or less.


Max

The MAX function returns the maximum value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MAX.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Min

The MIN function returns the minimum value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MIN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Mean

The MEAN function returns the average value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MEAN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Median

The MEDIAN function returns the median value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MEDIAN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Mod

The MOD function returns the remainder from a division of any two numeric expressions. The first value is the dividend and the second is the divisor. The divisor is not allowed to be 0.


Range

The RANGE function takes a variable and 1 or more pairs of low-high value pairs. It returns 1 for all cases with a value within the inclusive range of low to high.

data list free / ID (F2) Score (F2).
begin data
1, 10, 2, 20, 3, 30, 4, 40, 5, 50, 6, 60, 7, 70, 8, 80, 9, 90
end data.
compute InRange=range(Score,30,40,70,80).
list all.

ID

Score

InRange

1

10

0

2

20

0

3

30

1

4

40

1

5

50

0

6

60

0

7

70

1

8

80

1

9

90

0


Rnd

The RND function rounds any numeric expression to the nearest integer. In all cases, rounding ties are broken away from 0.

If the optional second argument is specified, RND rounds to the nearest multiple of that value. This value is not allowed to be 0.

compute rounded_gpa = rnd(true_gpa, 0.1).

If the optional third argument is specified, the threshold for rounding up is lowered by N bits.

* Mathematically, CONST = 1.5.
* Per the 64-bit floating point number implementation, CONST = 1.499999999999998.
compute CONST = 9.62 - 5.82 - 9.21 + 6.91.

* This returns 1.
compute bad_round = rnd(CONST, 1, 0).

* This returns 2.
compute good_round = rnd(CONST, 1, 4).

If the third argument is not specified, RND defaults to the system setting for FIZZBITS (i.e. SET FIZZBITS 0.), which has defaulted to 6 since SPSS 17.


SD

The SD function returns the standard deviation among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as SD.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


Sin

The SIN function returns the sine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.


Sqrt

The SQRT function returns the square root of any numeric expression. This value is not allowed to be negative.


Sum

The SUM function returns the sum of 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as SUM.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Trunc

The TRUNC function floors any numeric expression to the next integer toward 0.

If the optional second argument is specified, TRUNC floors to the next multiple of that value. This value is not allowed to be 0.

If the optional third argument is specified, a threshold for rounding up by N bits is introduced.

* Mathematically, CONST = 1.5.
* Per the 64-bit floating point number implementation, CONST = 1.499999999999998.
compute CONST = 9.62 - 5.82 - 9.21 + 6.91.

* This returns 1.4.
compute bad_floor = rnd(CONST, 0.1, 0).

* This returns 1.5.
compute good_floor = rnd(CONST, 0.1, 5).

If the third argument is not specified, RND defaults to the system setting for FIZZBITS (i.e. SET FIZZBITS 0.), which has defaulted to 6 since SPSS 17.


Uniform

The UNIFORM function selects from a random uniform distribution from 0 to N. Note that a random seed must be set first.

Below is a demonstration for how an SRS sample can be drawn.

set seed=random.
compute rand=uniform(100000).
rank variables=rand /rank into rrand.
compute sample=0.
if (rrand le 200) sample=1.


Variance

The VARIANCE function returns the variance among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as VARIANCE.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


CategoryRicottone

SPSS/NumericFunctions (last edited 2023-06-10 13:00:34 by DominicRicottone)