Teradata Package for Python Function Reference | 20.00 - DurbinWatson - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
 
 
DurbinWatson

 
Functions
       
DurbinWatson(data=None, data_filter_expr=None, explanatory_count=None, include_constant=False, method=None, significance_level=None, **generic_arguments)
DESCRIPTION:
    The DurbinWatson() function determines serial correlation between
    residuals within an independent time series data, or in the residual result
    of TDAnalyticResult.
 
    The following procedure is an example of how to use DurbinWatson() function:
        * Use LinearRegr() on the residuals.
        * Use DurbinWatson() on the output from LinearRegr() to determine
          if there is serial correlation.
 
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the input series or a TDAnalyticResult object
        created over the output residual generated by the UAF function.
        Types: TDSeries, TDAnalyticResult
 
    data_filter_expr:
        Optional Argument.
        Specifies the filter expression for "data".
        Types: ColumnExpression
 
    explanatory_count:
        Required Argument.
        Specifies the number of explanatory variables in the original regression.
        The number of explanatory variables along with the "include_constant"
        information is needed to perform the lookup in the Durbin-Watson data.
        Types: int
 
    include_constant:
        Optional Argument.
        Specifies whether the original regression equation contains a constant,
        also known as an intercept. When set to False, no constant is present,
        otherwise constant is present.
        Default Value: False
        Types: bool
 
    method:
        Required Argument.
        Specifies the enumerated value specifying the formula to calculate
        the Durbin-Watson test statistic value.
        Permitted Values:
            * DW_FORMULA: use the full summation formula to calculate
                          the value.
            * ACR_LAG1: perform the regression with an autocorrelation
                       of lag 1, and use as the role of the Durbin-Watson
                       statistic.
        Types: str
 
    significance_level:
        Required Argument.
        Specifies the significance level for the test. Value must be greater
        than 0 and less than 1. For example, 0.01, or 0.05.
        Types: float
 
    **generic_arguments:
        Specifies the generic keyword arguments of UAF functions.
        Below are the generic keyword arguments:
            persist:
                Optional Argument.
                Specifies whether to persist the results of the
                function in a table or not. When set to True,
                results are persisted in a table; otherwise,
                results are garbage collected at the end of the
                session.
                Note that, when UAF function is executed, an 
                analytic result table (ART) is created.
                Default Value: False
                Types: bool
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the
                function in a volatile ART or not. When set to
                True, results are stored in a volatile ART,
                otherwise not.
                Default Value: False
                Types: bool
 
            output_table_name:
                Optional Argument.
                Specifies the name of the table to store results. 
                If not specified, a unique table name is internally 
                generated.
                Types: str
 
            output_db_name:
                Optional Argument.
                Specifies the name of the database to create output 
                table into. If not specified, table is created into 
                database specified by the user at the time of context 
                creation or configuration parameter. Argument is ignored,
                if "output_table_name" is not specified.
                Types: str
 
 
RETURNS:
    Instance of DurbinWatson.
    Output teradataml DataFrames can be accessed using attribute 
    references, such as DurbinWatson_obj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        1. result
 
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
 
EXAMPLES:
    # Notes:
    #     1. Get the connection to Vantage to execute the function.
    #     2. One must import the required functions mentioned in
    #        the example from teradataml.
    #     3. Function will raise error if not supported on the Vantage
    #        user is connected to.
 
    # Check the list of available UAF analytic functions.
    display_analytic_functions(type="UAF")
 
    # Load the example data.
    load_example_data("uaf", ["house_values2"])
 
    # Create teradataml DataFrame object.
    data = DataFrame.from_table("house_values2")
 
    # Create teradataml TDSeries object.
    linearregr_series = TDSeries(data=data,
                                 id="cid",
                                 row_index_style="SEQUENCE",
                                 row_index="s_no",
                                 payload_field=["house_value", "salary"],
                                 payload_content="MULTIVAR_REAL"
                                 )
    # The LinearRegr() function fits TDSeries data to
    # the curve mentioned in the "formula." It returns
    # a result containing solved coefficients, model statistics,
    # and residuals statistics.
    linearregr_output = LinearRegr(data=linearregr_series,
                                   variables_count=2,
                                   weights=False,
                                   formula="Y=B0+B1*X1",
                                   algorithm='QR',
                                   model_stats=True,
                                   coeff_stats=False,
                                   residuals=True
                                   )
 
    # Example 1: Determine the serial correlation using TDAnalyticResult.
    # Create teradataml TDAnalyticResult object.
    artspec=TDAnalyticResult(data=linearregr_output.result)
 
    uaf_out1 = DurbinWatson(data=artspec,
                            explanatory_count=2,
                            method="DW_FORMULA",
                            significance_level=0.05)
 
    # Print the result DataFrame.
    print(uaf_out1.result)
 
    # Example 2: Determine the serial correlation using TDSeries.
    # Create teradataml TDSeries object.
    seriesspec = TDSeries(data=linearregr_output.fitresiduals,
                          id="cid",
                          row_index_style="SEQUENCE",
                          row_index="ROW_I",
                          payload_field="RESIDUAL",
                          payload_content="REAL"
                          )
 
    uaf_out2 = DurbinWatson(data=seriesspec,
                            explanatory_count=2,
                            method="DW_FORMULA",
                            significance_level=0.05)
 
    # Print the result DataFrame.
    print(uaf_out2.result)