# Simulate data from ECDF in R [closed]

Consider the following 11 continuous non-negative observations:

0, 0.3, 0.31, 0.33, 0.37, 0.49, 0.51, 0.53, 0.59, 0.6

1. Obtain the empirical cumulative distribution function for these observations.
2. Use the inversion method to simulate 1000 readings from this ECDF.

I tried using:

A<-c(0, 0.3, 0.31, 0.33, 0.37, 0.49, 0.51, 0.53, 0.59, 0.6)
ecdf(A)
plot.ecdf(A, main="ECDF of sample")


But this was I cannot get the function, and hence cannot simulate. Any ideas please?

• You might want to look at a combination of runif and the quantile function, with careful consideration which type is most suitable here – Henry Feb 12 '20 at 23:46
• What do you mean by "cannot get the function"? – Peter Flom Feb 13 '20 at 11:25

A <- c(0, 0.3, 0.31, 0.33, 0.37, 0.49, 0.51, 0.53, 0.59, 0.6)
e <- ecdf(A)
plot.ecdf(A, main="ECDF of sample")


e is a function giving the ECDF of A.

It's a bit late so I'm quite tired, but I think for the inversion method, you need to obtain the inverse CDF, and to transform 1,000 uniformly distributed numbers using the inverse CDF. This is, as is said in the literature, left as an exercise for the reader.

By the way, this seems like a homework assignment. You should tag it as such (self-study).

ecdf(A) is a function, so you call that function by giving it an argument. e.g ecdf(A)(x).

However, you can sample that ecdf just using sample (by sampling A with replacement).