dtmvnorm.marginal(tmvtnorm)
dtmvnorm.marginal()所属R语言包:tmvtnorm
One-dimensional marginal density functions from a Truncated Multivariate Normal distribution
从截断的多元正态分布的一维边缘概率密度函数
译者:生物统计家园网 机器人LoveR
描述----------Description----------
This function computes the one-dimensional marginal density function from a Truncated Multivariate Normal density function using the algorithm given in Cartinhour (1990).
此函数计算一维的边缘密度函数从一个被截断的多元正态密度函数的使用给出的算法在Cartinhour(1990年)。
用法----------Usage----------
dtmvnorm.marginal(xn, n=1,
mean= rep(0, nrow(sigma)),
sigma=diag(length(mean)),
lower=rep(-Inf, length = length(mean)),
upper=rep( Inf, length = length(mean)),
log=FALSE)
参数----------Arguments----------
参数:xn
Vector of quantiles to calculate the marginal density for.
向量的位数来计算的边际密度。
参数:n
Index position (1..k) within the random vector x to calculate the one-dimensional marginal density for.
索引的位置(1 .. k)于随机矢量x来计算一维边缘密度。
参数:mean
Mean vector, default is rep(0, length = nrow(sigma)).
均值向量,默认是:rep(0, length = nrow(sigma))。
参数:sigma
Covariance matrix, default is diag(length(mean)).
协方差矩阵,默认是diag(length(mean))。
参数:lower
Vector of lower truncation points,\ default is rep(-Inf, length = length(mean)).
矢量较低的截断点,\默认是rep(-Inf, length = length(mean))。
参数:upper
Vector of upper truncation points,\ default is rep( Inf, length = length(mean)).
向量上的截断点,\默认是rep( Inf, length = length(mean))。
参数:log
Logical; if TRUE, densities d are given as log(d).
逻辑,如果TRUE,密度d的log(D)。
Details
详细信息----------Details----------
The one-dimensional marginal density f_i(x_i) of x_i is
一维边缘密度f_i(x_i)x_i
Note that the one-dimensional marginal density is not truncated normal, but only conditional densities are truncated normal.
注意一维边缘密度不截断正常,但唯一条件密度被截断正常。
(作者)----------Author(s)----------
Stefan Wilhelm <Stefan.Wilhelm@financial.com>
参考文献----------References----------
Communications in Statistics - Theory and Methods, 19, 197–203
Psychometrika, 58, 471–488
实例----------Examples----------
#############################################[############################################]
#[]
# Example 1: truncated bivariate normal[例1:截断二元正常]
#[]
#############################################[############################################]
# parameters of the bivariate normal distribution[二元正态分布的参数]
sigma = matrix(c(1 , 0.95,
0.95, 1 ), 2, 2)
mu = c(0,0)
# sample from multivariate normal distribution[从多元正态分布的样本]
X = rmvnorm(5000, mu, sigma)
# tuncation in x2 with x2 <= 0[tuncation在X2 X2 <= 0]
X.trunc = X[X[,2]<0,]
# plot the realisations before and after truncation[绘制的实现前后截断]
par(mfrow=c(2,2))
plot(X, col="gray", xlab=expression(x[1]), ylab=expression(x[2]),
main="realisations from a\n truncated bivariate normal distribution")
points(X.trunc)
abline(h=0, lty=2, col="gray")
#legend("topleft", col=c("gray", "black")[传说(“左上”,列= C(“灰色”,“黑色”)]
# marginal density for x1 from realisations[实现从边缘密度为x1]
plot(density(X.trunc[,1]), main=expression("marginal density for "*x[1]))
# one-dimensional marginal density for x1 using the formula[使用下面的公式为x1一维边缘密度]
x <- seq(-5, 5, by=0.01)
fx <- dtmvnorm.marginal(x, n=1, mean=mu, sigma=sigma,
lower=c(-Inf,-Inf), upper=c(Inf,0))
lines(x, fx, lwd=2, col="red")
# marginal density for x2[边缘密度为x2]
plot(density(X.trunc[,2]), main=expression("marginal density for "*x[2]))
# one-dimensional marginal density for x2 using the formula[一维边缘密度为x2,使用下面的公式]
x <- seq(-5, 5, by=0.01)
fx <- dtmvnorm.marginal(x, n=2, mean=mu, sigma=sigma,
lower=c(-Inf,-Inf), upper=c(Inf,0))
lines(x, fx, lwd=2, col="blue")
#############################################[############################################]
#[]
# Example 2 : truncated trivariate normal[例2:截断三元正常]
#[]
#############################################[############################################]
# parameters of the trivariate normal distribution[三元正态分布的参数]
sigma = outer(1:3,1:3,pmin)
mu = c(0,0,0)
# sample from multivariate normal distribution[从多元正态分布的样本]
X = rmvnorm(2000, mu, sigma)
# truncation in x2 and x3 : x2 <= 0, x3 <= 0[截断X2和X3:X2 <= 0,X3 <= 0]
X.trunc = X[X[,2]<=0 & X[,3]<=0,]
par(mfrow=c(2,3))
plot(X, col="gray", xlab=expression(x[1]), ylab=expression(x[2]),
main="realisations from a\n truncated trivariate normal distribution")
points(X.trunc, col="black")
abline(h=0, lty=2, col="gray")
plot(X[,2:3], col="gray", xlab=expression(x[2]), ylab=expression(x[3]),
main="realisations from a\n truncated trivariate normal distribution")
points(X.trunc[,2:3], col="black")
abline(h=0, lty=2, col="gray")
abline(v=0, lty=2, col="gray")
plot(X[,c(1,3)], col="gray", xlab=expression(x[1]), ylab=expression(x[3]),
main="realisations from a\n truncated trivariate normal distribution")
points(X.trunc[,c(1,3)], col="black")
abline(h=0, lty=2, col="gray")
# one-dimensional marginal density for x1 from realisations and formula[一维边缘密度为x1实现和公式]
plot(density(X.trunc[,1]), main=expression("marginal density for "*x[1]))
x <- seq(-5, 5, by=0.01)
fx <- dtmvnorm.marginal(x, n=1, mean=mu, sigma=sigma,
lower=c(-Inf,-Inf,-Inf), upper=c(Inf,0,0))
lines(x, fx, lwd=2, col="red")
# one-dimensional marginal density for x2 from realisations and formula[一维边缘密度为x2实现和公式]
plot(density(X.trunc[,2]), main=expression("marginal density for "*x[2]))
x <- seq(-5, 5, by=0.01)
fx <- dtmvnorm.marginal(x, n=2, mean=mu, sigma=sigma,
lower=c(-Inf,-Inf,-Inf), upper=c(Inf,0,0))
lines(x, fx, lwd=2, col="red")
# one-dimensional marginal density for x3 from realisations and formula[一维边缘密度为X3的实现和公式]
plot(density(X.trunc[,3]), main=expression("marginal density for "*x[3]))
x <- seq(-5, 5, by=0.01)
fx <- dtmvnorm.marginal(x, n=3, mean=mu, sigma=sigma,
lower=c(-Inf,-Inf,-Inf), upper=c(Inf,0,0))
lines(x, fx, lwd=2, col="red")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|