2011-10-11 160 views

回答

1

TSQL具有計算峯度所需的所有功能,但我認爲您必須將它們放在一個自定義函數中。

這裏有一個實現,我發現(參考:SolidQ

SELECT 
    Kurt = SUM(SQUARE(SQUARE(((Age*1.0-m.mean)/m.[StDev])))) * MIN(m.corrfact2) - MIN(m.subfact) 
FROM 
     vTargetMail v 
    CROSS JOIN 
     (
     SELECT 
      mean = AVG(Age*1.0), [StDev] = STDEV(Age), 
      corrfact2 = COUNT(*)*1.0 * (COUNT(*)+1)/(COUNT(*)-1)/(COUNT(*)-2)/(COUNT(*)-3), 
      subfact = 3.0 * SQUARE((COUNT(*)-1))/(COUNT(*)-2)/(COUNT(*)-3) 
     FROM vTargetMail v 
    ) AS m; 
0

我對此表示懷疑—這是一個晦澀難懂的函數,MySQL傾向於實現更接近數學基本核心的函數。

然而,Kurtosis計算自己相當簡單。請參閱公式here

0

通過從http://blogs.solidq.com/en/sqlserver/skewness-and-kurtosis-part-1-t-sql-solution/#abh_postshttps://sqlwithpanks.wordpress.com/2016/06/22/kurtosis-a-measure-of-tailedness-of-the-distribution/結合的方法,下面是一個測試版工作:

;with v as (select floor(rand(convert(varbinary,newid()))*365)+1 as X from dbo.TblModel07_High), 
AGG as (SELECT m1 = AVG(X*1.0), sd1 = STDEV(X),corrfact1 = COUNT(*)*1.0/(COUNT(*)-1)/(COUNT(*)-2), 
[corrfact2] = COUNT(*)*1.0 * (COUNT(*)+1)/(COUNT(*)-1)/(COUNT(*)-2)/(COUNT(*)-3), 
[subfact] = 3.0 * SQUARE((COUNT(*)-1))/(COUNT(*)-2)/(COUNT(*)-3) from v) 
SELECT N=count(*), Xmin=min(X), Xmax=max(X),M = MIN(m1),SD = MIN(sd1),CV = min(sd1)/min(m1), 
Skew = SUM(((X*1.0 - m1)/sd1)*((X*1.0-m1)/sd1)*((X*1.0-m1)/sd1))* min(corrfact1), 
Kurt = SUM(SQUARE(SQUARE(((X * 1.0 - m1)/sd1)))) * min(corrfact2) - min(subfact)+3 from v cross apply 
(select m1,sd1,corrfact1,corrfact2,subfact from AGG) A 
相關問題