5
$\begingroup$

I am working on linear regression models including classic and robust linear regression models.

By classic models, I mean ordinary least square and least absolute regression. Also, by robust models, I mean something like Huber regression and MM estimate.

I am building models on generated data in R, and I assumed that the coefficients are set to be zero Without loss of generality. Thus, Y=epsilon.

Now, Is it possible to generate Y from different distributions rather than the normal distribution and the same for the X matrix? For example, from t, log normal, Beta, Weibull, Exponential Distribution.

In other words, Is it possible for example to generate data from t-distribution for both Y and X, and then compare OLS and Huber Regression? Does this contradict the assumption of the Linear Regression where the errors assumed to be normally distributed?

Bear in mind

  • My idea is to check/investigate which model is more robust to the outliers.

  • I want for example to compare Ordinary least square and Huber regression, so first, I will generate X and Y from a normal distribution and then I compare them based on some measure. I will then repeat the process BUT I generate the Y and X from another distribution for example Beta or Expnonetioal. In this case, is it ok to generate data from latter distributions to build Linear Regression Models?

  • The model each time will build on Y, and X, for example in R; lm(Y~X,...).

$\endgroup$

4 Answers 4

4
$\begingroup$

I think you'll want to revisit how regression simulation in supposed to work. The idea is to code the Data Generating Process (DGP) and as a result you will know what is true in the population. Then you build a sample using this DGP and run a regression on this sample (can be linear regression or Huber or any other type). You'll want to see if you recover the population parameters and how your conclusion changes as you change the DGP as desired. This way you can answer any questions you might have (such as investigating robustness to outliers). To simulate the model $Y=\beta_0+\beta_1*X+\epsilon$, you do the following:

  1. Independently simulate the error term $\epsilon$ from any assumed distribution (can be any distribution you please), and the independent variable from any assumed distribution (can be any distribution you please). You can build in a dependency of $\epsilon$ and $X$ but keep in mind that (if X is a random variable) your OLS model necessarily assumes that $E(\epsilon_i|X_i)=0$, so this condition must be satisfied by whatever dependency relationship you decide to model. With X non-random, there can be no dependency between $\epsilon$ and $X$, by definition.
  2. Assume values for $\beta_0$ and $\beta_1$. It looks like you want to assume that $\beta_0=0$ and $\beta_1=0$. That's fine but then X does not even enter the picture here. Your model ignores X and is literally $Y_i$=$\epsilon_i$. There is loss of generality once you assume $\beta_1=0$. You can assume $\beta_1=4$ without loss of generality, but not $\beta_1=0$.
  3. Generate $Y$ values using the DGP. You do not assume another distribution for $Y$. The distribution of $Y_i$ in your case is identical to the distribution of $\epsilon_i$. Whatever you assumed for $\epsilon_i$ holds for $Y_i$ because $Y_i$=$\epsilon_i$.

This clarification of how regression simulation works should answer all your questions.

$\endgroup$
1
4
$\begingroup$

Not sure what is the question here. First of all, yes, you can simulate data using any data generating process. However, if what you want is to compare the scenario to data simulated from a normal distribution, you just need to make sure that in both cases, the theoretical variance and means are the same. For example, if: $$y=X\beta +e$$ $$e\sim N(0,1)$$ then you can compare it to: $$ e \sim U \left( -\frac{\sqrt(12)}{2},\frac{\sqrt(12)}{2} \right) $$ because in both cases the mean is 0 and variance 1.

$\endgroup$
7
  • 1
    $\begingroup$ Hi Jeza, So I think my statement still fits stands. You need to create errors that have the same mean and standard errors, so the conditional distribution of Y|X are comparable in terms of the first and second-order moments. Now, i do think (but have not experimented) that the same conditions apply to the generation of X's They need to have the same moments. OLS only depends on means and variances, so as long as they are the same, I believe you can compare different models from different data-generating processes. $\endgroup$
    – Fcold
    Commented Feb 15, 2021 at 16:54
  • 1
    $\begingroup$ So, If I correctly understand you, it is possible for example to generate data from t-distribution for both Y and X, and then compare OLS and Huber Regression. Does this contradict the assumption of the Linear Regression where the errors assumed to be normally distributed. $\endgroup$
    – jeza
    Commented Feb 15, 2021 at 22:41
  • 1
    $\begingroup$ Yes it is possible. after all real data comes from not-normal distributions. Also, OLS doesnt need normality assumption. In fact, normality is only needed for statistical inference in small samples. For large samples, one relies on the Central Limit theory. I do this kind of simulations in Stata for class all the time, but not that familiar with R to provide an easy to read example tho. $\endgroup$
    – Fcold
    Commented Feb 16, 2021 at 1:32
  • 1
    $\begingroup$ @Fcold: You make it sound as if an assumption is made about the distribution of Y. However, that is not the case. No assumption is made about the distribution of Y. This flaw in presentation is widespread in books and the root-cause for much confusion. The distribution of $Y_i$ is determined by the distribution of $\epsilon_i$ and by the distributions of the regressors. Does OLS require us to make any assumptions about the distribution of $Y_i$? Absolutely not. $\endgroup$ Commented Feb 23, 2021 at 20:08
  • 1
    $\begingroup$ Thank you @ColorStatistics. I edited the answer to be more precise. To which I should add. the distribution of $Y$ is determined by the distribution of $e$ and $X$. So for the question here, if $X$ is constant, one can simulate the role of different distributions on the estimation of the beta coefficients by changing the distribution of the errors $e$, making sure the errors have the same mean and variance,regardless of the distribution they follow. $\endgroup$
    – Fcold
    Commented Feb 23, 2021 at 20:15
3
+25
$\begingroup$

is it ok to generate data from latter distributions to build Linear Regression Models?

You can simulate whatever you want. What matters more perhaps is the type of conclusions you want to draw from the results: I can imagine people using linear regression when the true error distribution is $t$-distributed, and it is valuable to know how linear regression performs vs other techniques. But is anyone using ordinary linear regression for exponential, or Weibull distributed processes?


Since this has the r tag, perhaps what you are really asking for is how to draw samples from non-normal distributions in R.

This is actually really simple and there are a lot of built-in choices, including each choice you mentioned:

  • rnorm(n, mu, sd) for n random draws from a normal distribution with mean mu and variance sd^2;
  • rt(n, df) for n random draws from a $t$-distribution with df degrees of freedom. You could multiply these draws by some value to increase their variance if you wanted to compare them to the normally distributed ones;
  • rlnorm(n, meanlog, sdlog) for n random draws from a log-normal distribution with mean and standard deviation on the log scake given by meanlog and sdlog, respectively;
  • rbeta(n, shape1, shape2) to draw n samples from a beta distribution with $\alpha$ given by shape1 and $\beta$ by shape2;
  • rweibull(n, shape, scale) for n samples from a Weibull distribution with $k$ given by shape and $\lambda$ by scale;
  • rexp(n, rate) for n samples from an exponential distribution with $\lambda$ given by rate.

There are many other distributions available in base R, as well as from packages you can install. You could even write your own random number generator based on runif to draw samples from an arbitrary probability distribution. For example, summing two uniform distributions with the same $a$ and $b$ will give you a triangular distribution.

You may then also want to set a seed before making a call to these functions. This forces the pseudo-random number generator to start from a fixed point, so any time you run your script, you will end up with the same 'random' numbers. This can be done by placing set.seed(xxx) at the top of your script, where xxx is some arbitrarily chosen integer. This makes your results reproducible.

$\endgroup$
3
$\begingroup$

It is certainly possible to generate random variables from distributions other than the normal distribution in R. You can find a large list of probability distributions here. If you are interested in conducting simulation analysis looking at the effects of outliers, a natural thing to do would be to use a T-distribution for the error term, which allows you to vary the degrees-of-freedom parameter which affects the "fatness of the tails" of the distribution. This can be done by generating random variables using the rt function.

Here is an example where I simulate linear regression data using a normally distributed explanatory variable and error terms that are T-distributed with two degrees-of-freedom (giving infinite variance). This is an error distribution with "fat tails" so you get some large error terms in the data.

#Set regression parameters
n     <- 200
beta0 <- 24.2
beta1 <- 0.8
    
#Generate simulated linear regression data
#Error terms are T-distributed with two degrees-of-freedom
set.seed(81301856)
ERR   <- rt(n, df = 2)
X     <- rnorm(n, mean = 40, sd = 8)
Y     <- beta0 + beta1*X + ERR

#Show scatterplot of the data
plot(X, Y, ylim = c(0, 100), main = 'Scatterplot of simulated regression data')

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks, loss of generality of coefficients are cited in a paper and it is assumed to be zero. Do you think it will be ok or I should assume something like you. sciencedirect.com/science/article/abs/pii/S016794732030205X $\endgroup$
    – jeza
    Commented Feb 24, 2021 at 15:39
  • $\begingroup$ What I need is to simulate data of y and x and then build the regression models after introducing some outliers. $\endgroup$
    – jeza
    Commented Feb 24, 2021 at 19:02
  • 2
    $\begingroup$ @jeza: The values I used were just for illustrative purposes to show you how you can code this in R. It is really up to you how you wish to conduct your simulation. It is useful to examine the case where there is no relationship (beta1 <- 0) to see how well the estimation methods perform in this case. If you use an error distribution like this one then you should get some "outliers" automatically. As you can see in the plot, there are a few data points that are far away from the general mass. $\endgroup$
    – Ben
    Commented Feb 25, 2021 at 0:10
  • $\begingroup$ It is really helpful. If I generate data from normal dist, I need to introduce outliers. Am I right? Thus, I can compare the outliers effect on regression models. $\endgroup$
    – jeza
    Commented Feb 25, 2021 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.