Re: Inconsistent behaviour of StudentTDistribution
- To: mathgroup at smc.vnet.net
- Subject: [mg103202] Re: Inconsistent behaviour of StudentTDistribution
- From: pfalloon <pfalloon at gmail.com>
- Date: Thu, 10 Sep 2009 07:22:20 -0400 (EDT)
- References: <h87pi3$5hp$1@smc.vnet.net>
On Sep 9, 6:38 pm, Alexey <lehi... at gmail.com> wrote:
> Hello,
> Consider the following:
>
> PDF[StudentTDistribution[f], x]
> D[CDF[StudentTDistribution[f], x], x]
>
> The outputs of these expressions must be equal. But in really the
> second is useless and confusing.
I totally agree that this is not a very useful result in this case.
I suspect the underlying issue is related to the presence of the
inoccuous-looking function Sign in the CDF:
In[311]:= CDF[StudentTDistribution[nu], x]
Out[311]= 1/2 (1+BetaRegularized[nu/(nu+x^2),1,nu/2,1/2] Sign[x])
This is problematic because Mathematica doesn't differentiate this the
way you might expect:
In[319]:= D[Sign[x], x]
Out[319]= Sign'[x]
This may seem like a simple oversight, but the real reason (if I
understand correctly) is more subtle. If you try passing complex
arguments to Sign, you get:
In[318]:= Sign[1+I]
Out[318]= (1+I)/Sqrt[2]
Looking in the documentation, we see that the general definition for
Sign[z] is z/Abs[z]. This gives the expected behaviour on the real
axis, but unfortunately in the complex-plane Abs[z] is non-
differentiable (w.r.t. the complex variable z).
So, it kind of looks like a fairly low-level design issue regarding
differentiability of complex-valued functions is what's responsible
here.
What's less clear to me is why something like the following doesn't
work, and whether it may be desirable if it did:
In[322]:= Assuming[Element[x, Reals], D[Sign[x], x]]
Out[322]= Sign'[x]
i.e. if we assume that x is real, why can't the differentiation
operator act on functions like Sign and Abs?
Looking in the documentation, it seems like the similar function
UnitStep has a different implementation which doesn't allow complex
arguments:
In[326]:= UnitStep[1+I]
Out[326]= UnitStep[1+I]
This suggests a workaround that you may find useful if you know that x
is always real (which AFAIK should always be the case):
In[343]:= cdf[nu_,x_] = CDF[StudentTDistribution[nu],x] /. Sign ->
(2*UnitStep[#]-1 &)
Out[343]= 1/2 (1+BetaRegularized[nu/(nu+x^2),1,nu/2,1/2] (-1+2 UnitStep
[x]))
With this definition, you get a reasonable derivative (albeit with
Indeterminate at x==0):
In[351]:= D[cdf[nu,x],x] // FullSimplify // InputForm
Out[351]//InputForm=
Piecewise[{{Indeterminate, x == 0}}, (Sqrt[(nu + x^2)^(-1)]*(nu/(nu +
x^2))^(nu/2))/Beta[nu/2, 1/2]]
Finally, I'd suggest this issue could be prevented by adopting an
alternative definition of the CDF, like the one which appears on the
Wikipedia page: this may or may not be valid for complex x, but who
cares since the domain of x is, by definition, the real numbers?
Cheers,
Peter.