1. Home
  2. MARGIN directive

MARGIN directive

Forms and calculates marginal values for tables.

Option

CLASSIFICATION = factors Factors classifying the margins to be formed; default * requests all margins to be formed

Parameters

OLDTABLE = tables Tables from which the margins are to be taken or calculated
NEWTABLE = tables New tables formed with margins
METHOD = string tokens Way in which the margins are to be formed for each table (totals, means, minima, maxima, variances, medians, deletion, or a null string to indicate that the marginal values are all to be set to the missing value); default tota

Description

You can use MARGIN to extend a table to contain marginal values, or to change the marginal values of a table that already has margins, or to delete the margins from a table. The tables whose margins are to be changed are specified by the OLDTABLE parameter. If you specify only this parameter, the new values replace those of the original tables. However, if you want to retain the original values, you can specify new tables to contain the amended values, using the NEWTABLE list. These tables will be declared automatically, if you have not declared them already.

The METHOD parameter controls the type of margins that are formed. If you set METHOD=deletion, all the margins of the tables are deleted but the body of the table is retained.

The CLASSIFICATION option specifies the list of factors for which you want to form marginal values. Genstat puts missing values in the margins that are excluded if the METHOD parameter is set to maxima or minima; for other settings of METHOD, Genstat puts in zeroes. The classifying sets for each table can be different, but all the factors in the CLASSIFICATION option must be in the classifying sets of each OLDTABLE.

Option: CLASSIFICATION.

Parameters: OLDTABLE, NEWTABLE, METHOD.

See also

Directives: TABLE, TABULATE, COMBINE.

Commands for: Calculations and manipulation.

Example

" Example COMB-1: Use of the COMBINE directive"

TEXT    [VALUES=Birmingham,London,Liverpool,Leeds,Manchester,Sheffield,\ 
        Cardiff,Newport,Swansea,Aberdeen,Dundee,Edinburgh,Glasgow] Townname
VARIATE [VALUES=1977,1978,1979,1980,1981,1982] Yearnum
FACTOR  [LABELS=Townname] Town
FACTOR  [LEVELS=Yearnum]  Year
TABLE   [CLASSIFICATION=Town,Year] Sales
READ Sales
618 601 784 720 863 921     1466 1502 1201 1773 1948 1910 
816 859 820 938 1007 1158   461 479 452 536 510 548 
662 632 758 721 893 837     531 569 615 624 607 593 
757 743 785 816 783 737     294 303 346 377 368 351 
416 461 478 462 497 520     608 635 672 692 685 723 
343 391 358 366 418 470     714 751 710 763 788 830
916 922 956 988 970 1004    :

" put the sales figures into a table classified by country and year "
TEXT   [VALUES=England,Wales,Scotland] Cname
FACTOR [LABELS=Cname] Country
TABLE  [CLASSIFICATION=Country,Year] Csales
COMBINE [OLDSTRUCTURE=Sales;NEWSTRUCTURE=Csales]\ 
    OLDDIMENSION=Town ; NEWDIMENSION=Country ;\ 
    NEWPOSITIONS=!T(6('England'),3('Wales'),4('Scotland')) 
PRINT Sales & Csales

" put the sales figures into a table classified by country & year with 
  2-yearly totals "
TEXT   [VALUES='1977','1978','1977-78','1979','1980','1979-80',\ 
               '1981','1982','1981-82'] Ytnam
FACTOR [LABELS=Ytnam] Yearsums
TABLE  [CLASSIFICATION=Yearsums,Country] Salesum
COMBINE [OLDSTRUCTURE=Sales;NEWSTRUCTURE=Salesum]\ 
    OLDDIMENSION=Town,Year ; NEWDIMENSION=Country,Yearsums ;\ 
    OLDPOSITIONS=*,!V((1977...1982)2) ;\ 
    NEWPOSITIONS=!T(6('England'),3('Wales'),4('Scotland')),\
                 !T('1977','1978','1979','1980','1981','1982',\ 
                    2('1977-78','1979-80','1981-82'))
PRINT Salesum

" add margins of totals to Salesum "
MARGIN Salesum
PRINT Salesum

" use COMBINE to correct the margins for the Yearsum dimension " 
COMBINE [OLDSTRUCTURE=Salesum; NEWSTRUCTURE=Salesum]\ 
    OLDDIMENSION=Yearsums; NEWDIMENSION=Yearsums;\ 
    OLDPOSITIONS=!(1...9,3,6,9);\ 
    NEWPOSITIONS=!(1...9,*,*,*)
PRINT Salesum
MATRIX [ROWS=4;COLUMNS=5;VALUES=101...120] Fullmat

" form a matrix containing the transpose of the last 3 rows & columns "
COMBINE [OLDSTRUCTURE=Fullmat;NEWSTRUCTURE=Subtrans]\ 
    OLDDIMENSION=1,2 ; NEWDIMENSION=2,1 ;\ 
    OLDPOSITIONS=!(2...4),!(3...5) ; NEWPOSITIONS=!(3...1)
PRINT Fullmat & Subtrans
Updated on March 7, 2019

Was this article helpful?