library(HyperbolicDist) ### Gamma distribution k <- 4 shape <- 2 old <- 0 new <- 1 sampSize <- 1000000 ### Calculate 1st to 4th raw moments m <- numeric(k) for (i in 1:k){ m[i] <- gamma(shape + i)/gamma(shape) } m ### Calculate 4th moment about new momChangeAbout(k, m, old, new) ### Calculate 3rd about new momChangeAbout(3, m, old, new) ### Calculate 1st to 4th moments about new momChangeAbout(oldMom = m, oldAbout = old, newAbout = new) momChangeAbout(order = "all", m, old, new) ### Approximate kth moment about new using sampling x <- rgamma(sampSize, shape) mean((x - new)^k)