Description Usage Arguments Details Value Author(s) See Also Examples

The probability density function, the distribution function and random number generation for the multivariate truncated normal (Gaussian) distribution

1 2 3 | ```
dmtruncnorm(x, mean, varcov, lower, upper, log = FALSE, ...)
pmtruncnorm(x, mean, varcov, lower, upper, ...)
rmtruncnorm(n, mean, varcov, lower, upper)
``` |

`x` |
either a vector of length |

`mean` |
a vector representing the mean value of the pre-truncation normal distribution. |

`varcov` |
a symmetric positive-definite matrix representing the variance matrix of the pre-truncation normal distribution. |

`lower` |
a vector representing the lower truncation values of the
component variables; |

`upper` |
a vector representing the upper truncation values of the
component variables; |

`log` |
a logical value (default value is |

`...` |
arguments passed to |

`n` |
the number of (pseudo) random vectors to be generated. |

For `dmtruncnorm`

and `pmtruncnorm`

,
the dimension `d`

cannot exceed `20`

.

Function `rmtruncnorm`

is just a wrapper of the imported function
`tmvnsim`

, set up so that the names and the pattern of
the `rmtruncnorm`

arguments are in agreement with the other functions
in the package.

a numeric vector in case of `dmtruncnorm`

and `pmtruncnorm`

;
a matrix in case of `rmtruncnorm`

, unless `n=1`

in which case
it is a vector.

Adelchi Azzalini

`sadmvn`

for regulating accuracy,
`tmvnsim`

for details on the underlying function
generating random numbers

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ```
m2 <- c(0.5, -1)
V2 <- matrix(c(3, 3, 3, 6), 2, 2)
lower <- a <- c(-1, -2.5)
upper <- b <- c(2, 1)
set.seed(1)
# generate a set of coordinates, pts, on the plane
pts <- matrix(runif(10, min=-1.5, max=1.5), nrow=5, ncol=2)
rownames(pts) <- LETTERS[1:nrow(pts)]
# compute PDF and CDF at the chosen coordinates, pts
pdf <- dmtruncnorm(pts, mean=m2, varcov=V2, lower, upper)
cdf <- pmtruncnorm(pts, mean=m2, varcov=V2, lower, upper)
print(cbind(pts, pdf, cdf))
#--
# generate a sample of random numbers
sample <- rmtruncnorm(300, mean=m2, varcov=V2, lower, upper)
#
# then plot the sample along with the pertaining box and the earlier points,
# just for graphical illustration
eps <- 0.5
ra <- lower -eps
rb <- upper + eps
plot(x=c(ra[1], rb[1]), y=c(ra[2], rb[2]), xlab="", ylab="",type="n")
points(sample, pch=20, col=4, cex=0.4)
xbox <- c(a[1], b[1], b[1], a[1], a[1])
ybox <- c(a[2], a[2], b[2], b[2], a[2])
polygon(xbox, ybox, lty=2, border="gray60")
text(pts[,1], pts[,2], col=2, labels=rownames(pts), cex=0.9)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.