I'm using cut() to transform data like this:

N <- 10

However, I do have many variables and I would like to determine what is the maximum acceptable N for variable. I thought this will be linked to unique values, but it is not that easy:

length(unique(iris$Sepal.Length)) # 35 unique values
    N <- 19
    ## Fails if N > 19

Is there a way how to calculate N or do I have to find this number iteratively?

Maybe this will be simpler case to work with:

N <- 4
x <- c(1,2,2,2,2,2,2,2,3,3,3,3,4,5,6,7,8)
  • $\begingroup$ What's your goal with the transformed data? $\endgroup$ – Thomas Jul 26 '13 at 9:02
  • $\begingroup$ I would like to use this as input to understand/plot relationship between variable and binary predictor. $\endgroup$ – Tomas Greif Jul 26 '13 at 9:07
  • $\begingroup$ Why not look at the raw data? $\endgroup$ – Thomas Jul 26 '13 at 9:10
  • 1
    $\begingroup$ The quantiles need to be unique. If the quantiles are unique depends on the data and the probabilities (the latter being calculated from N). The algorithm used by quantile is not exactly easy to understand and I don't think it is easily possible to predict if the quantiles are unique without calculating them. $\endgroup$ – Roland Jul 26 '13 at 9:13
  • 1
    $\begingroup$ I suggest to change your question to something like "How to calculate the maximum number of equidistant probability values from 0 to 1 that result in unique sample quantiles". That would make it a better fit for CV and is an interesting problem. $\endgroup$ – Roland Jul 26 '13 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.