在 R 中将一个 rnorm 作为另一个 rnorm 的参数是什么意思?
What does it mean to put an `rnorm` as an argument of another `rnorm` in R?
当一个 rnorm
被用作另一个 rnorm
的参数之一时,我很难理解这意味着什么? (我会在下面详细解释)
例如,在下面,在我的 R 代码的第一行中,我使用了 rnorm()
,我称之为 rnorm()
:mu
。
mu
包含 10,000 x
.
现在,让我把 mu
本身作为一个名为 "distribution" 的新 rnorm()
的 mean
参数。
我的问题是 mu
本身有 10,000 x
如何用作这个新的 rnorm()
分布的 mean
参数?
P.S.: mean
任何 normal distribution
的参数可以是单个数字,并且只有一个单一的均值,我们将有一个单一的、完整的正常。现在,为什么使用 10,000 个 mu
值仍然会导致单个法线?
mu <- rnorm( 1e4 , 178 , 20 ) ; plot( density(mu) )
distribution <- rnorm( 1e4 , mu , 1 ) ; plot( density(distribution) )
你distribution
是条件密度。虽然您使用 plot(density(distribution))
绘制的密度是 边缘密度 。
从统计学上讲,您首先有一个正常的随机变量 mu ~ N(178, 20)
,然后是另一个随机变量 y | mu ~ N(mu, 1)
。你制作的地块是y
.
的边际密度
P(y)
,在数学上是联合分布P(y | mu) * p(mu)
的积分,积分出mu
.
@李哲源ZheyuanLi, ahhh! so when we use a vetor as the mean argument or sd argument of an rnorm, the single, final plot is the result of the integral, right?
这意味着您正在从边际分布中抽样。密度估计近似于样本的 Monte Carlo 积分。
贝叶斯计算中经常看到这种东西。 给出了一个完整的例子,但是积分是通过数值积分计算的。
当一个 rnorm
被用作另一个 rnorm
的参数之一时,我很难理解这意味着什么? (我会在下面详细解释)
例如,在下面,在我的 R 代码的第一行中,我使用了 rnorm()
,我称之为 rnorm()
:mu
。
mu
包含 10,000 x
.
现在,让我把 mu
本身作为一个名为 "distribution" 的新 rnorm()
的 mean
参数。
我的问题是 mu
本身有 10,000 x
如何用作这个新的 rnorm()
分布的 mean
参数?
P.S.: mean
任何 normal distribution
的参数可以是单个数字,并且只有一个单一的均值,我们将有一个单一的、完整的正常。现在,为什么使用 10,000 个 mu
值仍然会导致单个法线?
mu <- rnorm( 1e4 , 178 , 20 ) ; plot( density(mu) )
distribution <- rnorm( 1e4 , mu , 1 ) ; plot( density(distribution) )
你distribution
是条件密度。虽然您使用 plot(density(distribution))
绘制的密度是 边缘密度 。
从统计学上讲,您首先有一个正常的随机变量 mu ~ N(178, 20)
,然后是另一个随机变量 y | mu ~ N(mu, 1)
。你制作的地块是y
.
P(y)
,在数学上是联合分布P(y | mu) * p(mu)
的积分,积分出mu
.
@李哲源ZheyuanLi, ahhh! so when we use a vetor as the mean argument or sd argument of an rnorm, the single, final plot is the result of the integral, right?
这意味着您正在从边际分布中抽样。密度估计近似于样本的 Monte Carlo 积分。
贝叶斯计算中经常看到这种东西。