简体   繁体   English

R 使用同一个库给出的不同时刻

[英]Different moments given by R using the same library

I'm using R along with library moments to generate a small dataset and compute the four initial moments of my data:我使用R和库moments来生成一个小数据集并计算我的数据的四个初始时刻:

  1. Mean意思是
  2. Variation变化
  3. Skewness偏度
  4. Kurstosis峰态

The code is shown below.代码如下所示。 I set a random seed for my PRNG and generates 1000 data points using a normal distribution.我为我的 PRNG 设置了一个随机种子,并使用正态分布生成 1000 个数据点。
Then, I print four moments two ways.然后,我以两种方式打印四个时刻。 First, I print then individually.首先,我单独打印。 Then, I print them using the method all.moments .然后,我使用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这些应该事后计算

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM