Defines a restricted set of units of vectors for subsequent statements.
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
RESTRICT directive defines a restriction on the units of a vector, so that future operations will involve only a subset of the units.
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.
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
.NE. Instead you should use operators
& [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
RESTRICT City; CONDITION=EXPAND(!(1,2,5,7))
Another function that may be useful is
RESTRICTION; this allows you to 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
Distance to the same units as those to which
City is currently restricted.
removes any restrictions that have been set on
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.
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.
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
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.
Commands for: Calculations and manipulation.
" 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