From 5082dd8bfd3036b327fe15c8af022688746f407a Mon Sep 17 00:00:00 2001 From: Jeffrey Arnold Date: Wed, 15 Jan 2020 10:41:22 -0800 Subject: [PATCH] Add equations to 19.2 Ex 4. (#749) The question asks: > Follow to write your own functions to compute the variance and skew of a numeric vector. However, the math on that page no longer renders. Directly include the skew and variance equations in the question. --- functions.Rmd | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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.