Question: 1 Creating an ECDF Function Empirical Cumulative Distribution Functions ( ECDFs ) are approximations to true Cumulative Distribution Functions. The function is defined as hat

1 Creating an ECDF Function
Empirical Cumulative Distribution Functions (ECDFs) are approximations to true Cumulative Distribution
Functions. The function is defined as
hat(F)n(x)=1n(numberof values x),
for n the sample size. In other words, count how many of the set of n values are less than or equal to a given
value x, then that is the function evaluation at that x.
Now, obviously to do this for all x is impossible, even on a computer, as there are infinite number of x's on
the real line. So, instead, we compute ECDFs on a finite, discrete mesh of values, e.g., all multiples of 0.01
between 0 and 3. The range needs to be carefully chosen to cover all of the values in the sample, and the
multiple needs to be chosen small enough to ensure the plot is useful and sensible.
Implement your own function in R which creates an ECDF given an input dat, consisting of n real numeric
values. That is, your function should resemble:
You will need to determine the range for the x values, set a step for your mesh, then determine the y values
that correspond to the x's. Store these two vectors (which will be quite large!) together in a data.frame object
called ecdf, so the final line of the function will return the data.frame of both x and y.
Ensure your function is defined in a chunk which is set to be visible, so the code can be evaluated.
2 Testing your Implementation
As with TC06, there is a data set included with R called ToothGrowth, which can be loaded using
library ("datasets")
data (ToothGrowth)
Use this data to generate an empirical CDF (ECDF) hat(F)n(x) of the tooth growth (len) of guinea pigs after
receiving one of three dose (dose) levels of one of two supplements (supp). Plot an ECDF of the growth, with
appropriate labels. You must use your self-developed code to generate the x and y pairs for the plot.
1 Creating an ECDF Function Empirical Cumulative

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!