Finding Optimal Lambda for Box-Cox Transform in R

前端 未结 2 497
无人及你
无人及你 2021-02-06 08:23

I am trying to transform data in a vector in R.

This is not for linear regression so I don\'t have a predictor and response relationship. I am simply using a model that

2条回答
  •  春和景丽
    2021-02-06 08:46

    Note that y~1 counts as a linear model in R, so you can use the boxcox function from MASS:

    tmp <- exp(rnorm(10))
    out <- boxcox(lm(tmp~1))
    range(out$x[out$y > max(out$y)-qchisq(0.95,1)/2])
    

    I think that the most important part of that function is not that it finds a "best" lambda, but that it finds the confidence interval for lambda, then encourages you to think about what the different transformations mean and combine that with the science behind the data. If the "best" lambda for your data is 0.41, but the interval contains 0.5 and there is scientific reasoning why a square root transform makes sense, then why use 0.41 instead of 0.5?

提交回复
热议问题