2019-08-08 14:20:25 +00:00
|
|
|
SET any_join_distinct_right_table_keys = 1;
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS series;
|
2015-06-23 16:35:04 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
CREATE TABLE series(i UInt32, x_value Float64, y_value Float64) ENGINE = Memory;
|
2015-06-23 16:35:04 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO series(i, x_value, y_value) VALUES (1, 5.6,-4.4),(2, -9.6,3),(3, -1.3,-4),(4, 5.3,9.7),(5, 4.4,0.037),(6, -8.6,-7.8),(7, 5.1,9.3),(8, 7.9,-3.6),(9, -8.2,0.62),(10, -3,7.3);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
/* varSamp */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT varSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT varSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
2017-12-22 22:11:08 +00:00
|
|
|
varSamp(x_value) AS res1,
|
2015-06-23 16:35:04 +00:00
|
|
|
(sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1) AS res2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/* stddevSamp */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT stddevSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT stddevSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
2017-12-22 22:11:08 +00:00
|
|
|
stddevSamp(x_value) AS res1,
|
2015-06-23 16:35:04 +00:00
|
|
|
sqrt((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1)) AS res2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
);
|
|
|
|
|
2019-05-06 04:08:54 +00:00
|
|
|
/* skewSamp */
|
|
|
|
|
|
|
|
SELECT skewSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT skewSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
skewSamp(x_value) AS res1,
|
|
|
|
(
|
|
|
|
sum(x_value * x_value * x_value) / count()
|
|
|
|
- 3 * sum(x_value * x_value) / count() * sum(x_value) / count()
|
|
|
|
+ 2 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1), 1.5) AS res2
|
|
|
|
FROM series
|
|
|
|
);
|
|
|
|
|
|
|
|
/* kurtSamp */
|
|
|
|
|
|
|
|
SELECT kurtSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT kurtSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
kurtSamp(x_value) AS res1,
|
|
|
|
(
|
|
|
|
sum(x_value * x_value * x_value * x_value) / count()
|
|
|
|
- 4 * sum(x_value * x_value * x_value) / count() * sum(x_value) / count()
|
|
|
|
+ 6 * sum(x_value * x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
- 3 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1), 2) AS res2
|
|
|
|
FROM series
|
|
|
|
);
|
|
|
|
|
2015-06-23 16:35:04 +00:00
|
|
|
/* varPop */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT varPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT varPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
2017-12-22 22:11:08 +00:00
|
|
|
varPop(x_value) AS res1,
|
2015-06-23 16:35:04 +00:00
|
|
|
(sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count() AS res2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/* stddevPop */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT stddevPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT stddevPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
2017-12-22 22:11:08 +00:00
|
|
|
stddevPop(x_value) AS res1,
|
2015-06-23 16:35:04 +00:00
|
|
|
sqrt((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count()) AS res2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
);
|
|
|
|
|
2019-05-06 04:08:54 +00:00
|
|
|
/* skewPop */
|
|
|
|
|
|
|
|
SELECT skewPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT skewPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
skewPop(x_value) AS res1,
|
|
|
|
(
|
|
|
|
sum(x_value * x_value * x_value) / count()
|
|
|
|
- 3 * sum(x_value * x_value) / count() * sum(x_value) / count()
|
|
|
|
+ 2 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count(), 1.5) AS res2
|
|
|
|
FROM series
|
|
|
|
);
|
|
|
|
|
|
|
|
/* kurtPop */
|
|
|
|
|
|
|
|
SELECT kurtPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
|
|
|
|
SELECT kurtPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
|
|
|
|
|
|
|
|
SELECT round(abs(res1 - res2), 6) FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
kurtPop(x_value) AS res1,
|
|
|
|
(
|
|
|
|
sum(x_value * x_value * x_value * x_value) / count()
|
|
|
|
- 4 * sum(x_value * x_value * x_value) / count() * sum(x_value) / count()
|
|
|
|
+ 6 * sum(x_value * x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
- 3 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
|
|
|
|
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count(), 2) AS res2
|
|
|
|
FROM series
|
|
|
|
);
|
|
|
|
|
2015-06-23 16:35:04 +00:00
|
|
|
/* covarSamp */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT covarSamp(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 0);
|
|
|
|
SELECT covarSamp(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(COVAR1 - COVAR2), 6)
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
arrayJoin([1]) AS ID2,
|
2015-06-23 16:35:04 +00:00
|
|
|
covarSamp(x_value, y_value) AS COVAR1
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2017-12-22 22:11:08 +00:00
|
|
|
) ANY INNER JOIN
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
arrayJoin([1]) AS ID2,
|
2015-06-23 16:35:04 +00:00
|
|
|
sum(VAL) / (count() - 1) AS COVAR2
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
|
|
|
SELECT (X - AVG_X) * (Y - AVG_Y) AS VAL
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
toUInt32(arrayJoin([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) AS ID,
|
|
|
|
avg(x_value) AS AVG_X,
|
2015-06-23 16:35:04 +00:00
|
|
|
avg(y_value) AS AVG_Y
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2017-12-22 22:11:08 +00:00
|
|
|
) ANY INNER JOIN
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
i AS ID,
|
|
|
|
x_value AS X,
|
2015-06-23 16:35:04 +00:00
|
|
|
y_value AS Y
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
) USING ID
|
|
|
|
)
|
|
|
|
) USING ID2;
|
|
|
|
|
|
|
|
/* covarPop */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT covarPop(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 0);
|
|
|
|
SELECT covarPop(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
|
|
|
SELECT round(abs(COVAR1 - COVAR2), 6)
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
arrayJoin([1]) AS ID2,
|
2015-06-23 16:35:04 +00:00
|
|
|
covarPop(x_value, y_value) AS COVAR1
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2017-12-22 22:11:08 +00:00
|
|
|
) ANY INNER JOIN
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
arrayJoin([1]) AS ID2,
|
2015-06-23 16:35:04 +00:00
|
|
|
sum(VAL) / count() AS COVAR2
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
|
|
|
SELECT (X - AVG_X) * (Y - AVG_Y) AS VAL
|
2017-12-22 22:11:08 +00:00
|
|
|
FROM
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
toUInt32(arrayJoin([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) AS ID,
|
|
|
|
avg(x_value) AS AVG_X,
|
2015-06-23 16:35:04 +00:00
|
|
|
avg(y_value) AS AVG_Y
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2017-12-22 22:11:08 +00:00
|
|
|
) ANY INNER JOIN
|
2015-06-23 16:35:04 +00:00
|
|
|
(
|
2017-12-22 22:11:08 +00:00
|
|
|
SELECT
|
|
|
|
i AS ID,
|
|
|
|
x_value AS X,
|
2015-06-23 16:35:04 +00:00
|
|
|
y_value AS Y
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM series
|
2015-06-23 16:35:04 +00:00
|
|
|
) USING ID
|
|
|
|
)
|
|
|
|
) USING ID2;
|
|
|
|
|
|
|
|
/* corr */
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT corr(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 0);
|
|
|
|
SELECT corr(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 1);
|
2015-06-23 16:35:04 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT round(abs(corr(x_value, y_value) - covarPop(x_value, y_value) / (stddevPop(x_value) * stddevPop(y_value))), 6) FROM series;
|
2015-06-23 16:35:04 +00:00
|
|
|
|
2018-08-13 09:28:49 +00:00
|
|
|
/* quantile AND quantileExact */
|
|
|
|
SELECT '----quantile----';
|
|
|
|
|
|
|
|
SELECT quantileExactIf(number, number > 0) FROM numbers(90);
|
|
|
|
|
|
|
|
SELECT quantileExactIf(number, number > 100) FROM numbers(90);
|
|
|
|
SELECT quantileExactIf(toFloat32(number) , number > 100) FROM numbers(90);
|
|
|
|
SELECT quantileExactIf(toFloat64(number) , number > 100) FROM numbers(90);
|
|
|
|
|
|
|
|
SELECT quantileIf(number, number > 100) FROM numbers(90);
|
|
|
|
SELECT quantileIf(toFloat32(number) , number > 100) FROM numbers(90);
|
|
|
|
SELECT quantileIf(toFloat64(number) , number > 100) FROM numbers(90);
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE series;
|