I'm using R
along with library moments
to generate a small dataset and compute the four initial moments of my data:
The code is shown below. I set a random seed for my PRNG and generates 1000 data points using a normal distribution.
Then, I print four moments two ways. First, I print then individually. Then, I print them using the method all.moments .
library(moments)
set.seed(123)
x = rnorm(1000, sd = 0.02)
print(mean(x));
print(var(x));
print(skewness(x))
print(kurtosis(x))
print(moments::all.moments(x, order.max = 4))
The outputs are shown below.
print(mean(x));
0.0003225573
print(var(x));
0.0003933836
print(skewness(x));
0.06529391
print(kurtosis(x));
2.925747
print(moments::all.moments(x, order.max = 4));
1.000000e+00 3.225573e-04 3.930942e-04 8.889998e-07 4.527577e-07
One may note that both the skewness and the kurtosis of both methods are different.
My question is: Why they give different results? Which result is the right one?
Note that the third and fourth moments are NOT the skewness and kurtosis. These should be calculated afterwards
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.