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

SEQUENTIAL DIFFERENCE

Name:
    SEQUENTIAL DIFFERENCE (LET)
Type:
    Let Subcommand
Purpose:
    Compute the sequential differences (i.e., X(I) - X(I-1)) between the elements of a variable.
Description:
    Given a data series with N points, the sequential difference will contain the points

               Y(1) = X(2) - X(1)
               Y(2) = X(3) - X(2)
                    ...
               Y(N-1) = X(N) - X(N-1)
               

    If there are less than two points in the series, nothing will be done.

    One use of sequential differencing is to remove trend from time series data.

    The 2016/02 version of Dataplot generalized this command in the following two ways.

    1. In additon to the difference, the following additional sequential values can also be computed:

        SEQUENTIAL SUM - X(I) + X(I-1)
        SEQUENTIAL PRODUCT - X(I) * X(I-1)
        SEQUENTIAL MEAN - (X(I) + X(I-1))/2
        SEQUENTIAL MINIMUM - MIN(X(I), X(I-1))
        SEQUENTIAL MAXIMUM - MAX(X(I), X(I-1))
        SEQUENTIAL LOWER - X(I-1)
        SEQUENTIAL UPPER - X(I)

    2. A group-id variable can be included. That is, the data values in each group will differenced. If there are K groups, then the differenced series will have N - K points.

      The original data series does not have to be sorted by group. However, the output series will be sorted as follows:

      • The data will be sorted by group in the order that the groups are detected in the original series.

      • Within a group, the order in the output series will be based on the order of the input series.

      For example, if X is the group-id variable and Y is the response variable

        X(1) = 1
        X(2) = 2
        X(3) = 3
        X(4) = 1
        X(5) = 2
        X(6) = 3
        X(7) = 1
        X(8) = 2
        X(9) = 3

      then the output group-id variable (X2) and differenced variable will be in the order

        X2(1) = 1,   Y2(1) = Y(4) - Y(1)
        X2(2) = 1,   Y2(2) = Y(7) - Y(4)
        X2(3) = 2,   Y2(3) = Y(5) - Y(2)
        X2(4) = 2,   Y2(4) = Y(8) - Y(5)
        X2(5) = 3,   Y2(5) = Y(6) - Y(3)
        X2(6) = 3,   Y2(6) = Y(9) - Y(6)
Syntax 1:
    LET <y> = SEQUENTIAL <stat> <x>             <SUBSET/EXCEPT/FOR qualification>
    where <x> is the response variable;
                <stat> is one of
        DIFFERENCE
        SUM
        PRODUCT
        MEAN
        MINIMUM
        MAXIMUM
        LOWER
        UPPER;
                <y> is a variable containing the differenced series;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Syntax 2:
    LET <y2> <x2> = SEQUENTIAL <stat> <y> <x>
                            <SUBSET/EXCEPT/FOR qualification>
    where <y> is the response variable;
                <x> is a the group-id variable;
                <stat> is one of
        DIFFERENCE
        SUM
        PRODUCT
        MEAN
        MINIMUM
        MAXIMUM
        LOWER
        UPPER;
                <y2> is a variable containing the differenced series;
                <x2> is a variable containing the group-id of the differenced series;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Examples:
    LET XD = SEQUENTIAL DIFFERENCE PRESSURE
    LET XD = SEQUENTIAL MEAN PRESSURE
    LET XD = SEQUENTIAL SUM PRESSURE
    LET XD = SEQUENTIAL DIFFERENCE PRESSURE SUBSET X > 4
    LET YDIFF X2 = SEQUENTIAL DIFFERENCE Y X
Default:
    None
Synonyms:
    DIFFERENCE is a synonym for SEQUENTIAL DIFFERENCE
    SEQUENTIAL AVERAGE is a synonym for SEQUENTIAL MEAN
    SEQUENTIAL MIN is a synonym for SEQUENTIAL MINIMUM
    SEQUENTIAL MAX is a synonym for SEQUENTIAL MAXIMUM
Related Commands:
    CUMULATIVE SUM = Compute the cumulative sum of the elements of a variable.
    SORT = Sort the elements of a variable.
    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 Transformations
Implementation Date:
    Pre-1987
    2016/02: Support for SUM, PRODUCT, MEAN
    2016/02: Support for MINIMUM, MAXIMUM, LOWER, and UPPER
    2016/02: Support for group-id variable<
Program 1:
    LET X1 = DATA 12 4 2 3 9 7
    LET XD = SEQUENTIAL DIFFERENCE X1
        
    The variable XD will contain the following values:
      8, 2, 1, 6, 2
Program 2:
     
    . Step 1:   Define the data
    .
    let y = sequence 1 1 10
    .
    . Step 2:   Compute the sequential statistics
    .
    let ydiff = sequential difference y
    let ysum  = sequential sum        y
    let yprod = sequential product    y
    let ymean = sequential mean       y
    let ymin  = sequential min        y
    let ymax  = sequential max        y
    .
    . Step 3:   Print the results
    .
    set write decimals 1
    print y ydiff ysum yprod ymean ymin ymax
        
    The following output is generated.
    ------------------------------------------------------------
                  Y          YDIFF           YSUM          YPROD
    ------------------------------------------------------------
                1.0            1.0            3.0            2.0
                2.0            1.0            5.0            6.0
                3.0            1.0            7.0           12.0
                4.0            1.0            9.0           20.0
                5.0            1.0           11.0           30.0
                6.0            1.0           13.0           42.0
                7.0            1.0           15.0           56.0
                8.0            1.0           17.0           72.0
                9.0            1.0           19.0           90.0
               10.0            0.0            0.0            0.0
     
     
    ------------------------------------------------------------
                  Y          YMEAN           YMIN           YMAX
    ------------------------------------------------------------
                1.0            1.5            1.0            2.0
                2.0            2.5            2.0            3.0
                3.0            3.5            3.0            4.0
                4.0            4.5            4.0            5.0
                5.0            5.5            5.0            6.0
                6.0            6.5            6.0            7.0
                7.0            7.5            7.0            8.0
                8.0            8.5            8.0            9.0
                9.0            9.5            9.0           10.0
               10.0            0.0            0.0            0.0
        
Program 3:
     
    . Step 1:   Define the data
    .
    dimension 40 columns
    let y = sequence 1 1 10
    let x = sequence 1 5 1 2
    .
    . Step 2:   Compute the sequential statistics
    .
    let ydiff ygroup = sequential difference y x
    let ysum  ygroup = sequential sum        y x
    let yprod ygroup = sequential product    y x
    let ymean ygroup = sequential mean       y x
    let ymin  ygroup = sequential min        y x
    let ymax  ygroup = sequential max        y x
    let ylow  ygroup = sequential lower      y x
    let yupp  ygroup = sequential upper      y x
    .
    . Step 3:   Print the results
    .
    set write decimals 1
    print ygroup ydiff ysum yprod ymean ymin ymax ylow yupp
        
    The following output is generated.
    ---------------------------------------------------------------------------
             YGROUP          YDIFF           YSUM          YPROD          YMEAN
    ---------------------------------------------------------------------------
                1.0            1.0            3.0            2.0            1.5
                1.0            1.0            5.0            6.0            2.5
                1.0            1.0            7.0           12.0            3.5
                1.0            1.0            9.0           20.0            4.5
                2.0            1.0           13.0           42.0            6.5
                2.0            1.0           15.0           56.0            7.5
                2.0            1.0           17.0           72.0            8.5
                2.0            1.0           19.0           90.0            9.5
     
     
    ---------------------------------------------------------------------------
             YGROUP           YMIN           YMAX           YLOW           YUPP
    ---------------------------------------------------------------------------
                1.0            1.0            2.0            1.0            2.0
                1.0            2.0            3.0            2.0            3.0
                1.0            3.0            4.0            3.0            4.0
                1.0            4.0            5.0            4.0            5.0
                2.0            6.0            7.0            6.0            7.0
                2.0            7.0            8.0            7.0            8.0
                2.0            8.0            9.0            8.0            9.0
                2.0            9.0           10.0            9.0           10.0
        

Privacy Policy/Security Notice
Disclaimer | FOIA

NIST is an agency of the U.S. Commerce Department.

Date created: 02/26/2016
Last updated: 02/26/2016

Please email comments on this WWW page to alan.heckert.gov.