Excel FDist的兼容SQL函数

有没有人知道在Excel中有一个兼容的函数为Excel FDIST和FINV? 如果没有,任何人有任何想法如何build立? 可能在C#中?

谢谢。 非常感谢您的帮助。

我设法解决我的问题,通过使用.NET Framework 4.0及以上(System.Windows.Forms.DataVisualization.Charting.StatisticFormula)的库。

我能够在C#中使用上面的库开发一个函数来计算过程。 这是一个function强大的图书馆,您可以在那里find大多数常用的统计公式(例如,平均值,中位数,t分布,f分布和逆matrix)。

以下是我的代码片段:

 using System.Windows.Forms.DataVisualization.Charting; private Chart ch = new Chart(); // You will need to declare an object of Chart type, as Statistic Formula class does not have a public constructor double fDist = ch.DataManipulator.Statistics.FDistribution(fRatioVariance, degreeFreedom1, degreeFreedom2); 

希望这会帮助别人。 谢谢。

尽pipe其时间太晚但在SQL Server本身中是一些统计function的实现。

要获得FDist函数(相当于Excel – FDist),我们将需要完整和不完整的beta函数以及gamma函数:

 --GAMMA Function CREATE FUNCTION [dbo].[udf_Gamma] ( @x Float=NULL ) RETURNS Float AS BEGIN Declare @f Float = 10E99; Declare @g Float = 1; if ( @x > 0 ) Begin while (@x < 3) Begin SET @g = @g * @x; SET @x = @x + 1; End SET @f = (1 - (2/(7*power(@x,2))) * (1 - 2/(3*power(@x,2))))/(30*power(@x,2)); SET @f = (1-@f)/(12*@x) + @x*(log(@x)-1); SET @f = (exp(@f)/@g)*power(2*PI()/@x,0.5); End else Begin SET @f = 10E99 End return @f; END --BETA Complete Function CREATE FUNCTION [dbo].[udf_BetaC] ( @x Float=NULL ,@a Float=NULL ,@b Float=NULL ) RETURNS Float AS BEGIN --double betacf(double a,double b,double x){ Declare @maxIterations int = 50, @m int =1 Declare @eps Float = 3E-5 Declare @am Float = 1; Declare @bm Float = 1; Declare @az Float = 1; Declare @qab Float = @a+@b; Declare @qap Float = @a+1; Declare @qam Float = @a-1; Declare @bz Float = 1 - @qab*@x/@qap; Declare @aold Float = 0; Declare @em Float, @tem Float, @d Float, @ap Float, @bp Float, @app Float, @bpp Float; while((@m<@maxIterations) AND (abs(@az-@aold)>=@eps*abs(@az))) Begin SET @em = @m; SET @tem = @em+@em; SET @d = @em*(@b-@m)*@x/((@qam + @tem)*(@a+@tem)); SET @ap = @az+@d*@am; SET @bp = @bz+@d*@bm; SET @d = -(@a+@em)*(@qab+@em)*@x/((@a+@tem)*(@qap+@tem)); SET @app = @ap+@d*@az; SET @bpp = @bp+@d*@bz; SET @aold = @az; SET @am = @ap/@bpp; SET @bm = @bp/@bpp; SET @az = @app/@bpp; SET @bz = 1; SET @m = @m + 1; End return @az END --BETA INCOMPLETE Function CREATE FUNCTION [dbo].[udf_BetaI] ( @x Float=null ,@a Float=null ,@b Float=null ) RETURNS Float AS BEGIN Declare @bt Float=0.0 Declare @beta Float=0.0 if( @x=0 OR @x=1 ) Begin SET @bt = 0 End else if((@x>0) AND (@x<1)) Begin SET @bt = (Select dbo.UDF_Gamma(@a+@b)* power(@x,@a)* power(1-@x,@b)/(dbo.UDF_Gamma(@a)*dbo.UDF_Gamma(@b)) ) End if(@x<(@a+1)/(@a+@b+2)) Begin SET @beta = (Select @bt*dbo.udf_betaC(@x,@a,@b)/@a) End else Begin SET @beta = (Select 1-@bt*dbo.udf_betaC(1-@x,@b,@a)/@b) End Return @beta END --FDist Function CREATE FUNCTION [dbo].[udf_FDist] ( @x Float=NULL ,@df1 Float=NULL ,@df2 Float=NULL ) RETURNS Float AS BEGIN Declare @x1 Float=(@x*@df1)/((@x*@df1)+@df2) return (select 1 - dbo.udf_BetaI(@x1,(@df1/2),(@df2/2))) END 

检查Excel = FDIST(0.5,1,1)= 0.608173448,并在SQL编辑器= SELECT udf_FDIST(0.5,1,1)= 0.608173457369209

问候,阿维

FDIST FINV不存在于Sql Server中。

您可以编写一个SQL Sever函数来实现两个Excelfunction。

在这里显示创buildfunction

在MS SQL Server中有standard_deviation和一些更多的统计函数,包括方差。

还有一百万个解决方法,例如: http : //oreilly.com/catalog/transqlcook/chapter/ch08.html

,但是你需要深入挖掘这些math。