blob: 129fae8b640790d4f1146c4824768628a13d7653 [file] [log] [blame]
/* ----------------------------------------------------------------------- *//**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*//* ----------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Test Linear Regression.
* -------------------------------------------------------------------------- */
/*
* The following example is taken from:
* http://www.weibull.com/DOEWeb/estimating_regression_models_using_least_squares.htm#Example%205.1
* http://www.weibull.com/DOEWeb/hypothesis_tests_in_multiple_linear_regression.htm#Example%205.3
*/
DROP TABLE IF EXISTS weibull;
CREATE TABLE weibull (
id INTEGER NOT NULL,
x1 DOUBLE PRECISION,
x2 DOUBLE PRECISION,
y DOUBLE PRECISION
);
/*
* We materialize the table here because on MPP systems we want to distribute
* the data to the segments (and not do the calculations in memory).
*/
INSERT INTO weibull(id, x1, x2, y) VALUES
( 1, 41.9, 29.1, 251.3),
( 2, 43.4, 29.3, 251.3),
( 3, 43.9, 29.5, 248.3),
( 4, 44.5, 29.7, 267.5);
--------------------- Robust linear regression install checks -----------
SELECT (robust_linregr(y, ARRAY[1, x1, x2], coef)).*
FROM
( SELECT (linregr(y, ARRAY[1, x1, x2])).coef
FROM weibull
) as mle_coef,
weibull as src;
DROP TABLE IF EXISTS result_weibull_3;
DROP TABLE IF EXISTS result_weibull_3_summary;
select robust_variance_linregr('weibull', 'result_weibull_3', 'y', 'ARRAY[1, x1, x2]');
-- End of robust linear regression