I am looking at the sample kurtosis of a fairly skewed random variable, and the results seem inconsistent. To simply illustrate the problem, I looked at the sample kurtosis of a log-normal RV. In R (which I am slowly learning):
library(moments);
samp_size = 2048;
n_trial = 4096;
kvals <- rep(NA,1,n_trial); #preallocate
for (iii in 1:n_trial) {
kvals[iii] <- kurtosis(exp(rnorm(samp_size)));
}
print(summary(kvals));
The summary I get is
Min. 1st Qu. Median Mean 3rd Qu. Max.
11.87 28.66 39.32 59.17 61.70 1302.00
According to Wikipedia, the kurtosis for this log-normal RV should be around 114. Clearly the sample kurtosis is biased.
Doing some research I found that sample kurtosis is biased for small sample sizes. I used the 'G2' estimator as provided by the e1071 package in CRAN, and got very similar results for this sample size.
The question: which of the following characterize what is going on:
- The standard error of the sample kurtosis is simply very large for this RV (even though the hand-wavey common estimate of the standard error is of order $1/\sqrt{n}$). Alternatively, I used too few samples (2048) in this study.
- These implementations of sample kurtosis suffer from numerical problems which might be corrected by e.g. Terriberry's method (in much the same way that Welford's method gives better results than the naive method for sample variance).
- I computed the population kurtosis incorrectly. (ouch)
- Sample kurtosis is inherently biased and you can never fix it for such small sample sizes.
;on the ends of your statements. You did right to pre-allocate, but no need to fill withNA,kvals <- numeric(length = n_trial)would have sufficed. Withrep, you only need arguments 1 and 3 from your call (e.g.rep(NA, 10)). In theforloop set-up,1:n_trialcan be dangerous if programming; better isseq_along(kvals)orseq_len(n_trial)in this case. Finally, if you don't need to force printing, drop theprint()roundsummary()- you'd only need it if you weren't working interactively with R. HTH. – Gavin Simpson Dec 8 '10 at 8:28print. The args torepwere certainly erroneous. – shabbychef Dec 8 '10 at 17:46