Search code examples
rprobabilityecdf

Is it possible to extract the value of a function of multiple points using R?


Hello and thanks for reading!

I built an ecdf function using rstudio and I am trying to get the probabilities that correspond to certain points (list format). My R code looks like this:

input <- read.table('/home/agalvez/data/domains/test_ecdf.txt', sep="\t", header=TRUE)

#Build the function
myecdf <- ecdf(input$X118.4)
#Plot the function
plot(myecdf, main = "CDF", xlab = "Bit score", ylab = "Probability") +
abline(v = 25, col = "red")

#Extract probabilities
myecdf(100)

As you can see I am able to extract the probability of one point at a time. But if I try to get more than one I get an error message. I will now attach things that I have tried that did not work.

myecdf(100, 2, 4, ...)
Error in myecdf(100, 2, 4) : unused arguments (2, 4)
myecdf(100)
myecdf(2)
myecdf(4)
...
This approach gives me the results like this in the console:
> myecdf(100)
[1] 0.8048582
> myecdf(2)
[1] 1.382514e-05
> myecdf(4)
[1] 0.0005875684

I would like them to be a list.
myecdf(100,2,4,...)
Error in myecdf(100, 2, 4) : unused arguments (2, 4)

Any help would be really appreciated, sorry for disturbing with this simple question but I am pretty new to R and thanks in advance!


Solution

  • You have to define the wanted values as vector:

    myecdf(c(100, 2, 4))