Annemarie
Annemarie

Reputation: 123

exponentiate log2(outcome) in rms package

I have a highly skewed outcome variable TnI, which I have transformed using log2. I have used the excellent rms package to plot the OLS predictions. Is it possible to exponentiate log2(TnI) to get the plots of predictors vs TnI instead of log2(TnI)? Many thanks, Annemarie

dd <- datadist(df); options(datadist="dd")
m1 <- ols(log2(tni) ~ age + ischaemia, data=df, x=TRUE, y=TRUE)
plot(Predict(m1)

Upvotes: 0

Views: 215

Answers (1)

Gavin Simpson
Gavin Simpson

Reputation: 174803

Yes; the inverse of the transformation xx = log_2(x) is x = 2^xx. More generally, the inverse of taking logs of x using base b is b^x.

For example:

> x <- c(4,8)
> xx <- log2(x)
> 2^xx
[1] 4 8

For the Predict() function/method, you'll need to do

predvals <- 2^Predict(m1)$yhat

or something similar, to extract the predicted values from the data frame returned by Predict(). If there are components lower and upper (if you requested a confidence interval) then you can extract and back transform these in the same manner.

Upvotes: 1

Related Questions