SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 2 Vol 1

RANK2

Name:
    RANK2 (LET)
Type:
    Let Subcommand
Purpose:
    Rank the elements of a response variable when there are one, two, or three group-id variables.
Description:
    The RANK command is used to rank a response variable. However, there may be cases where you want to rank the data withing groups. The RANK2, RANK3, and RANK4 commands let you perform the ranking for the cases with one, two, or three group-id variables, respectively.

    Nonparameteric analysis is often based on ranked data rather than the original data. This command may be helpful in implementing nonparameteric methods that are not directly supported by Dataplot.

Syntax 1:
    LET <y2> = RANK2 <y1> <x1>
                            <SUBSET/EXCEPT/FOR qualification>
    where <y1> is a response variable to be ranked;
                <x1> is a group-id variable;
                <y2> is a variable where the ranked <y1> values are saved;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax is used for the case where we are ranking based on one group-id variable.

Syntax 2:
    LET <y2> = RANK2 <y1> <x1> <x2>
                            <SUBSET/EXCEPT/FOR qualification>
    where <y1> is a response variable to be ranked;
                <x1> is the first group-id variable;
                <x2> is the second group-id variable;
                <y2> is a variable where the ranked <y1> values are saved;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax is used for the case where we are ranking based on two group-id variables.

Syntax 3:
    LET <y2> = RANK2 <y1> <x1> <x2> <x3>
                            <SUBSET/EXCEPT/FOR qualification>
    where <y1> is a response variable to be ranked;
                <x1> is the first group-id variable;
                <x2> is the second group-id variable;
                <x3> is the third group-id variable;
                <y2> is a variable where the ranked <y1> values are saved;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax is used for the case where we are ranking based on three group-id variables.

Examples:
    LET Y2 = RANK2 Y X1
    LET Y2 = RANK2 Y X1 X2
    LET Y2 = RANK2 Y X1 X2 X3
    LET Y2 = RANK2 Y X1 SUBSET X1 > 2
Note:
    The response values are ranked in ascending order.
Note:
    The groups in the data do not need to be pre-sorted or contiguous. The ranked response variable will be in the same order as the original response variable (i.e., the groups are not sorted on output).

    If you want to extract the rankings for a specific group, you can do something like the following

      LET Y2 = RANK3 Y X1 X2 LET ZY2 = Y2 LET ZY = Y RETAIN ZY2 ZY SUBSET X1 =2 SUBSET X2 = 3
Default:
    None
Synonyms:
    None
Related Commands:
    RANK = Rank the elements of a variable.
    SORT = Sort the elements of a variable.
    SORTC = Sort the elements of a variable and carry one or more variables along.
    COCODE = Generate a cocoded variable.
    CODE = Generate a coded variable.
    SEQUENCE = Generate a sequence of numbers.
    PATTERN = Generate numbers with a specific pattern.
Applications:
    Data Management
Implementation Date:
    2008/12
Program 1:
     
    skip 25
    read gear.dat y x
    .
    let x2 y2 = rank2 x y
    .
    set write decimals 3
    print x y x2 y2
        
    The following output is generated.
     VARIABLES--X              Y              Y2      
    
              1.000          1.006         10.000
              1.000          0.996          4.000
              1.000          0.998          5.000
              1.000          1.000          7.500
              1.000          0.992          1.000
              1.000          0.993          2.000
              1.000          1.002          9.000
              1.000          0.999          6.000
              1.000          0.994          3.000
              1.000          1.000          7.500
              2.000          0.998          4.500
              2.000          1.006          9.500
              2.000          1.000          6.500
              2.000          1.002          8.000
              2.000          0.997          3.000
              2.000          0.998          4.500
              2.000          0.996          2.000
              2.000          1.000          6.500
              2.000          1.006          9.500
              2.000          0.988          1.000
              3.000          0.991          2.000
              3.000          0.987          1.000
              3.000          0.997          7.000
              3.000          0.999          8.500
              3.000          0.995          4.000
              3.000          0.994          3.000
              3.000          1.000         10.000
              3.000          0.999          8.500
              3.000          0.996          5.500
              3.000          0.996          5.500
              4.000          1.005         10.000
              4.000          1.002          8.500
              4.000          0.994          1.500
              4.000          1.000          7.000
              4.000          0.995          3.000
              4.000          0.994          1.500
              4.000          0.998          6.000
              4.000          0.996          4.500
              4.000          1.002          8.500
              4.000          0.996          4.500
              5.000          0.998          8.500
              5.000          0.998          8.500
              5.000          0.982          2.000
              5.000          0.990          4.000
              5.000          1.002         10.000
              5.000          0.984          3.000
              5.000          0.996          6.500
              5.000          0.993          5.000
              5.000          0.980          1.000
              5.000          0.996          6.500
              6.000          1.009          8.500
              6.000          1.013         10.000
              6.000          1.009          8.500
              6.000          0.997          5.000
              6.000          0.988          2.000
              6.000          1.002          7.000
              6.000          0.995          3.000
              6.000          0.998          6.000
              6.000          0.981          1.000
              6.000          0.996          4.000
              7.000          0.990          1.000
              7.000          1.004          8.000
              7.000          0.996          2.500
              7.000          1.001          6.000
              7.000          0.998          4.000
              7.000          1.000          5.000
              7.000          1.018         10.000
              7.000          1.010          9.000
              7.000          0.996          2.500
              7.000          1.002          7.000
              8.000          0.998          3.500
              8.000          1.000          5.500
              8.000          1.006          9.500
              8.000          1.000          5.500
              8.000          1.002          7.500
              8.000          0.996          1.500
              8.000          0.998          3.500
              8.000          0.996          1.500
              8.000          1.002          7.500
              8.000          1.006          9.500
              9.000          1.002          8.000
              9.000          0.998          5.500
              9.000          0.996          3.500
              9.000          0.995          2.000
              9.000          0.996          3.500
              9.000          1.004          9.500
              9.000          1.004          9.500
              9.000          0.998          5.500
              9.000          0.999          7.000
              9.000          0.991          1.000
             10.000          0.991          2.500
             10.000          0.995          5.000
             10.000          0.984          1.000
             10.000          0.994          4.000
             10.000          0.997          7.000
             10.000          0.997          7.000
             10.000          0.991          2.500
             10.000          0.998          9.000
             10.000          1.004         10.000
             10.000          0.997          7.000
        
Program 2:
     
    skip 25
    read ripken.dat y x1 x2 x3 x4
    .
    let y2 = rank3 y x1 x2
    .
    set write decimals 3
    print x1 x2 y y2
        
    The following output is generated.
     VARIABLES--X1             X2             Y              Y2      
    
              1.000          1.000          0.400          4.000
              1.000          2.000          0.354          2.000
              1.000          3.000          0.388          4.000
              2.000          1.000          0.380          4.000
              2.000          2.000          0.409          2.000
              2.000          3.000          0.391          3.000
              3.000          1.000          0.136          2.000
              3.000          2.000          0.322          4.000
              3.000          3.000          0.304          3.000
              1.000          1.000          0.166          1.500
              1.000          2.000          0.333          1.000
              1.000          3.000          0.000          1.000
              2.000          1.000          0.300          1.500
              2.000          2.000          0.875          4.000
              2.000          3.000          1.000          4.000
              3.000          1.000          0.166          4.000
              3.000          2.000          0.090          1.000
              3.000          3.000          0.333          4.000
              1.000          1.000          0.382          3.000
              1.000          2.000          0.373          4.000
              1.000          3.000          0.223          2.000
              2.000          1.000          0.333          3.000
              2.000          2.000          0.350          1.000
              2.000          3.000          0.304          2.000
              3.000          1.000          0.086          1.000
              3.000          2.000          0.280          3.000
              3.000          3.000          0.218          2.000
              1.000          1.000          0.166          1.500
              1.000          2.000          0.363          3.000
              1.000          3.000          0.333          3.000
              2.000          1.000          0.300          1.500
              2.000          2.000          0.454          3.000
              2.000          3.000          0.285          1.000
              3.000          1.000          0.162          3.000
              3.000          2.000          0.211          2.000
              3.000          3.000          0.000          1.000
        

Date created: 12/4/2008
Last updated: 12/4/2008
Please email comments on this WWW page to alan.heckert@nist.gov.