I have a set of data with one explanatory and one response variable. They are both extremely positively skewed, and so have been transformed using a log to make them 'more normal'.
When I created a linear regression between the two variables, the fit was very good (R squared of 0.85), but the larger values were very highly under-predicted once back-transformed, due to the multiplicative nature of errors using a log transformation.
The following example shows what i mean:
set.seed(10) x=rlnorm(100,5,1) y=rlnorm(100,2,2) x=sort(x, decreasing = FALSE) y=sort(y, decreasing = FALSE) DF=data.frame(x=x,y=y) ## Plot relationship between variables plot(log(y)~log(x))
## Create regression using logged data fit=lm(log(y)~log(x), data=DF) summary(fit) ## Plot regression line plot(log(y)~log(x)) abline(-7.936712,1.990450, col="red")
## Compute predicted y values by back-transforming DF$Predicted=(exp(-7.936712)*(DF$x^1.990450)) ## Calculate sum of actual vs. predicted. sum(DF$y) # 4632.657 sum(DF$Predicted) # 3792.603 ## Create model between actual and predicted. pred_fit=lm(Predicted~y-1, data=DF) summary(pred_fit) plot(Predicted~y-1,data=DF) abline(0,1, col="red")
I have been advised to try other models (such as GLMs), but can't seem to work out exactly how these are applicable. My reason for this is:
- The relationship between the variables seems to be linear once the log transformation of both the response and explanatory variables have been applied. Therefore, a GLM would be subjected to the Gaussian family (correct me if i'm wrong), and so there is no difference to what i have already.
If I apply a GLM to the un-transformed data, using a log-link function, then will this apply the log transformation to my response or explanatory variable (or both), and would I need to back-transform afterward, like i do with the linear model?
Additionally, I don't see if this would solve the multiplicative error problem, which is my motivation for exploring this. Finally, I would like to view the results of this GLM on a plot using the log-log scale, so i can see how well the model fits the data. Not sure if this would be possible, but it would probably help me to understand.