sim_Y_MVN_X | R Documentation |
N spatially correlated design vectors are simulated from an MVN. These design vectors are used to then simulate scalar outcomes that have one of Gaussian, Binomial, Multinomial or Poisson distributions.
sim_Y_MVN_X(
N,
B,
L = NULL,
R = NULL,
S = NULL,
Q = NULL,
use.spam = TRUE,
mu = 0,
rand.err = 1,
dist = "gaussian",
V = NULL,
incl.subjectID = TRUE,
threshold.method = "none",
Y.thresh = NULL,
X.categorical = FALSE,
X.num.categories = 2,
X.category.type = "percentile",
X.manual.thresh = NULL,
X.cat.names = NULL,
print.out = FALSE
)
N |
The number of draws to take from MVN; i.e., the number of subjects. |
B |
A vector parameter values; i.e. "betas". Note that
|
L, R |
|
S, Q |
A covariance or precision matrix respectively. These are for
use with |
use.spam |
Logical. If |
mu |
One of the following:
|
rand.err |
A vector for the random error standard deviation when
|
dist |
The distribution of the scalar outcome.
|
V |
A numeric value stating the number of categories desired when
|
incl.subjectID |
When |
threshold.method |
One of |
Y.thresh |
A manual value used to threshold 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.manual.thresh |
A vector containing the thresholds for categorizing
the values; e.g. if |
X.cat.names |
A vector of category names. If |
print.out |
If
This is useful to see the effect of image parameter selection and beta parameter selection on distributional parameters for the outcome of interest. |
A data frame where each row consists of a single subject's data. Col 1 is the outcome, Y, and each successive column contains the subject predictor values.
Careful parameter selection, i.e. B
, is necessary to ensure
that simulated outcomes are reasonable; in particular, counts arising from
the Poisson distribution can be unnaturally large.
spamsim2Dpredictr
\insertRefRipley:1987sim2Dpredictr
\insertRefRue:2001sim2Dpredictr
\insertRefAgresti:2007sim2Dpredictr
\insertRefFriedman:2010sim2Dpredictr
## generate precision matrix and take Cholesky decomposition
Rpre <- chol_s2Dp(im.res = c(3, 3), matrix.type = "prec",
use.spam = TRUE, neighborhood = "ar1",
triangle = "upper", return.prec = TRUE)
## Generate correlation matrix & take Cholesky decomposition
Rcov <- chol_s2Dp(corr.structure = "ar1", im.res = c(3, 3),
rho = 0.5,
triangle = "upper",
use.spam = FALSE, neighborhood = "none")
## Define non-zero beta values
Bex <- beta_builder(row.index = c(2, 3),
col.index = c(3, 3),
im.res = c(3, 3),
B0 = 0, B.values = rep(1, 2),
output.indices = FALSE)
## Simulate Datasets
## parameter values
Nex = 100
set.seed(28743)
## with precision matrix
Gauss.exp <- sim_Y_MVN_X(N = Nex, B = Bex,
R = Rpre$R, Q = Rpre$Q,
dist = "gaussian")
hist(Gauss.exp$Y)
## with covariance matrix
Gauss.exc <- sim_Y_MVN_X(N = Nex, B = Bex,
R = Rcov$R, S = Rcov$S,
dist = "gaussian")
hist(Gauss.exc$Y)
## direct draws from binomial
Bin.ex <- sim_Y_MVN_X(N = Nex, B = Bex, R = Rcov$R, S = Rcov$S,
dist = "binomial", print.out = TRUE)
table(Bin.ex$Y)
## manual cutoff
Bin.ex2 <- sim_Y_MVN_X(N = Nex, B = Bex,
R = Rcov$R, S = Rcov$S,
dist = "binomial",
threshold.method = "manual",
Y.thresh = 1.25)
table(Bin.ex2$Y)
## percentile cutoff
Bin.ex3 <- sim_Y_MVN_X(N = Nex, B = Bex,
R = Rcov$R, S = Rcov$S,
dist = "binomial",
threshold.method = "percentile",
Y.thresh = 0.75)
table(Bin.ex3$Y)
## Poisson Example - note the large counts
Pois.ex <- sim_Y_MVN_X(N = Nex, B = Bex,
R = Rcov$R, S = Rcov$S,
dist = "poisson", print.out = TRUE)
mean(Pois.ex$Y)
quantile(Pois.ex$Y,
probs = c(0, 0.1, 0.25, 0.45, 0.5,
0.75, 0.9, 0.95, 0.99, 1))
hist(Pois.ex$Y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.