diff --git a/functions.Rmd b/functions.Rmd index 5635dd2..77f6cfe 100644 --- a/functions.Rmd +++ b/functions.Rmd @@ -150,9 +150,16 @@ This is an important part of the "do not repeat yourself" (or DRY) principle. Th sd(x, na.rm = TRUE) / mean(x, na.rm = TRUE) ``` -1. Follow to - write your own functions to compute the variance and skew of a numeric - vector. +1. write your own functions to compute the variance and skewness of a numeric vector. + Variance is defined as + $$ + \mathrm{Var}(x) = \frac{1}{n - 1} \sum_{i=1}^n (x_i - \bar{x}) ^2 \text{,} + $$ + where $\bar{x} = (\sum_i^n x_i) / n$ is the sample mean. + Skewness is defined as + $$ + \mathrm{Skew}(x) = \frac{\frac{1}{n-2}\left(\sum_{i=1}^n(x_i - \bar x)^3\right)}{\mathrm{Var}(x)^{3/2}} \text{.} + $$ 1. Write `both_na()`, a function that takes two vectors of the same length and returns the number of positions that have an `NA` in both vectors.