Question
You will need the SaratogaHouses data set, which is in the mosaicData package. This is done within the program R. 1) Measuring skew A variable
You will need the SaratogaHouses data set, which is in the mosaicData package. This is done within the program R.
1) Measuring skew
A variable is called skewed if it has a long tail or outliers on one side. (For some visual examples, see http://www.statisticshowto.com/probability-and-statistics/skewed-distribution/.) One numerical measure of skewness is Pearson's median skewness coefficient:
$\frac{3*(mean(x) - median(x))}{sd(x)}$
(Recall that sd stands for standard deviation. Notice that a coefficient > 0 indicates right skewness, and a coefficient < 0 indicates left skewness.)
1a.
Write a function, `pearson_skew`, which computes Pearson's median skewness coefficient for a vector x. (For now, you may assume that x contains only numeric values and no NAs.)
Use your function to compute Pearson's median skewness coefficient for the vector `example_1a`:
example_1a = c( 1, 1, 2, 10 )
1b.
Modify function so it accepts additional arguments (such as na.rm = TRUE) and passes them to the functions it calls.
Use your function to compute Pearson's median skewness coefficient for the vector `example_1b`:
example_1b = c( 1, 2, 5, NA, 9 )
```
1c.
Modify your function so it returns two pieces of output: The skewness coefficient, and the length of the vector.
Run the following code (without changes) to create the vector `example_1c`.Then find what `pearson_skew` returns when applied to this vector.
set.seed(999)
example_1c = rexp(floor(runif(1, 101, 199)), 2)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started