sim_Y_MVN_X {sim2Dpredictr} | R Documentation |
Simulate Scalar Outcomes from Simulated Spatially Correlated Predictors
Description
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.
Usage
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
)
Arguments
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. |
Value
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.
Note
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.
References
Furrer R, Sain SR (2010). “spam: A Sparse Matrix R Package with Emphasis on MCMC Methods for Gaussian Markov Random Fields.” Journal of Statistical Software, 36(10), 1-25. https://www.jstatsoft.org/v36/i10/.
Ripley BD (1987). Stochastic Simulation. John Wiley & Sons. doi:10.1002/9780470316726.
Rue H (2001). “Fast Sampling of Gaussian Markov Random Fields.” Journal of the Royal Statistical Society B, 63, 325-338. doi:10.1111/1467-9868.00288.
Agresti A (2007). An Introduction to Categorical Analysis, 2nd edition. John Wiley & Sons, Hoboken, New Jersey.
Friedman J, Hastie T, Tibshirani R (2010). “Regularization paths for generalized linear models via coordinate descent.” Journal of Statistical Software, 33, 1-22. doi:10.18637/jss.v033.i01.
Examples
## 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)