1

I am using data which I suspect is distributed according to the Normal Inverse Gaussian distribution (NIG). The literature says that the 4 parameters of the NIG distribution can be estimated from the sample mean, variance, kurtosis, and skewness. I would like to test the fit of NIG with the calculated parameters and the data. Now, my function is written as:

NIG2[x_, {α_, β_, μ_, δ_}] := 
  (α/(δ π)) Exp[Sqrt[α^2 - β^2] - (β μ)/δ] (K1[α*Sqrt[1 + ((x - μ)/δ)^2]]
    Sqrt[1 + ((x - μ)/δ)^2]) Exp[β/δ x];

Edit: The K1 function is the Bessel function of the third kind which is:

K1[w_] = Integrate[ Exp[ -w (t + t^(-1)) / 2 ] , {t, 0, Infinity}]
         (*  = ConditionalExpression[2 BesselK[1, w], Re[w] > 0]  *) 

The four parameters are

{α, β, μ, δ}

and their values are (respectively):

{0.635655,  - 0.00143495 I, 6.87671, 1.56309}

I saw Mr Alpha's answer to a similar query where data followed an AR(4) process. I tried using the residualAnalysis module presented, but Mathematica claims that NIG2 is not a valid process. Yet the 4 plots do appear to be quite correct as the residuals seem distributed normally.

How should I test data against a NIG distribution function?

Xavier_B
  • 193
  • 6
  • 1
    whats K1? (15) – george2079 Dec 23 '15 at 15:44
  • Sorry, forgot to say that K1 is the Bessel Function of the third kind: K1[w_] = 1/2 !( *SubsuperscriptBox[([Integral]), (0), ([Infinity])](Exp[(- *FractionBox[(w ((t + t^(((-1)))))), (2)])] [DifferentialD]t)); – Xavier_B Dec 23 '15 at 18:39
  • Can you edit the question to add the definition of K1 (at a glance I don't see a "third kind" Bessel function directly available..) – george2079 Dec 23 '15 at 18:59
  • I did't understand your question. What do you want to do with this function? Just use it to fit your data with calculation of the optimal alfa, beta etc? – Rom38 Dec 24 '15 at 06:27
  • Your calculation has a complex result with an imaginary part that is pretty small, but not so small to just use Chop. This is likely the source of your error. Is it supposed to be real? Do you just want to take the real part? Another thing, you might set K1[w_] = 2 BesselK[1, w] and verify the conditional is satisfied after you get your fit. – george2079 Dec 24 '15 at 15:21
  • I don't know if it's any help, but your NIG2 is proportional to PDF[HyperbolicDistribution[3/2, α/δ, β/δ, δ, μ], x] (as a function of x). – Michael E2 Dec 24 '15 at 20:12
  • @Rom38 There are a number of fittedDistribution tests that I can use in Mathematica, but only with PDF known to Mathematica. The NIG is not one of them. If the NIG is the correct PDF to use, then, the parameters can been estimated using the literature. However, I now wish to make sure that this NIG is effectively the a good fit for the data. – Xavier_B Dec 25 '15 at 09:05
  • @Michael E2: I tried plotting the PDF[HyperbolicDistribution] using the parameters you mention, and the values for them as defined above, but the functions don't overlap: they merely have approximately the same mean and they don't fit the data. Are you sure about the parameter definition? When I use the HyperbolicDistribution as the distribution definition for the DistributionFitTest, I get the following parameters : {3/2,7.71259,-1.04967,18.447,2.38682}, and the tails for this distribution are too thin compared to the data (I don't know how to insert a picture of the graph). – Xavier_B Dec 25 '15 at 09:25
  • I meant PDF[HyperbolicDistribution[3/2, α/δ, β/δ, δ, μ], x]/NIG2[x, {α, β, μ, δ}] // FullSimplify[#, δ > 0]& simplifies to a "constant" depending only on α and β. Since I've no data to test and I'm not that familiar with your problem, I can't really say much more. I thought the built-in distribution might be used more easily than a user-constructed one. One thing I don't understand is that the linked question deals with time-series data & processes, but I don't see the connection with your problem, at least in the details presented. (I'm only vaguely familiar with time series.) – Michael E2 Dec 25 '15 at 15:49
  • Of course, I should have mentioned: The "constant" means that to get the functions to be identical, the parameters or a function would have to be adjusted. Unless Mathematica is wrong, it means NIG2 is not a PDF, except for values of parameters that make the constant equal to 1; since you don't claim it is a PDF, maybe that's unimportant. – Michael E2 Dec 25 '15 at 15:56
  • @MichaelE2 You are actually correct: the NIG is from the hyperbolic family of functions, and in the case I am using, is a PDF. As you mentioned it could be used as one of the Hyperparabolic pdf for DistributionFitTest purposes, I tried it, but, as I said got parameters for which the hyperbolic function does not match the data. But maybe, I am not using the correct function to test whether a function describes a dataset. Do you know of some other Mathematica test I could use? – Xavier_B Dec 25 '15 at 20:15
  • 1
    I think they're all probably closely related: DistributionFitTest, EstimatedDistribution, FindDistributionParameters; maybe FindDistribution. I can't think of anything else. Maybe someone with a better statistics will come along. Things can get a little slow on SE this time of the year. – Michael E2 Dec 25 '15 at 20:28
  • Do you have any sample data that can be used by potential answerers? – J. M.'s missing motivation Feb 22 '16 at 03:07
  • @J.M. how can I send you an excel file with the 30 years' worth of weekly temperature anomalies in France? These anomalies are supposed to follow a NIG distribution. that 1675 numbers. – Xavier_B Feb 23 '16 at 15:54
  • I would say that's a bit too much. Why not reduce/downsample your data a bit so that it is more manageable as an example. In any case, if you can convert your spreadsheet to a *.csv file, you can put it on pastebin and link to it here. – J. M.'s missing motivation Feb 23 '16 at 15:59
  • Excuse my ignorance, how do i put a csv file on pastebin? OK got it, link to pastebin is: http://pastebin.ca/3380053 – Xavier_B Feb 23 '16 at 16:36
  • @J.M. I put all the data in the csv file for anomalies in temperature in France over 30 years on a 4-week rolling basis. Numbers can b epositive or negative. They should allow to evaluate the best fitting NIG. – Xavier_B Feb 23 '16 at 16:41

1 Answers1

4

Mathematica's HyperbolicDistribution[λ,α,β,δ,μ] is the generalized hyperbolic distribution.

When λ = -1/2, it is the NIG distribution. So it can be used directly with FindDistributionParameters or EstimatedDistribution to fit a NIG to data, and then check the fit by DistributionFitTest.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Frank
  • 286
  • 1
  • 6