使用一些数据获得概率以将正态分布与 R 拟合

时间:2021-03-23 18:02:28

标签: r distribution

我得到了这些数据,我需要拟合正态分布才能得到另一组与发生概率相关的数据。

data = c(150,94.1,127.6,77.2,136.1,83.4,75.6,92.7,106.5,95.9,112.1,90.4,143.7,152.7,113.3,143.9,87.9,85.2,117.2,193,153.7,84.7,97.3,140.3,80,103.6,72.6,90.7,52.6,52.8)

然后是发生的概率:

returntime = c(1.02,1.5,2,3,4,5,6,7,8,9,10,15,20,25,30,50,100,200,500,1000,5000,10000) #years
prob_returntime = 1/returntime #need to get the data associated with this prob.

我曾尝试使用 qnorm(),但我认为我做错了什么...

预期输出:

enter image description here

1 个答案:

答案 0 :(得分:2)

如果您想找到对应于 data 的正态分布的分位数,但对于 1 - prob_returntime 的值,我们可以执行以下操作。

代码

# Estimate mean and standard deviation from your data
mu <- mean(data)
std <- sd(data)

# then use qnorm to get quantiles of data associated with return prob

data.frame("return_time" = returntime, "probability" = 1/returntime,
           "data value" = qnorm(1 - (1 / returntime), mu, std))
   

#    return_time probability data.value
# 1         1.02  0.98039216   38.94683
# 2         1.50  0.66666667   92.69954
# 3         2.00  0.50000000  106.89333 
# 4         3.00  0.33333333  121.08712
# 5         4.00  0.25000000  129.11985
# 6         5.00  0.20000000  134.62735
# 7         6.00  0.16666667  138.77285
# 8         7.00  0.14285714  142.07307
# 9         8.00  0.12500000  144.80089
# 10        9.00  0.11111111  147.11719
# 11       10.00  0.10000000  149.12440
# 12       15.00  0.06666667  156.35874
# 13       20.00  0.05000000  161.09633
# 14       25.00  0.04000000  164.58383
# 15       30.00  0.03333333  167.32647
# 16       50.00  0.02000000  174.57069
# 17      100.00  0.01000000  183.55366
# 18      200.00  0.00500000  191.77484
# 19      500.00  0.00200000  201.73763
# 20     1000.00  0.00100000  208.72601
# 21     5000.00  0.00020000  223.55000
# 22    10000.00  0.00010000  229.44638

相关问题