我有一个多参数函数,我使用MCMC推断出参数。这意味着我有很多参数样本,我可以绘制函数:
# Simulate some parameters. Really, I get these from MCMC sampling.
first = rnorm(1000) # a
second = rnorm(1000) # b
# The function (geometric)
geometric = function(x, a, b) b*(1 - a^(x + 1)/a)
# Plot curves. Perhaps not the most efficient way, but it works.
curve(geometric(x, first[1], second[1]), ylim=c(-3, 3)) # first curve
for(i in 2:length(first)) {
curve(geometric(x, first[i], second[i]), add=T, col='#00000030') # add others
}
如何将其制作成密度图而不是绘制单个曲线?例如,很难看到y = 0周围的密度大于其他值的密度。
以下情况会很好: