sim_reg {mmirestriktor} | R Documentation |
Regression Data Simulation for Linear Models
Description
This function simulates data for linear regression analysis, as described in the supplemental material of the referenced paper. It generates datasets with a specified number of predictors and sample size, effect size, and correlation coefficient, considering a linear model with fixed regression coefficients.
Usage
sim_reg(n, p, f2, rho, beta = 0.1)
Arguments
n |
The total number of observations to generate. |
p |
The number of predictors (Beta) in the regression model. |
f2 |
The effect size, calculated as (f^2 = R^2 / (1 - R^2)), where ( R^2) is the coefficient of determination. |
rho |
The correlation coefficient between predictors, representing the off-diagonal elements in the covariance matrix. Should be a numeric value. |
beta |
The regression coefficients, either a single value replicated for each predictor or a vector of length equal to the number of predictors (p). |
Details
The function validates the length of the beta vector, constructs a covariance matrix for the predictors, and calculates the variance of the error term. It then uses the multivariate normal distribution to generate predictor values and calculates the response variable based on the specified regression coefficients and effect size.
Value
A list containing two elements: 'y', the simulated response variable, and 'X', the matrix of predictors.
References
Vanbrabant, Leonard; Van De Schoot, Rens; Rosseel, Yves (2015). Constrained statistical inference: sample-size tables for ANOVA and regression. Frontiers in Psychology, 5. DOI:10.3389/fpsyg.2014.01565. URL: https://www.frontiersin.org/articles/10.3389/fpsyg.2014.01565
Examples
# Example usage:
# Simulate data for a regression model with 100 observations, 3 predictors,
# an effect size of 0.10, and a correlation coefficient of 0.5
sim_reg(n = 100, p = 3, f2 = 0.10, rho = 0.5)