1

我想知道是否有人有用 R 编写的 dpareto 功能?

我无法使用 R 中的内置函数,因为我无法安装库。

谢谢!

4

1 回答 1

2

从 R 包中删除函数相对容易,例如,从:

http://cran.r-project.org/web/packages/VGAM/VGAM.pdf

dpareto <- function(x, location, shape, log = FALSE) {
    if (!is.logical(log.arg <- log) || length(log) != 1)
        stop("bad input for argument 'log'")
    rm(log)

    L = max(length(x), length(location), length(shape)) 
    x = rep(x, length.out = L);
    location = rep(location, length.out = L);
    shape = rep(shape, length.out = L)

    logdensity = rep(log(0), length.out = L)
    xok = (x > location)
    logdensity[xok] = log(shape[xok]) + shape[xok] * log(location[xok]) -
            (shape[xok]+1) * log(x[xok])
    if (log.arg) logdensity else exp(logdensity)
}

alpha <- 3; k <- exp(1); x <- seq(2.8, 8, len = 300)
## Not run: 
plot(x, dpareto(x, location = alpha, shape = k), type = "l",
        main = "Pareto density split into 10 equal areas")
于 2013-02-07T11:43:10.173 回答