I estimate a model with linear regression:

model <- lm(orders ~ 
          day +
        ,data=training_df, na.action = na.exclude)


my response variable is zero somewhere but positive - in fact:


   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   0.000   0.000   3.174   4.000  67.000 

When I try to estimate the boxcox like:

bc<-boxcox(model,plotit = T) 

I get:

 Error in boxcox.default(model, plotit = T): response variable must be positive

I shouldnt be a problem to have zero values right?

Hints are welcome!

  • $\begingroup$ Not really. The box-cox transformation includes the log transformation as a particular case. See, e.g., here r-bloggers.com/on-box-cox-transform-in-regression-models. $\endgroup$
    – utobi
    Nov 28, 2016 at 14:34
  • $\begingroup$ that would mean that both lambdas are zero. is there a way to fix one of them and just keep (log + c) and estimate just one? @utobi $\endgroup$ Nov 28, 2016 at 14:38
  • 2
    $\begingroup$ There is only one lambda in box-cox transformation. A quick fix would be to add a small positive value to all of your observations prior to the box-cox transformation. Otherwise a zero-inflated model might be more appropriate. $\endgroup$
    – utobi
    Nov 28, 2016 at 15:00
  • 1
    $\begingroup$ As @utobi suggests since more than half your observations are zero any transformation is going to have a spike at the value which is the transformed zero so choosing a model which explicitly allows for clumping at zero looks a much better bet. $\endgroup$
    – mdewey
    Nov 28, 2016 at 15:05
  • 1
    $\begingroup$ Perhaps this article from JSS will help. $\endgroup$
    – mdewey
    Nov 28, 2016 at 15:15


Your Answer

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

Browse other questions tagged or ask your own question.