Unlike genCorrelatedData, this new-and-improved function can generate a data frame with as many predictors as the user requests along with an arbitrarily complicated regression formula. The result will be a data frame with columns named (y, x1, x2, ..., xp).
means: P-vector of means for X. Implicitly sets the dimension of the predictor matrix as N x P.
sds: Values for standard deviations for columns of X. If less than P values are supplied, they will be recycled.
rho: Correlation coefficient for X. Several input formats are allowed (see lazyCor). This can be a single number (common correlation among all variables), a full matrix of correlations among all variables, or a vector that is interpreted as the strictly lower triangle (a vech).
stde: standard deviation of the error term in the data generating equation
beta: beta vector of coefficients for intercept, slopes, and interaction terma. The first P+1 values are the intercept and slope coefficients for the predictors. Additional elements in beta are interpreted as coefficients for nonlinear and interaction coefficients. I have decided to treat these as a column (vech) that fills into a lower triangular matrix. It is easy to see what's going on if you run the examples. There is also explanation in Details.
intercept: Default FALSE. Should the predictors include an intercept?
verbose: TRUE or FALSE. Should information about the data generation be reported to the terminal?
Returns
A data matrix that has columns c(y, x1, x2, ..., xP)
Details
Arguments supplied must have enough information so that an N x P matrix of predictors can be constructed. The matrix X is drawn from a multivariate normal distribution, the expected value vector (mu vector) is given by the means and the var/covar matrix (Sigma) is built from user supplied standard deviations sds
and the correlations between the columns of X, given by rho. The user can also set the standard deviation of the error term (stde) and the coefficients of the regression equation (beta).
If called with no arguments, this creates a data frame with X ~ MVN(mu = c(50,50,50), Sigma = diag(c(10,10,10))). y = X
is N(m = 0, sd = 200). All of these details can be changed by altering the arguments.
The y (output) variable is created according to the equation
For shorthand, I write b1 for beta[1], b2 for beta[2], and so forth.
The first P+1 arguments in the argument beta are the coefficients for the intercept and the columns of the X matrix. Any additional elements in beta are the coefficients for nonlinear and interaction terms.
Those additional values in the beta vector are completely optional. Without them, the true model is a linear regression. However, one can incorporate the effect of squared terms (conceptualize that as x1 * x1, for example) or interactions (x1 * x2) easily. This is easier to illustrate than describe. Suppose there are 4 columns in X. Then a beta vector like beta = c(0, 1, 2, 3, 4, 5, 6, 7, 8) would amount to asking for
y=0+1x1+2x2+3x3+4x4+5x12+6x1x2+7x1x3+8x1x4+error
If beta supplies more coefficients, they are interpeted as additional interactions.
When there are a many predictors and the beta vector is long, this can become confusing. I think of this as a vech for the lower triangle of a coefficient matrix. In the example with 4 predictors, beta[1:5] are used for the intercepts and slopes. The rest of the beta elements lay in like so:
X1 X2 X3 X4
X1 b6 . .
X2 b7 b10 .
X3 b8 b11 b13
X4 b9 b12 b14 b15
If the user only supplies b6 and b7, the rest are assumed to be 0.
To make this clear, the formula used to calculate y is printed to the console when genCorrelatedData2 is called.