Data generating in a simulation I am trying to check the Regression robustness of multiple Regression methods. I would like to investigate how outliers in the response variable(Y) OR in the explanatory variables (X) affect the regression methods.
I am doing this through simulation in R, but I am confused firstly about generating explanatory and response variables.
Do I need to generate them independently or Not? Which one is right?
Independently, for example as the following, where x is generated independently from y
p <- 5
n <- 100
x <- matrix(rnorm(n * p), nrow = n)
y <- rnorm(n)

Or, they are related such as following, where x is used to generate y
p <- 5
n <- 100
x <- cbind(1, Rfast::matrnorm(n, p))
ber <- rnorm(p+1, 3, 1)
m <- x %*% ber
y <- rnorm(n, m, 1)

 A: You need to generate your data in accordance with what you want the data-generating process to be. If you want your dependent variable to be related to your independent variables, then you need to generate it as such. If you don't want your dependent variable to be related to your independent variables, then you need to generate it as such. There is no right way to generate data, but you do have to propose a data-generating process (i.e., a population regression model), and simulate data from it in a way that mirrors it.
The data-generating process you seem to want to investigate is
$$Y_i = \beta_0 + \beta_1 X_{1i} + \beta_2 X_{2i} + \dots + \beta_p X_{pi} + \varepsilon_i$$
If you set all the $\beta$s to $0$, this would correspond to your first block of code. If you want the $\beta$s to be drawn from a normal distribution, this would correspond to your second block. So the question for you is, which data-generating process are you trying to represent in your simulation?
You might ask, "Which data-generating process would allow me to study the statistical phenomena I wish to investigate?" That is a different question than the one you are asking here and one that would require you to go into detail about your specific research question.
