# Why doesn't the kurtosis function work properly for complex numbers?

16 views (last 30 days)

Show older comments

Guillem Foreman
on 20 Sep 2022

Edited: David Goodmanson
on 23 Sep 2022

Good morning,

I was trying out the kurtosis function on Matlab with complex numbers, using the following code:

var = sqrt(1/2) * randn(1,1000) + 1i * sqrt(1/2) * randn(1,1000);

var_kurt = kurtosis(var);

I was expecting var_kurt to equal 3, since I'm calculating the kurtosis of a gaussian distributed complex function, but instead I get a value of 68.7674 +18.3410i. However, kurtosis(real(var)) does equal 3, which surprises me since the kurtosis should not depend on the variable being complex. Any idea why this happens?

Thanks very much in advance,

Guillem

##### 1 Comment

Star Strider
on 20 Sep 2022

### Accepted Answer

David Goodmanson
on 20 Sep 2022

Edited: David Goodmanson
on 22 Sep 2022

Hi Guillem,

Both the standard deviation and the variance (std and var) work correctly for complex argument, so kurtosis appears to be a bug in the sense that if Matlab does the other two correctly, why not this one?

For complex data the mean stays complex, and the variance is the sum of (absolute distance)^2 from the mean. For

n = 1e6;

y = sqrt(1/2)*randn(1,n) + i*sqrt(1/2)*randn(1,n);

m = mean(y);

vcalc = sum(abs(y-m).^2)/n

v = var(y,1)

v and vcalc are identical.

The variance uses the '1' option because that version is used to find kurtosis. With the '1' option, the variance is

sum(abs(y-m).^2)/n;

otherwise var divides by (n-1). I wish dividing by n was the default, but somebody else makes the rules.

For kurtosis you need [4th moment about the mean] / [2nd moment about the mean]^2, so the obvious thing to do is

mom2 = sum(abs(y-m).^2)/n % same as vcalc and var(..,1)

mom4 = sum(abs(y-m).^4)/n

kcalc = mom4/mom2^2

k = kurtosis(y)

For real data, these last two agree. For samples from a real normal distribution the kurtosis is close to 3 (not exactly 3 since you are sampling from the distribution) which is correct. For the complex normal distribution used in your code the kurtosis is close to 2, also correct.

As for Matlab kurtosis, it is treating the complex variable just as it would a real variable, which means leaving out the 'abs' in the calculations of the moments above. This leads to a meaningless complex value for kurtosis.

##### 7 Comments

David Goodmanson
on 23 Sep 2022

Hi Paul,

Oh, it seemed like things were just getting going. What I meant was, the first moment <z> is complex in general, and that property must be retained when computing the variance. |<z>| is a quantity that does no good when subtracting off the mean. Absolute values only come in with the variance, < |(z-<z>)|^2 >.

I modified my previous comment to mention that in the kurtosis formula the z's are assumed to already have the mean subtracted off, so <z> = 0.

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!