RESTRICT directive

Defines a restricted set of units of vectors for subsequent statements.

 

No options

 

Parameters

VECTOR = vectors Vectors to be restricted
CONDITION = expression Logical expression defining the restriction for each vector; a zero (false) value indicates that the unit concerned is not in the set
SAVESET = variates List of the units in each restricted set
NULL = scalars Indicator for each restricted set, set to 1 or 0 according to whether or not it contains no units

 

Description

The RESTRICT directive defines a restriction on the units of a vector, so that future operations will involve only a subset of the units.

The VECTOR parameter specifies the vector or vectors that are to be restricted. These can be variates, factors or texts, but all the vectors listed must be of the same length.

The CONDITION parameter specifies a logical expression which indicates which units of the vectors are in the defined subset. For example,

VARIATE [VALUES=1,2,3,2,3,4,3,4,5] V

RESTRICT V; CONDITION=V.EQ.2

restricts the vector V to those units with the value 2. Genstat evaluates the expression to generate internally a variate of zeroes and ones, of the same length as the vectors being restricted. A zero value indicates that the corresponding unit is to be excluded. The logical expression can involve any vector of the same length as the vector to be restricted. For example, to restrict variate V and text T to the units with levels 1 or 2 or 4 of factor F, you could use the statement

RESTRICT V,T; CONDITION=(F.LE.2).OR.(F.EQ.4)

When using a text to define a restriction, remember that you cannot use logical operators like .EQ. and .NE. Instead you should use operators .IN., .NI., .EQS. and .NES.:

TEXT [VALUES=London,Madrid,Nairobi,Ottawa,Paris,Quito,Rome]\

     City

& [VALUES=London,Madrid,Paris,Rome] Europe

RESTRICT City; CONDITION=City.IN.Europe

restricts the text City to lines 1, 2, 5 and 7 only.

Of course, the expression may just contain a single variate of the of the same length as the vectors to be restricted. Again a zero indicates that the corresponding unit in the vector to be restricted is excluded, while any non-zero entry causes inclusion. Thus the restriction above on the text City could also be specified by

RESTRICT T; CONDITION=!(1,1,0,0,1,0,1)

The same effect can be achieved by using the EXPAND function:

RESTRICT City; CONDITION=EXPAND(!(1,2,5,7))

Another function that may be useful is RESTRICTION; this lets you generate a variate of ones and zeros indicating the units to which a vector is currently restricted. It thus provides a very convenient way of transferring a restriction from one vector to another. For example,

RESTRICT Timezone,Distance; CONDITION=RESTRICTION(City)

restricts the vectors Timezone and Distance to the same units as those to which City is currently restricted.

Finally, if you omit the CONDITION parameter, this removes any restrictions on the vectors are removed. For example

RESTRICT City,Timezone,Distance

removes any restrictions that have been set on City, Timezone and Distance.

Note that if the vectors used in the CONDITION expression are themselves restricted these restrictions will remain in force during the current calculation of the condition. A danger here, therefore, is that you may accidentally end up restricting out all the elements of a vector by using RESTRICT repeatedly. The safest way to avoid this is to remove the restrictions on any vectors to be used in the CONDITION expression before you use them to restrict vectors in some different way.

The SAVESET parameter can be used to save the numbers of the units that are in the restricted set. These are saved in a variate with one value for each unit retained by the restriction. Thus, if the example above with variate V were to become

VARIATE [VALUES=1,2,3,2,3,4,3,4,5] V

RESTRICT V; CONDITION=V.EQ.2; SAVESET=S

S would be created as a variate of length 2, with values 2 and 4.

The NULL parameter can specify a list of scalars, one for each vector in the VECTOR list, that will be set to one if its restricted set contains no units; otherwise it is set to zero. Also, when NULL set, RESTRICT suppresses the warnings that it normally gives if a restricted set is null.

Not all directives take account of RESTRICT. For those that do, usually only one vector in the list of parameters has to be restricted for the directive to treat them all as being restricted in the same way. A fault is reported if any vectors in such a list are restricted in different ways.

Options: none.

Parameters: VECTOR, CONDITION, SAVESET.

 

See also

Directives: EXPRESSION, CALCULATE.

Procedures: FRESTRICTEDSET, SUBSET.

Commands for: Calculations and manipulation.

Example

" Example FIT-1: Simple linear regression

  Modelling the relationship between counts of apples from 12 trees
  (recorded as 100s of fruit) and percentage damage by codling moth.
  (Snedecor & Cochran, Statistical analysis, 1980, p162.)"

VARIATE [VALUES= 8, 6,11,22,14,17,18,24,19,23,26,40] Cropsize
&       [VALUES=59,58,56,53,50,45,43,42,39,38,30,27] Wormy
DGRAPH  Wormy; Cropsize

" It is expected that the larger the crop is the less the damage will be,
  since the density of the flying moths is unrelated to the crop size.
  Try fitting a linear model relating the percentage of damage directly
  to the size of the crop."
MODEL Wormy
FIT Cropsize

" Tree number 4 seems different from the rest: perhaps it was not
  adequately protected by the standard spraying programme, or was on the
  side from which the codling moths flew in to the orchard.
  Tree number 12 has a much larger crop than the rest: the results of the
  regression are strongly influenced by this one observation.
  Display all the fitted values, residuals and leverages (influence)."
RDISPLAY [PRINT=fittedvalues]

" Check the effect of omitting tree number 4."
RESTRICT Wormy; .NOT.EXPAND(4; 12)
FIT [PRINT=summary] Cropsize

" Return to the complete dataset, and display the fitted line."
RESTRICT Wormy
FIT [PRINT=*] Cropsize
RGRAPH [GRAPHICS=high]

" Plot the fitted values against the residuals, to check that the
  variance is roughly constant; use the procedure RCHECK from the
  Genstat Procedure Library."
RCHECK [GRAPHICS=high] residual; fittedvalues
Updated on January 16, 2018

Was this article helpful?