1. Home
  2. SETRELATE directive

SETRELATE directive

Compares the distinct values contained in two data structures.

Options

FREPRESENTATION = string token How to represent factors in a comparison between two factors (levels, labels, ordinals); default leve
LFACTORIAL = scalar Limit on number of factors or variates in the terms formed from a LEFT formula; default * i.e. none
RFACTORIAL = scalar Limit on number of factors or variates in the terms formed from a RIGHT formula; default * i.e. none
TOLERANCE = scalar Tolerance to use when comparing numerical values; default 10-6
SUBSTITUTE = string token Whether to substitute dummies within LEFT or RIGHT pointers and formulae (yes, no); default no

Parameters

LEFT = identifiers First structures in each comparison
RIGHT = identifiers Second structures in each comparison
CONTAINS = scalars Returns 1 or 0 according to whether or not LEFT contains RIGHT
EQUALS = scalars Returns 1 or 0 according to whether or LEFT and RIGHT contain exactly the same distinct set of items
INCLUDEDIN = scalars Returns 1 or 0 according to whether or not LEFT is included in RIGHT
DISTINCT = scalars Returns 1 or 0 according to whether or not LEFT and RIGHT are distinct

Description

SETRELATE can compare the distinct values of any numerical structure (scalar, variate, table, matrix, diagonal matrix or symmetric matrix) with another numerical structure or with a factor. It can compare a factor either with another factor, or with a variate or a text. It can compare a text with another text, or two pointers. Finally, it can compare two formulae.

The LEFT and RIGHT parameters specify the structures to compare. The other parameters provide the results of the comparison as scalars containing the values 0 or 1. CONTAINS is set to 1 if the LEFT structure contains every (distinct) value in the RIGHT structure. EQUALS returns 1 if the sets of distinct values in the LEFT and RIGHT structures are identical. INCLUDEDIN equals 1 if the RIGHT structure contains every (distinct) values in the LEFT structure. DISTINCT equals 1 if the LEFT and RIGHT structures are have a null intersection, i.e. they have no values in common.

When comparing two factors, the FREPRESENTATION option specifies whether to use levels, labels or ordinal values. (The ordinal values are formed representing the levels, in numerical order, by the numbers 1, 2 and so on.) By default levels are used.

When comparing pointers and formulae, the SUBSTITUTE option controls whether any dummies that they contain are substituted by the data stuctures to which they point, before the comparison is made. Note, if any of those data structures is a dummy, it too is replaced, and so on until we reach a data structure that is not a dummy. However, if the original dummy (or any of the dummies to which it points) is unset, the original dummy is retained.

The LFACTORIAL and RFACTORIAL options can be used to set a limit on number of factors or variates in the terms formed from a LEFT or RIGHT formula, respectively; by default there are no limits.

The TOLERANCE option defines the tolerance to be used when comparing numbers. The default value 10-6 should be suitable, however, unless the numbers are very small.

Options: FREPRESENTATION, LFACTORIAL, RFACTORIAL, TOLERANCE, SUBSTITUTE.

Parameters: LEFT, RIGHT, CONTAINS, EQUALS, INCLUDEDIN, DISTINCT.

Action with RESTRICT

SETRELATE ignores any restrictions on LEFT or RIGHT vectors.

See also

Directives: SETALLOCATIONS, SETCALCULATE, SET2FORMULA, CALCULATE.

Commands for: Calculations and manipulation.

Example

" Examples 1:4.3.2 and 1:4.3.3 "
" Examinations passed by three students "
TEXT Jim,Kim,Tim; VALUES=\
     !t(Art,English,French,Geography,History,\
        'Information technology',Maths,Music,Science,Spanish),\
     !t('Business studies',English,French,Geography,History,\
        Maths,Music,'Resistant materials',Science,Spanish),\
     !t('Business studies',English,French,Geography,History,\
        'Resistant materials')

" Compare Jim with Kim: neither set of exams is a subset of the other"
SETRELATE Jim; Kim; CONTAINS=Kim_subset_of_Jim;\
          EQUALS=Jim_same_as_Kim; INCLUDEDIN=Jim_subset_of_Kim
PRINT     [ORIENTATION=across; RLWIDTH=20]\
          Kim_subset_of_Jim,Jim_same_as_Kim,Jim_subset_of_Kim;\
          DECIMALS=0

" but Tim's exams are a subset of Kim's."
SETRELATE Kim; Tim; CONTAINS=Tim_subset_of_Kim;\
          EQUALS=Kim_same_as_Tim; INCLUDEDIN=Kim_subset_of_Tim
PRINT     [ORIENTATION=across; RLWIDTH=20]\
          Tim_subset_of_Kim,Kim_same_as_Tim,Kim_subset_of_Tim;\
          DECIMALS=0

" All exams passed by any of the students "
SETCALCULATE All_exams = Jim .OR. Kim .OR. Tim
PRINT        All_exams; JUSTIFICATION=left

" Exams passed by both Jim and Kim "
SETCALCULATE Jim_and_Kim = Jim .AND. Tim
PRINT        Jim_and_Kim; JUSTIFICATION=left

" Exams passed by Kim but not Tim "
SETCALCULATE Kim_not_Tim = Kim - Tim
PRINT        Kim_not_Tim; JUSTIFICATION=left

" Exams passed by only one student "
SETCALCULATE One_student = (Jim - (Kim .OR. Tim))\
                      .OR. (Kim - (Jim .OR. Tim))\
                      .OR. (Tim - (Jim .OR. Kim))
PRINT        One_student; JUSTIFICATION=left
Updated on March 5, 2019

Was this article helpful?