Using ks.test to check generated random values with an empirical cumulative distribution function

14 Views Asked by At

I was given a task to generate pseudo-random numbers from the seed that could fit to the given distribution function (and use with ks.test to test it.) However, my code seems to be faulty. I followed the steps we used in our practice questions (only found empirical cumulative function, that was mentioned in our lecture, was found from internet.) I’m quite a beginner in R and I do not know how to fix the code. I appreciate your help and tips.

set.seed(seed)
n<-10000
u<- runif(10000)

F <- function(x){
  return(((x + 9)^2) / ((6 + 9 + 1)^2)*(x >= -9)*(x<7)+
           1*(x >= 7))
}

# empirical
ecdf <- ecdf(u)
ks_test <- ks.test(ecdf, F)
#Error in x[!is.na(x)] : object of type 'closure' is not subsettable
In addition: Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'closure'