问题描述
我很难理解将rnorm
用作另一个rnorm
的参数之一是什么意思? (我将在下面详细说明)
I have difficulty understanding what it means when an rnorm
is used as one of the arguments of another rnorm
? (I'll explain more below)
例如,在下面的R代码的第一行中,我使用rnorm()
,并将其称为rnorm()
:mu
.
For example, below, in the first line of my R code I use an rnorm()
and I call this rnorm()
: mu
.
mu
由10,000个x
组成.
mu
consists of 10,000 x
.
现在,让我将mu
本身作为新的rnorm()
的mean
自变量,称为分发".
Now, let me put mu
itself as the mean
argument of a new rnorm()
called "distribution".
我的问题是,如何将本身具有10,000个x
的mu
用作这个称为分发的新rnorm()
的mean
自变量?
My question is how mu
which itself has 10,000 x
be used as the mean
argument of this new rnorm()
called distribution?
P.S .:任何normal distribution
的mean
自变量可以是一个数字,并且只有一个均值,我们将有一个完整的正态.现在,为什么使用10,000个mu
值仍然会产生一个法线?
P.S.: mean
argument of any normal distribution
can be a single number, and with only ONE single mean, we will have a single, complete normal. Now, how come, using 10,000 mu
values still results in a single normal?
mu <- rnorm( 1e4 , 178 , 20 ) ; plot( density(mu) )
distribution <- rnorm( 1e4 , mu , 1 ) ; plot( density(distribution) )
推荐答案
您distribution
是条件密度.使用plot(density(distribution))
绘制的密度是边际密度.
You distribution
is a conditional density. While the density you draw with plot(density(distribution))
, is a marginal density.
从统计学上讲,您首先拥有一个正常的随机变量mu ~ N(178, 20)
,然后是另一个随机变量y | mu ~ N(mu, 1)
.您生成的图是y
的边际密度.
Statistically speaking, you first have a normal random variable mu ~ N(178, 20)
, then another random variable y | mu ~ N(mu, 1)
. The plot you produce is the marginal density of y
.
P(y)
,在数学上是关节分布P(y | mu) * p(mu)
的积分,并整合为mu
.
P(y)
, is mathematically an integral of joint distribution P(y | mu) * p(mu)
, integrating out mu
.
这意味着您正在从边际分布中采样.密度估计值近似于样本中的蒙特卡洛积分.
It means you are sampling from the marginal distribution. The density estimate approximates the Monte Carlo integral from samples.
这种事情在贝叶斯计算中很常见. 关于正态分布均值[降雪量的数据]的贝叶斯推理上的Toy R代码给出了一个完整的例子,但积分是通过数值积分计算.
This kind of thing is often seen in Bayesian computation. Toy R code on Bayesian inference for mean of a normal distribution [data of snowfall amount] gives a full example, but integral is computed by numerical integration.
这篇关于在R中将rnorm作为另一个rnorm的参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!