R中dpareto的功能

时间:2013-02-07 11:26:45

标签: r statistics

我想知道是否有人用R写的dpareto函数?

我无法在R中使用in built函数,因为我无法安装库。

谢谢!

1 个答案:

答案 0 :(得分: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")