[R] How to determine whether a value belong to a cumulative distribution?

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Sun May 10 14:02:43 CEST 2020


On Sun, 10 May 2020 10:17:47 +0200
Luigi Marongiu <marongiu.luigi using gmail.com> wrote:

>If I do, as in the formula:
>```
>> p = 2 * (1-cum_fun)  
>Error in 1 - cum_fun : non-numeric argument to binary operator
>```

The ecdf function returns another function that calculates the ECDF
value for an arbitrary input. For example,

e <- ecdf(1:10)
e
# Empirical CDF
# Call: ecdf(1:10)
#  x[1:10] =      1,      2,      3,  ...,      9,     10
e(c(-1, 5, 100)) # call the returned value as a function
# [1] 0.0 0.5 1.0

If you want to see the empirical distribution function values for the
points of the dataset itself, call the function returned by ecdf with
the same data again:

x <- 1:10
ecdf(x)(x)
# [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

If you want to calculate the CDF for a given value of 1 ± |r|, pass
this value as an argument to the function returned by ecdf:

cum_fun <- ecdf(abs(x[1:n])
p <- 2 * (1 - cum_fun(1 - abs(r)))

On the other hand, given the quotes from the text, I think than you
might need to use the theoretical t distribution function (available as
`dt` in R) in the formula instead of ECDF:

df <- ... # degrees of freedom for Student t distribution
p <- 2 * (1 - dt(1 - abs(r), df))

I am not sure about that, though.

-- 
Best regards,
Ivan



More information about the R-help mailing list