sim_MVN_X | R Documentation |
Takes N draws from a Multivariate Normal (MVN) distribution using either
base R or the R package spam
. This function requires the Cholesky
decomposition of the desired covariance matrix.
sim_MVN_X(
N,
mu = 0,
L = NULL,
R = NULL,
S = NULL,
Q = NULL,
use.spam = FALSE,
use.MASS = FALSE,
X.categorical = FALSE,
X.num.categories = 2,
X.category.type = "percentile",
X.percentiles = NULL,
X.manual.thresh = NULL,
X.cat.names = NULL
)
N |
The number of draws to take from MVN; i.e., the number of subjects. |
mu |
One of the following:
|
L, R |
|
S, Q |
A covariance or precision matrix respectively. These are for
use with |
use.spam |
Logical. If |
use.MASS |
Logical. When |
X.categorical |
Default is |
X.num.categories |
A scalar value denoting the number of categories in which to divide the data. |
X.category.type |
Tells R how to categorize the data. Options are
|
X.percentiles |
A vector of percentiles to be used in thresholding
when |
X.manual.thresh |
A vector containing the thresholds for categorizing
the values; e.g. if |
X.cat.names |
A vector of category names. If |
Matrix of dimension N
x (nrow(L))
(or equivalently
N
x (nrow(R))
) where each row is draw from MVN, and each
column represents a different "variable"; e.g. location in an image.
This function requires the Cholesky decomposition of the desired
covariance matrix for the MVN; this allows for using this function in
simulating multiple datasets of N
MVN draws while only taking the
Cholesky decomposition of the covariance matrix once.
spamsim2Dpredictr
\insertRefRipley:1987sim2Dpredictr
\insertRefRue:2001sim2Dpredictr
## verify MVN with base R
set.seed(732)
Lex <- chol_s2Dp(corr.structure = "ar1",
im.res = c(3, 3),
rho = 0.25,
sigma = 1,
use.spam = FALSE,
corr.min = 0.02,
triangle = "lower",
return.cov = TRUE)
XbR = sim_MVN_X(N = 1000, mu = 0, L = Lex$L)
apply(XbR, 2, mean)
cov(XbR)
Lex$S
## verify MVN with \code{spam}
set.seed(472)
Rex <- chol_s2Dp(im.res = c(3, 3), matrix.type = "prec",
use.spam = TRUE, neighborhood = "ar1",
triangle = "upper", return.prec = TRUE)
Xspam = sim_MVN_X(N = 1000, mu = 0, R = Rex$R, Q = Rex$Q)
apply(Xspam, 2, mean)
solve(cov(Xspam))
as.matrix(Rex$Q)
## Categories
set.seed(832)
Xtest <- sim_MVN_X(N = 30, mu = 0, L = Lex$L,
X.categorical = TRUE,
X.num.categories = 3,
X.category.type = "percentile",
X.cat.names = c("A", "B", "C"))
Xtest
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.