User Documentation
 All Files Functions Groups
Huber White Variance
+ Collaboration diagram for Huber White Variance:
About:
When doing regression analysis, we are sometimes interested in the variance of the computed coefficients \( \boldsymbol c \). While the built-in regression functions provide variance estimates, we may prefer a robust variance estimate.

The robust variance calculation can be expressed in a sandwich formation, which is the form

\[ S( \boldsymbol c) = B( \boldsymbol c) M( \boldsymbol c) B( \boldsymbol c) \]

where \( B( \boldsymbol c)\) and \( M( \boldsymbol c)\) are matrices. The \( B( \boldsymbol c) \) matrix, also known as the bread, is relatively straight forward, and can be computed as

\[ B( \boldsymbol c) = n\left(\sum_i^n -H(y_i, x_i, \boldsymbol c) \right)^{-1} \]

where \( H \) is the hessian matrix.

The \( M( \boldsymbol c)\) matrix has several variation, each with different robustness properties. The form implemented here is the Huber-White sandwich operator, which takes the form

\[ M_{H} =\frac{1}{n} \sum_i^n \psi(y_i,x_i, \boldsymbol c)^T \psi(y_i,x_i, \boldsymbol c). \]

The above method for calculating robust variance (Huber-White estimates) is implemented for linear regression, logistic regression, and multinomial logistic regression. It is useful in calculating variances in a dataset with potentially noisy outliers. The Huber-White implemented here is identical to the "HC0" sandwich operator in the R module "sandwich".

The interface for robust linear, logistic, and multinomial logistic regression are similar, differing only in the optimal parameters. Calling the help and usage functions is identical across all three robust regressions.

When multinomial logistic regression is computed before the multinomial robust regression, it uses a default reference category of zero and the regression coefficients are included in the output table. The regression coefficients in the output are in the same order as multinomial logistic regression function, which is described below. For a problem with \( K \) dependent variables \( (1, ..., K) \) and \( J \) categories \( (0, ..., J-1) \), let \( {m_{k,j}} \) denote the coefficient for dependent variable \( k \) and category \( j \) . The output is \( {m_{k_1, j_0}, m_{k_1, j_1} \ldots m_{k_1, j_{J-1}}, m_{k_2, j_0}, m_{k_2, j_1} \ldots m_{k_K, j_{J-1}}} \). The order is NOT CONSISTENT with the multinomial regression marginal effect calculation with function marginal_mlogregr. This is deliberate because the interfaces of all multinomial regressions (robust, clustered, ...) will be moved to match that used in marginal.

Input:

The training data is expected to be of the following form:

{TABLE|VIEW} sourceName (
    outputTable VARCHAR,
    regressionType  VARCHAR,
    dependentVariable VARCHAR,
    independentVariable VARCHAR
)
Usage:

The Full Interface

Warning
The 'groupingCol' and 'print_warnings' input parameter for robust_variance_mlogregr is a placeholder in the Madlib V1.0. These input parameters will be implemented in a future release.
SELECT madlib::robust_variance_linregr(
    'source_table',        -- name of input table, VARCHAR
    'out_table',           -- name of output table, VARCHAR
    'dependent_varname',   -- dependent variable, VARCHAR
    'independent_varname', -- independent variables, VARCHAR
    'grouping_cols'        -- [OPTIONAL] grouping variables, VARCHAR
);

OR

SELECT madlib::robust_variance_logregr(
    'source_table',        -- name of input table, VARCHAR
    'out_table',           -- name of output table, VARCHAR
    'dependent_varname',   -- dependent variable, VARCHAR
    'independent_varname', -- independent variables, VARCHAR
    'grouping_cols',       -- [OPTIONAL] grouping variables, VARCHAR
    max_iter,              -- [OPTIONAL] Integer identifying the maximum iterations used by the logistic regression solver.  Default is 20, Integer
    'optimizer',           -- [OPTIONAL] String identifying the optimizer used in the logistic regression.  See the documentation in the logistic regression for the available options.  Default is irls.  VARCHAR
    tolerance,             -- [OPTIONAL] Float identifying the tolerance of the logistic regression optimizer. Default is 0.0001.  DOUBLE PRECISION
    print_warnings         -- [OPTIONAL] Boolean specifying if the regression fit should print any warning messages.  Default is false. BOOLEAN
);

OR

SELECT madlib.robust_variance_mlogregr(
    'source_table',        -- name of input table, VARCHAR
    'out_table',           -- name of output table, VARCHAR
    'dependent_varname',   -- dependent variable, VARCHAR
    'independent_varname', -- independent variables, VARCHAR
    ref_category,          -- [OPTIONAL] Integer specifying the reference category. Default is 0.
    'grouping_cols',       -- [OPTIONAL] grouping variables, VARCHAR. Default is NULL.
    max_iter,              -- [OPTIONAL] Integer identifying the maximum iterations used by the logistic regression solver.  Default is 20.
    'optimizer',           -- [OPTIONAL] String identifying the optimizer used in the multinomial logistic regression.  See the documentation in the multinomial logistic regression for the available options.  Default is irls.
    tolerance,             -- [OPTIONAL] Float identifying the tolerance of the multinomial logistic regression optimizer. Default is 0.0001.
    print_warnings         -- [OPTIONAL] Boolean specifying if the regression fit should print any warning messages.  Default is false.
);

Here the 'independent_varname' can be the name of a column, which contains array of numeric values. It can also have a format of string 'array[1, x1, x2, x3]', where x1, x2 and x3 are all column names.

Output is stored in the out_table:

[ coef | std_err | (z/t)-stats | p_values |
+------+---------+-------------+----------+
Examples:
  1. For function summary information. Run
    sql> select robust_variance_{linregr OR logregr OR mlogregr}('help');
    OR
    sql> select robust_variance_{linregr OR logregr OR mlogregr}();
    OR
    sql> select robust_variance_{linregr OR logregr OR mlogregr}('?');
    
  2. For function usage information.
    sql> select robust_variance_{linregr OR logregr OR mlogregr}('usage');
    
  3. Create the sample data set:
    sql> SELECT * FROM data;
     id | second_attack | treatment | trait_anxiety
    ----+---------------+-----------+---------------
      1 |             1 |         1 |            70
      3 |             1 |         1 |            50
      5 |             1 |         0 |            40
      7 |             1 |         0 |            75
      9 |             1 |         0 |            70
     11 |             0 |         1 |            65
     13 |             0 |         1 |            45
     15 |             0 |         1 |            40
     17 |             0 |         0 |            55
    ...
    
  4. Run the logistic regression function and then compute the robust logistic variance of the regression:
    sql> select robust_variance_logregr('patients', 'newTable',  'second_attack', 'ARRAY[1, treatment, trait_anxiety]');
    sql> select * from newTable;
    coef           | {11.962748350258,1.37269168529894,0.00285507335100035}
    std_err        | {3.45872062333141,1.17161925782182,0.053432886418388}
    z_stats        | {-1.839833462942,-0.874094587942144,2.22793348156965}
    p_values       | {0.0657926909738772,0.382066744586027,0.0258849510756295}
    
Literature:

[1] vce(cluster) function in STATA: http://www.stata.com/help.cgi?vce_option

[2] clustered estimators in R: http://people.su.se/~ma/clustering.pdf

[3] Achim Zeileis: Object-oriented Computation of Sandwich Estimators. Research Report Series / Department of Statistics and Mathematics, 37. Department of Statistics and Mathematics, WU Vienna University of Economics and Business, Vienna. http://cran.r-project.org/web/packages/sandwich/vignettes/sandwich-OOP.pdf

See Also
File robust.sql_in documenting the SQL functions.