1
$\begingroup$

enter image description hereI am working with multiple linear regression models and am attempting to transform the predictors of the model. I am attempting to use the powertransform() function however since my data contains zeros, doing so returns an error stating that the first value must be strictly postive. Is there an alternative to the powertransform function when data contains zeros? The data looks as below. I would like to transform it in order to get a better linear regression model

$\endgroup$
15
  • 2
    $\begingroup$ What does your data look like/ represent? Why do you want to transform it? Can you show examples\histograms? $\endgroup$ Jun 5, 2020 at 4:12
  • 1
    $\begingroup$ What exactly does "better" LRM mean? That's sort of like saying you want a better pair of shoes. Without specifying what you seek to accomplish, we can't steer you in the right direction. $\endgroup$
    – dimitriy
    Jun 5, 2020 at 4:38
  • 1
    $\begingroup$ One approach is to use theory/local knowledge to inform how predictors should be transformed. One approach might be to bin them into 0, 1-3, 4-5, or something else meaningful, and then use dummies. You often get good ideas here by plotting the data and doing some thinking about the science of the problem. You have not specified the outcome and your goal, so it is hard to offer more concrete guidance. $\endgroup$
    – dimitriy
    Jun 5, 2020 at 5:08
  • 1
    $\begingroup$ Another approach would be to replace the zeros with a small positive number and then do the transform. This is less demanding on you, but a bit ad hoc, and the results can be sensitive to what that small number is. $\endgroup$
    – dimitriy
    Jun 5, 2020 at 5:08
  • 1
    $\begingroup$ Instead of some arbitrary transformations, I suggest you fit a Generalized Additive Model (see R package mgcv). Then you can inspect the smoothers and, if you need a parametric model, you can then still look for transformations that result in the same shape. If your goal is prediction, you can just use machine learning approaches (which sort of would also include GAMs). $\endgroup$
    – Roland
    Jun 5, 2020 at 6:14

1 Answer 1

1
$\begingroup$

Well one way is to just add one to every value and then transform, Powertransform$(x+1)$. I assume this is some type of Box-Cox transform.

But, looking at your picture it looks like a very large number of the entries are zero. If virtually every value is zero, there is not much information that the column can provide, so it might be better to drop the column and create a model using the other columns.

If there are a few but a nontrial number of non-zero values, it might also be good to make all the non-zero values one and make the column a categorical variable with two levels, zero and one. Here you are just trying to detect the situation that would make it non-zero.

If there are a reasonable number of non-zero values, but the distribution of the column is non-normal, you can make it zero-one as above, or bin the predictor into some reasonable number of levels, or standardize the column, ie subtract the mean and divide by the sd.

It should be noted that the requirement of linear regression is not normal predictors OR normal response, rather, normal residuals after the regression model has been fit.

There are possibly other things I can't think of off the top of my head right now.

$\endgroup$
6
  • $\begingroup$ The general aim of my analysis is simply to provide the best model I can. Do you think that setting the zeros say equal to .1 would provide much of a difference in values for coefficients? $\endgroup$ Jun 5, 2020 at 5:38
  • 1
    $\begingroup$ The problem isn't exactly that they are mostly all zero, it is that they are all the same value. Setting them all to .1 doesn't fix the problem. How many zeros and non-zeros for the relevant columns? $\endgroup$
    – Kenney
    Jun 5, 2020 at 16:52
  • $\begingroup$ There are a great deal that are zeros, in every single column, the dataset pretty much sought to isolate factors and exluded others hence the zeros. $\endgroup$ Jun 6, 2020 at 1:14
  • $\begingroup$ it seems that this might be the solution, wil; the result that follows after adding one to the numbers be accurate ? Note: I have checked for normality of residuals and found that normality. $\endgroup$ Jun 6, 2020 at 23:54
  • $\begingroup$ Adding one to all the values and then transforming will bias the results. If you ran the model with all the values as numeric and the residuals are normal, and all the other linear regression checks are good too, your model is good! $\endgroup$
    – Kenney
    Jun 7, 2020 at 14:46

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.