-1

When using ecdf() (or Ecdf ) in R, I get a number of knots equal to around 500. However, I need a number of knots that reflects the number of observations I have in the original dataset (in my case, 300).

How can I adjust the number of knots in ecdf? Or, is it possible?

Below is the R code:

install.packages("Hmisc");
library(Hmisc)

nobs <- 300
g1_true <- 2
eps <- rnorm(nobs, 3.5,2.1)
Z <- rbinom(n=nobs, size=3, p=0.5) 

P <- g1_true*Z + eps 

# marginal density for P
h.p <- density(P,bw="nrd0", kernel="epanechnikov")$y

# get the marginal distribution H(p)
H.p <- ecdf(h.p)
length(knots(H.p))
ralucaGui
  • 73
  • 5
  • I found the solution - it is in the density() function. The default is n=512 knots. If I change that to 300 , or the length of the dataset it works fine. – ralucaGui May 18 '15 at 12:12
  • If you've found your own solution, please post it as an answer and accept it to close out the question and to be of help to others in the future. – MrFlick May 18 '15 at 15:29

1 Answers1

0

The solution is in the density() function called before the ecdf() function. The density() function has a parameter n, which by default is 512. Changing that to whatever number is suitable for one's question will change the number of knots of the ecdf function, if ecdf is applied to the result of the density function call.

e.g.

H <- density(P, n=length(P))$x
H.ecdf <- ecdf(H)
ralucaGui
  • 73
  • 5