sim.eco {ecoreg} | R Documentation |
Simulate ecological data and samples of individual-level data
Description
Simulate ecological data and samples of individual-level data from an individual-level logistic regression model, depending on given binary, categorical or normally-distributed covariates.
Usage
sim.eco(N, ctx, binary, m, data=NULL, S=0, cross=NULL, covnames, ncats,
mu, alpha.c=0, alpha=0, beta=0, sig=0, strata, pstrata, isam = 0)
Arguments
N |
Vector of population sizes, one for each group. |
ctx |
A model formula containing names of group-level, or contextual, covariates on the right-hand side. |
binary |
A model formula containing names of individual-level binary covariates on the right-hand side. |
data |
Data frame containing the group-level variables given in
|
m |
A data frame with |
S |
A data frame with |
cross |
A matrix of cross-classifications of individuals in the
area between categories of multiple binary or categorical covariates, defined in
the same way as in |
covnames |
Vector of names of the covariates, if |
ncats |
Numeric vector of the number of levels of the
covariates used in |
mu |
Regression intercept on the logit scale. |
alpha.c |
Vector of coefficients for the group-level
covariates in the underlying logistic regression, corresponding to
the columns of |
alpha |
Vector of coefficients for the individual-level
binary covariates, corresponding to the columns of
|
beta |
Vector of coefficients for the individual-level
continuous covariates, corresponding to the columns of |
sig |
Random-effects standard deviation. |
strata |
A matrix with rows representing groups, and columns representing strata occupancy probabilities. |
pstrata |
A vector with one element for each stratum, giving
the assumed baseline outcome probabilities for the strata. The
logits of |
isam |
Number of individuals per group to retain in the individual-level data. |
Value
A list with components:
y |
The simulated aggregate-level response, one for each group. |
idata |
A data frame containing the retained individual-level
samples. The grouping indicator (with values |
Author(s)
C. H. Jackson chris.jackson@mrc-bsu.cam.ac.uk
See Also
Examples
N <- rep(50, 20)
ctx <- cbind(deprivation = rnorm(20), mean.income = rnorm(20))
phi <- cbind(nonwhite = runif(20), smoke = runif(20))
sim.df <- as.data.frame(cbind(ctx, phi))
mu <- qlogis(0.05) ## Disease with approximate 5% prevalence
## Odds ratios for group-level deprivation and mean imcome
alpha.c <- c(1.01, 1.02)
## Odds ratios for individual-level ethnicity and smoking
alpha <- c(1.5, 2)
sim.eco(N, ctx = ~ deprivation + mean.income, binary = ~ nonwhite +
smoke, data=sim.df, mu=mu, alpha.c=alpha.c, alpha=alpha)
sim.eco(N, ctx = ~ deprivation + mean.income, binary = ~ nonwhite +
smoke, data=sim.df, mu=mu, alpha.c=alpha.c, alpha=alpha, isam=3)