Skewness and Kurtosis

Problem

Suppose we have a vector of numbers x.

Give R code to compute the observed moments of x around zero of order one to four (i.e. the average of the powers one to four of the elements of x).
Give R code to compute the observed moments of x around the mean of order one to four (i.e. the average of the powers one to four of the elements of x in deviations from the mean).
Give R code to compute the skewness and kurtosis of x.
Code

Preferred format is three R functions that take the vector x as an argument and return a list or vector of results. The functions can call each other if that seems desirable. Try to avoid loops. Do not use builtin function such as mean or var, except possible for checking your results.

Definitions

Skewness is defined (in terms of moments around the mean) as
γ1=μ3(μ2)3/2,
while kurtosis is
γ2=μ4μ22−3.
Test on generated numbers

Use built-in R functions such as rnorm(), rcauchy(), rlaplace() and rchisq() to generate random vectors (say of length 1000) to try out your code. Generate a table with skewness and kurtosis results for these four distributions (see the Markdown Quick Reference document in RStudio on how to make tables). Do not print a table directly from R, collect the results that are needed and then put them in a Markdown table.

 

  • 9 years ago
Skewness and Kurtosis
NOT RATED

Purchase the answer to view it

blurred-text
  • attachment
    answer.docx
  • attachment
    data.xlsx