[R] linear regression, log-transformation and plotting
JRadinger at gmx.at
Wed Sep 7 12:17:58 CEST 2011
I've some questions concerning log-transformations and plotting of the regression lines. So far as I know is it a problem to log-transform values smaller than 1 (0-1). In my statistics lecture I was told to do a log(x+1) transformation in such cases. So I provide here a small example to explain my questions:
# Some example data for testing
data1 <- data.frame(a1,b1)
model <- lm(log(a1+1)~log(b1+1))
because of values less then one I did the log(x+1) transformation for running the lm. Is that correct so far? (Just to mention: These are example data so I haven't checked if the need a transformation at all)
Then some questions arise when it comes to plot the data. As usual I'd like to plot the original data (not log transformed) but in a log-scale.
I tried two approaches the standard plot function and ggplot.
# Plot with ggplot
# Plot with standard plot
1) The regression lines are different for plot vs. ggplot(transformed or untransformed). So what is actually the correct line?
2) The regression line was calculated on basis of log(x+1), but the log scale on my axis is just simple log (without +1). So how are such cases usually treated? I thought about subtracting the value 1 from the intercept?
So my simple question: What is the best way to display such data with a regression line?
More information about the R-help