On Sun, 10 May 2020 10:17:47 +0200 Luigi Marongiu <marongiu.lu...@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 ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.