# Skewness of distribution vs. skewness of distribution's PDF

I'm having trouble understanding why the skewness of built-in distributions is not the same as the skewness of their probability density functions. For example, the following are different (the first being correct):

Skewness[NormalDistribution[0, 1]]
Skewness[PDF[NormalDistribution[0, 1], Table[x, {x, -4, 4, 0.1}]]]


..despite them both being (looking?) the same:

Plot[PDF[NormalDistribution[0, 1], x], {x, -4, 4}]
ListPlot[PDF[NormalDistribution[0, 1], Table[x, {x, -4, 4, 0.1}]]]


What I'm trying to do is estimate the skewness of a distribution resulting from a numerically solved PDE model (i.e. a distribution for which I have no analytical solution). Mathematica's skewness function is giving me positive skewness estimates even when the distribution is clearly negatively-skewed. Thanks.

@Szabolcs The PDE itself is rather "complicated" (boundary conditions, etc.), so I’ll try illustrate with a simpler version (which, unfortunately, doesn’t exhibit the negative skew of the complete model):

deqn = D[u[x, t], t] == d D[u[x, t], x, x] - a  D[u[x, t], x] - \[Lambda] u[x, t]

g[x_, \[Epsilon]_]:=Piecewise[{{0,x<0}, {1,0<=x<=\[Epsilon]}, {0,x>\[Epsilon]}}]

d=0.02; \[Lambda]=0.001; a=0.05;

sol=NDSolve[{deqn, u[x,0]==g[x,0.1], u[-10,t]==0, u[10,t]==0}, u, {x,-10,10}, {t,0,300}]

Plot3D[Evaluate[u[x,t]/.sol[[1]]], {x,-10,10}, {t,0,300}, PlotPoints->40, Mesh->False, PlotRange->All, AxesLabel->{length, time, density}]

Plot[Evaluate[{u[1, t]/.sol[[1]], u[5,t]/.sol[[1]]}], {t,0,300}, AxesLabel->{time, density}, PlotRange->All]


It is the skewness of the two distributions in the second plot that I'm after. Thanks.

You are confusing the PDF of the distribution with numbers that are distributed according to it.

Skewness works on distribution objects such as NormalDistribution and gives the skewness of that distribution.

Skewness also works on a list of data points and gives the skewness of the distribution of the data (or an estimate of it).

PDF[NormalDistribution[0, 1], Table[x, {x, -4, 4, 0.1}]] computes the probability density function of the normal distribution at regularly spaced points. These number are not normally distributed.

These are normally distributed: RandomVariate[NormalDistribution[0,1], 1000]. Their skewness will be close to zero.

• Yes, of course, that now makes perfect sense. Thanks for the quick response. However, despite the clarification on the question I posed, I still can't figure out how to solve my underlying problem: determining the skewness of a slice through my PDE solution. I'll add text to my original question to explain. Thanks – user12734 Mar 4 '14 at 15:28
• @user12734 What is the definition of skewness? Use the definition directly to derive the integral in terms of your function, then use Mathematica to numerically evaluate the integral. – Szabolcs Mar 4 '14 at 16:02
• Sorry, I'm not following. CentralMoment[list,3]/CentralMoment[list,2]^(3/2) or $\frac{\sqrt{n(n-1)}}{n-2}\frac{\frac{1}{n}\sum_{i=1}^{n}(x_i - \bar{x})^3}{(\frac{1}{n}\sum_{n=1}^{n}(x_i - \bar{x})^2)^{3/2}}$ – user12734 Mar 4 '14 at 18:00
• @user12734 That definition is valid for a set of points drawn from some distribution. It sounds like you want the skewness of a function. The first question for you is: what is the skewness of a function (not distribution)? I'm not asking you what the function Skewness does. I am asking you to tell me, in precise mathematical terms (not code), what you want to calculate. – Szabolcs Mar 4 '14 at 18:02
• If your supervisor asked you to calculate the "skewness" and you're not sure what he meant, you should ask him. – Szabolcs Mar 4 '14 at 18:04