Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:10:29+00:00 2026-06-16T19:10:29+00:00

I wanted to follow up on a question asked before about the all.moments function

  • 0

I wanted to follow up on a question asked before about the all.moments function from the moments package: all.moments function weird outcome

The distribution – specifically the asymptotic variance – of the output of all.moments does not seem to align with standard theory for the 3rd and 4th moments, or I am doing something incorrectly.

Consider the following code:

reps <- 100000                              # number of repetitions
n <- 1000000                                # sample size
asy.cmtx <- matrix(0,nrow=reps,ncol=5)      # initialize our matrix of conventional moments
for(i in 1:reps){
vec <- rnorm(n,mean=0,sd=1)               # create vector of 1M standard normals
asy.cmtx[i,] <- all.moments(vec,order.max=5)[2:6]    # get sample moments 
}
mean(asy.cmtx[,3])             # this should be 0
# [1] 3.972406e-06
mean(asy.cmtx[,4])            # this should be 3
# [1] 2.999996
var(sqrt(n)*asy.cmtx[,3]/(asy.cmtx[,2]^(3/2)))     # this should be 6
# [1] 14.41766
var(sqrt(n)*(asy.cmtx[,4]-3)/(asy.cmtx[,2]^(2))) # this should be 24
# [1] 96.25745

The asymptotic variance seems larger than expected.

I went back and simply used the sample moment formulae that we all know and got the correct outcome:

reps <- 100000                              # number of repetitions
n <- 1000000                                # sample size
asy.34.2 <- matrix(0,nrow=reps,ncol=2)      # initialize our matrix of conventional moments
for(i in 1:reps){
y <- rnorm(n,mean=0,sd=1)               # create vector of 1M standard normals
y.bar <- mean(y)
m2 <- ((1/n)*sum((y-y.bar)^2))
asy.34.2[i,1] <- ((1/n)*sum((y-y.bar)^3))/(m2^(3/2))
asy.34.2[i,2] <- ((1/n)*sum((y-y.bar)^4))/(m2^2)
}

mean(asy.34.2[,1])
# [1] 7.512593e-06
mean(asy.34.2[,2])
# [1] 2.999985
var(sqrt(1000000)*asy.34.2[,1])     # this should be 6
# [1] 5.990771
var(sqrt(1000000)*(asy.34.2[,2]-3)) # this should be 24
# [1] 24.23367                    

So the actual formulae have the variance that we would expect, but all.moments does not, even though it has the proper expectation. This should not be an issue due to sample size or number of iterations because both are large in this case (1M and 100k respectively in both cases). Has anyone had this issue before?

Also, has anyone had issues with R simply dropping your output? When I attempted to manipulate the output above, somehow the output “vanished”, with dim = NULL. However if the first thing I do is write.csv() the data, I can then read it back in and manipulate without it vanishing on me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:10:30+00:00Added an answer on June 16, 2026 at 7:10 pm

    There are two errors: (1) as flodel points out you need central moments not raw moments, this won’t make much difference for point estimates of the moments but it does make a difference for estimates of their variance; (2) there is a bug in the computation of the kurtosis when using all.moments. When we apply these corrections we have:

    reps <- 1000                              
    n <- 100000
    

    …

        asy.cmtx[i,] <- all.moments(vec,order.max=5, central = TRUE)[2:6]
    

    …

    var(sqrt(n)*asy.cmtx[,3]/(asy.cmtx[,2]^(3/2)))     # this should be 6
    # [1] 5.993772
    var(sqrt(n)*(asy.cmtx[,4])/(asy.cmtx[,2]^(2)) - 3) # this should be 24
    # [1] 23.89204
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to follow up on a question I previously asked which I'm still
Following on from another question I asked, Scala 2.8 breakout , I wanted to
Earlier today I asked a question about passing dictionary values to a function. While
This is a follow-up question to a different question I asked not too long
This is a follow-up from this question . Functions are not allowed to write
This is a follow-up of this question . I wanted to plot multiple curves
This is follow on from this question: Format List<T> to concatenate fields . The
After following this question on updating a GUI from another thread I wanted to
A persistent follow-up of an admittedly similar question I had asked: What security restrictions
this is a follow up question from my previous one. you can find it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.