简体   繁体   English

使用R的概率转换

[英]Probability transformation using R

I want to turn a continuous random variable X with cdf F(x) into a continuous random variable Y with cdf F(y) and am wondering how to implement it in R. 我想将具有cdf F(x)的连续随机变量X转换为具有cdf F(y)的连续随机变量Y ,并且想知道如何在R中实现它。

For example, perform a probability transformation on data following normal distribution (X) to make it conform to a desirable Weibull distribution (Y). 例如,对遵循正态分布(X)的数据执行概率转换,以使其符合所需的威布尔分布(Y)。

(x=0 has CDF F(x=0)=0.5, CDF F(y)=0.5 corresponds to y=5, then x=0 corresponds to y=5 etc.) (x = 0的CDF F(x = 0)= 0.5,CDF F(y)= 0.5对应y = 5,然后x = 0对应y = 5等)

There are many built in distribution functions, those starting with a 'p' will transform to a uniform and those starting with a 'q' will transform from a uniform. 有许多内置的分布函数,以“ p”开头的函数将转换为统一的,以“ q”开头的函数将转换为统一的。 So the transform in your example can be done by: 因此,示例中的转换可以通过以下方式完成:

y <- qweibull( pnorm( x ), 2, 6.0056 )

Then just change the functions and/or parameters for other cases. 然后只需更改其他情况下的功能和/或参数即可。

The distr package may also be of interest for additional capabilities. distr包也可能对其他功能感兴趣。

In general, you can transform an observation x on X to an observation y on Y by 通常,您可以通过以下方式将X上的观测值x转换为Y上的观测值y

  • getting the probability of X≤x, ie F X (x). 得到X≤x的概率,即F X (x)。
  • then determining what observation y has the same probability, 然后确定哪些观测值y具有相同的概率,

Ie you want the probability Y≤y = F Y (y) to be the same as F X (x). 也就是说,您希望概率Y≤y= F Y (y)与F X (x)相同。

This gives F Y (y) = F X (x). 这样得出F Y (y)= F X (x)。

Therefore y = F Y -1 (F X (x)) 因此y = F Y -1 (F X (x))

where F Y -1 is better known as the quantile function, Q Y . 其中F Y -1更好地称为分位数函数Q Y。 The overall transformation from X to Y is summarized as: Y = Q Y (F X (X)). 从X到Y的整体转换总结为:Y = Q Y (F X (X))。

In your particular example, from the R help, the distribution functions for the normal distribution is pnorm and the quantile function for the Weibull distribution is qweibull , so you want to first of all call pnorm , then qweibull on the result. 在您的具体的例子,从R的帮助下,正态分布的分布函数是pnorm和Weibull分布的分位数功能是qweibull ,所以要首先调用pnorm ,然后qweibull的结果。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM