# How to see which transformation is the best

In R I have data and I want to make a regression analysis, finding a function that can fit the data. So head(data) gives

promotion   new_users
39.5              100
36.1               79
0.0               18


To find the optimal regression function that fitted data I plot the residuals of the regression model to see if the residuals are systematic close the zero line. But I do not know which transformation is the best one to use. Here I tried to do linear transformation, sqrttransformation and finally log-transformation.

lm.linear = lm(formula= data$new_users ~ data$promotion )
plot(resid(lm.linear), col="blue")


lm.sqrt = lm(formula= data$new_users ~ sqrt(data$promotion) )
plot(resid(lm.sqrt), col="blue")


lm.log = lm(formula= data$new_users ~ log(0.1+data$promotion ))
plot(resid(lm.log), col="blue")


If I simply just plot the data and the fitted regression function I can't see which regression function fittest the data best because they are very similar. Which transformation is the best one and is there another way to find out what is the best transformation ?

Thanks.

To see if I can use poission regression model I type

model=glm(data$new_users ~data$promotion, familiy="poisson", data=data)


I use goodnes of fit to see if the model fits.

with(m1, cbind(res.deviance = deviance, df = df.residual,
p = pchisq(deviance, df.residual, lower.tail=FALSE)))


I get a low p-value meaning that the model is a good fit?

Furthermore say we want to compare two poison regression models (one poission regr. model from data and another one from another dataset say data_new) and see if there is a significantly difference between the two, how would one do that? I assume one could use anova test to solve this.

If your dependent variable is discrete, you should be using glm with a poisson model. You can use lm but you're obviously violating assumptions.

• When I use goodnes of fit test on my possion regression model I get a low p-value so this indicates that my model fit the observed data? I entered the code above. – Ole Petersen May 23 '16 at 10:33
• No - a low model p-value just means that you can reject the null hypothesis that random chance fit the data better than your model. It doesn't mean that your model necessarily fit the data well. – Robert de Graaf May 23 '16 at 11:49
• What will be the best way to compare two poission regression models as I describe above ? – Ole Petersen May 23 '16 at 12:07
• Try anova(fit1, fit2). It should provide a test between fit1 and fit2. But this is just off memory. I'll provide a reference later. You can also try AIC and BIC functions. – Jon May 23 '16 at 15:13

There are two main reasons people typically transform their data. Either to help meet assumptions or to help boost predictive performance.

1. Help meet assumptions In your case of a linear regression, you have several assumptions that you have to meet including things like linearity and residuals have a constant variance and appear independent of each other. Transforming your response can help make your relationship more linear and help with your residual assumptions, while a transformation on your predictors primarily helps with those residuals. Typically if you are doing inference, you need normal residuals (or large sample size for CLT to kick in) which you can assess with a qq-plot or a test for normality, but if you are doing predictions you don't have to worry about this. Trying a few popular transformations (sqrt, square, log) is a good idea, as is the Box-Cox transformation (on predictors) which basically finds a transformation that maximizes the normal likelihood function of the residuals. The box-cox goes through several power transformations in a systematic manner, and it primarily used to make the residuals normal, though it can help the other issues too.
2. Improve predictive power This is more of an open game, and I would be wary of over fitting. See what works best and go with it (can be tough, might have to go with cross-validation if you're data isn't too big).
3. Your Case Usually your x-axis for those plots is the fitted values (you can plot a glm object, not sure about lm, so run through most of your basic diagnostic plots). just with those plots its also tough to assess normality, which is typically done with a qq-plot or a hisotgram of the residuals. It looks like your response variable new_users is a count; maybe a poisson model would be another option. "best" transformation is the one that helps you meet your assumptions as noted in (1), its more of finding the transformation that makes you feel most confident that your assumptions are met. If you are looking to increase performance, $R^2$ will help indicate a helpful transformation, but again be wary of overfitting. The power transformations e.g.$(x^{1/3}), log(x+0.1), x^{2}$ are usually a good route to go.

The best transformation is often a subjective decision. So you need to makr your own choicr with a sound explanation of why. In my opinion it looks as though the log transformation leads to the strongest correlation.