R中超出概率的计算和生成图

问题描述 投票:0回答:1

我正在尝试在R中计算probability of exceedance。这是link,其中包含用于计算超出概率的详细信息和公式。我尝试使用以下示例代码来复制该过程,但是,我离所附的示例绘图很近。一次,我想出了该怎么做的方法-然后我想将该过程应用于具有多个data.framevariables

library(tidyverse)

A = sample(0:5000, 2500)
A = A[order(A, decreasing = TRUE)]
Rank = 1:2500

DF = data.frame(cbind(A,Rank))
DF$Prob =  100*(DF$Rank/(length(DF$Prob+1)))

ggplot(data = DF, aes(x=Prob, y=A))+
  geom_line() + scale_y_continuous(trans = "log10")

这里是我想制作的地块的样本enter image description here

r ggplot2 statistics probability
1个回答
0
投票

计算Prob的公式在该问题中没有很好地实现。它在DF$Prob上加1,然后在应在length上加1时取其lengthDF <- data.frame(A, Rank) DF$Prob <- DF$Rank/(length(DF$Rank) + 1) ggplot(data = DF, aes(x = Prob, y = A)) + geom_line() + scale_x_continuous(breaks = seq(0, 1, by = 0.20), labels = percent) + scale_y_continuous(trans = "log10")

enter image description here

数据创建代码。

我已更改数据集示例。由于使用了set.seed并且sample的概率降低,因此下面的代码是可重现的。

set.seed(1234) A <- sample(0:5000, 2500, prob = exp(seq(10, 0, length.out = 5001))) A <- A[order(A, decreasing = TRUE)] Rank <- 1:2500

© www.soinside.com 2019 - 2024. All rights reserved.