0

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)
Annemarie
  • 123
  • 1
  • 8
  • 1
    As an aside, if the skewness is due to restrictions on the data (eg. `tni` is a strictly positive continuous variable, like a size or a concentration) then consider fitting the model as a GLM (generalised linear model). The model you are using is for the expectation of log2(y) not the expectation of y itself - the GLM instead will model the expectation of y. – Gavin Simpson Apr 13 '17 at 15:11
  • @GavinSimpson Using GLM, would I not need to specify the family eg = gaussian, which would need tni to be normally distributed? – Annemarie Apr 13 '17 at 15:25
  • 1
    No; if `tni` is physically constrained to be positive (can't have a zero weight animal for example) then this implies mean-variance relationship and that the response conditional upon the covariates has some distribution, say Gamma. Such data will be skewed. Hence, if the skew you observe in `tni` is the result of a lower bound at 0 (and thence 0 variance at a value of 0), instead of fitting a linear model to the log of Y, I would fit a GLM with `family = Gamma(link = "log")` for example. – Gavin Simpson Apr 13 '17 at 20:18
  • @GavinSimpson fantastic, thank you – Annemarie Apr 14 '17 at 07:38

1 Answers1

1

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.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • Great thank you for your help. How would you then plot these predicted values to visualise the relationships between tni and age, ischaemia? – Annemarie Apr 13 '17 at 15:10
  • 1
    I'm not very familiar with Frank's **rms** package, but if `plot(Predict(m1))` does what you want, I would try `pred <- Predict(m1)` followed by `pred <- transform(pred, yhat = 2^yhat, lower = 2^lower, upper = 2^upper)`. Finally `plot(pred)`, but I'm assuming that `plot(Predict(m1))` already does what you want just without the back transformation – Gavin Simpson Apr 13 '17 at 15:12
  • Thank you. It doesn't quite work for me, but I can see that it could do... Yes, plot(Predict(m1)) does exactly what I would like, with individual plots for log2(tni) vs age and log2(tni) vs ischaemia. I would just like to get rid of the log2 for ease of clinical interpretation. – Annemarie Apr 13 '17 at 15:20
  • If you can put up a reproducible example I will look in more detail. – Gavin Simpson Apr 13 '17 at 20:19