Creates a design matrix X with controlled correlation structure and simulates
a response y according to the specified family. Supports Gaussian,
Binomial, Poisson, Gamma GLMs, and Cox survival data with exponential baseline hazard.
Arguments
- n
Integer; number of observations (default: 600).
- theta
Numeric vector of true coefficients (length p).
- intercept
Numeric; true intercept term (default: 0).
- settings
Character; correlation pattern:
"S1": all p variables equally correlated."S2": first 5×5 block correlated, others independent."S3": two p/2 × p/2 blocks correlated.
Default:
c("S1","S2","S3").- rho
Numeric in
[0,1]; within-block correlation (default: 0.9).- dispersion
Numeric; dispersion for Gaussian/Gamma (default: 1).
- family
A
familyobject (e.g.gaussian(),binomial(),poisson(),Gamma()) or the string"cox"for survival data (default:gaussian()).- censoring_rate
Numeric in
[0,1]; fraction censored for Cox models (default: 0.3).- baseline_hazard
Numeric or function; constant hazard rate for Cox, or a hazard function if provided (default: 1).
Value
A list with components:
- X
n × p design matrix with specified correlation.
- y
Response:
Numeric vector of length n (GLMs).
n × 2 matrix (time, status) (Cox).
- eta
Linear predictor intercept + X %*% theta.
Examples
if (FALSE) { # \dontrun{
# Gaussian data, p = 2
dat1 <- generate(n = 100, theta = c(1, 0), settings = "S1",
family = gaussian(), dispersion = 2)
# Binomial data with probit link
dat2 <- generate(n = 200, theta = c(0.5, -0.5),
family = binomial(link = "probit"),
settings = "S2", rho = 0.7)
# Cox survival data
dat3 <- generate(n = 150, theta = c(1, 1, 0),
settings = "S3", family = "cox",
censoring_rate = 0.2, baseline_hazard = 0.05)
} # }