0

I have a dependent variable Cost and an independent variable VPT. I want to perform a power transformation on VPTwith the Box-Cox Transformation.

In the end I am looking for something like this:

C~ I(VPT^(lambda))

What are the steps to get lambda? I read it is possible to do it with the library Mass, but I am also open for other options to get lambda.

ustroetz
  • 741
  • 1
  • 8
  • 14
  • The point is that a Box-Cox program (command, function, ...) estimates it for you. – Nick Cox Apr 22 '14 at 12:55
  • I know, and I am wondering how to use the Box-Cox program? – ustroetz Apr 22 '14 at 12:56
  • Software-specific questions are off-topic here. Even in a software-based forum, you have to ask questions that don't invite the answer "Read the documentation". – Nick Cox Apr 22 '14 at 12:59
  • This question appears to be off-topic because it is about how to use a specific piece of software. Nor would it be suitable for Stack Overflow. – Nick Cox Apr 22 '14 at 13:00
  • 1
    @Nick I don't agree - software specific questions have always been on topic, as long as there's a statistical element to the question ("what are the steps to get lambda?" meets that criterion to my eyes, or potentially does). The most popular tag on CV is actually `r`. – Glen_b Apr 22 '14 at 13:23
  • Questions should be off-topic if the *only* thing the OP needs explained is how to use software. If the OP needs to understand something about statistics (etc) it can be considered on-topic. – gung - Reinstate Monica Apr 22 '14 at 13:42
  • I edit my question to be less software specific. – ustroetz Apr 22 '14 at 13:47
  • There are many ways to estimate $\lambda$ depending on what kinds of data you have and why you are attempting to make this transformation. It is used to render residuals more homoscedastic, to linearize relationships, and to symmetrize univariate distributions; each of those purposes has its own set of tools. Please edit your question to include information about the purpose of finding this transformation. – whuber Apr 22 '14 at 15:09
  • Note to discussants: OP's exact wording to which I was replying last was "I am wondering how to use the Box-Cox program". I don't see that the OP's wording has yet added any statistical question to that. I am happy to agree, as always, that making this more statistical would bring it back within the scope of CV. – Nick Cox Apr 22 '14 at 22:44

1 Answers1

0

Since the Box-Cox transformation is typically used on the dependent variable, you could try doing this (which I think would still be valid):

  1. Model your independent variable (I.V.) as a function of your dependent variable (D.V.)
  2. Use the boxcox function in MASS to estimate lambda
  3. Switch the variables in the (backwards) model above (so that D.V. ~ I.V.) and check the model fit with and without the estimated lambda.

For example:

set.seed(123)
y1 <- rnorm(200,10,2)
set.seed(321)
x1 <- .8*(y1^3)-rnorm(200)
##
require(MASS)
lm.xy <- lm(x1~y1) ## first model I.V. ~ D.V.
boxcox(lm.xy) ## for graph
bcTest <- boxcox(lm.xy,plotit=FALSE) ## for output
lambda <- bcTest$x[which.max(bcTest$y)] ## estimate of optimal lambda
## reverse your first model so that D.V. ~ I.V. 
## and compare with and without transformation:
lm0.yx <- lm(y1~x1)
lm1.yx <- lm(y1~I(((x1^lambda)-1)/lambda))
summary(lm0.yx)
summary(lm1.yx)

I am not completely positive that this is a valid approach so (anyone) please feel free to correct me if I'm wrong or if you have a better suggestion.

nrussell
  • 406
  • 4
  • 8