简体   繁体   English

如何从R中的pareto密度函数生成随机数据?

[英]How to generate random data from pareto density function in R?

I am trying to generate data from given pareto density in R. 我正在尝试根据R中的给定pareto密度生成数据。

Pareto density: F(x) = |X|^(-3) * 1 |x|>1 帕累托密度:F(x)= | X | ^(-3)* 1 | x |> 1

I know that I need to use rpareto function from actuar library, but I am not sure how should I transform given pareto density into parameters. 我知道我需要使用执行器库中的rpareto函数,但是我不确定如何将给定的pareto密度转换为参数。

The Pareto distribution is simple enough to allow for the transformation method (aka Inverse Transform Sampling ). 帕累托分布足够简单,可以使用转换方法(也称为逆变换采样 )。 The CDF of the Pareto distribution is 帕累托分布的CDF为

$$F(x) = \\int_{x_{min}}^xf(x')\\,dx' = 1- \\left(\\frac{x_{min}}{x}\\right^k$$ $$ F(x)= \\ int_ {x_ {min}} ^ xf(x')\\,dx'= 1- \\ left(\\ frac {x_ {min}} {x} \\ right ^ k $$

which can be analytically inverted to 可以解析为

$$F^{-1}(y) = x_{min} \\cdot (1-y)^{-1/k}$$ $$ F ^ {-1-1(y)= x_ {min} \\ cdot(1-y)^ {-1 / k} $$

Thus, if you transform random numbers uniformly distributed on $(0,1)$ with $F^{-1}$, you obtain Pareto distributed random numbers. 因此,如果用$ F ^ {-1} $变换均匀分布在$(0,1)$上的随机数,则可以获得Pareto分布的随机数。

Edit: Oh sorry, apparently Latex-Code is not supported here. 编辑:抱歉,显然这里不支持Latex-Code。 Here is, for your convenince, the R code: 为了方便起见,这里是R代码:

k <- 5      # parameter k of the Pareto distribution
x.min <- 2  # cutoff point of Pareto distribution
N <- 500    # number of random points
x.random <- x.min*(1-runif(N))^(-1/k)

And here is the practical demonstration that it works: 这是可行的实际演示:

h <- hist(x.random, freq=FALSE, plot=TRUE)
x <- seq(x.min, h$breaks[length(h$breaks)], by=0.01)
lines(x, k*x.min^k/x^(k+1), col="red")

plot for k=5 and x.min=2 k = 5和x.min = 2的图

Using inverse sampling method, formulas from Pareto Distribution 使用逆采样方法,来自帕累托分布的公式

Here is updated version with mean and sd computed 这是带有平均值和标准差的更新版本

rpar <- function(n, xm, a) {
    v <- runif(n)
    xm / v^(1.0/a)
}

rpar_mean <- function(xm, a) {
    result <- 1/0 # Inf
    if (a > 1.0)
        result <- a*xm/(a - 1.0)
    result
}

rpar_var <- function(xm, a) {
    result <- 1/0 # Inf
    if (a > 2.0)
        result <- xm*xm*a/((a - 1.0)^2*(a - 2.0))
    result
}

set.seed(54122345)

xm = 1.0
a  = 3.0

q <- rpar(10000, xm, a)
print(mean(q))
print(rpar_mean(xm, a))

print(sd(q))
print(sqrt(rpar_var(xm, a)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 R 中已知密度函数的分布中生成随机值? - How to generate random values from a distribution with known density function in R? R:从概率密度分布生成数据 - R: Generate data from a probability density distribution 如何在r中生成概率密度函数和期望值? - How to generate a probability density function and expectation in r? 使用R生成具有密度对象的随机随机偏差 - Generate stochastic random deviates from a density object with R 如何在R中随机生成根据自己的密度function分布的数据? - How do I randomly generate data that is distributed according to my own density function in R? 从随机抽样中提取R中的近似概率密度函数(pdf) - Extract approximate probability density function (pdf) in R from random sampling 如何从R中的Pareto尾部的对数正态分布生成样本? - How can I generate a sample from a log-normal distribution with Pareto tail in R? 如何生成此 R function 以获得随机效应 model? - How to generate this R function for random effect model? 如何在R中生成随机缺失(MNAR)数据? - How to generate Missing Not at random (MNAR) data in R? 如何一次从 R 中的 kernel 密度 function 中提取多个样本的数据 - How can I extract data from a kernel density function in R for many samples at one time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM