# Log Transformation in R

I need to transform my not normal distributed data to normal distributed variables. Therefore I need to log-transform them. Log10(x+1) has not worked to create a normal distribution. Therefore, I want to do a log100 transformation but it does not work in R. How do I write the function to get the new data? Thanks a lot!!!

E. g.t one variable of my data set is "cover single". the hist() is: and according to the test of normal distribution: Shapiro-Wilk normality test

data: daten$Cover_single W = 0.85141, p-value = 8.116e-05 with hist(log10(daten$Cover_single+1)) the following hist exists: Shapiro-Wilk normality test

data: log10(daten$Cover_single + 1) W = 0.79318, p-value = 3.942e-06 So i dont get this variable into normal distribution by transformation. How can I do this in R? • Can you show us some plots of your data. – user2974951 Jan 9 '19 at 9:50 • i included two pictures – sonnisonja Jan 9 '19 at 10:42 • You seem to have asymmetric data with a left fat tail, I don't think this can be transformed to normal looking data. Why are you trying to do this anyway? For the Shapiro-Wilk assumption? – user2974951 Jan 9 '19 at 10:46 • Please say more about why you think you need to transform your data into a normal distribution. This is often not necessary and with a small data set you don’t often have enough power to perform a proper test of normality. See this page for extensive discussion. In your case the data seem to be proportions; there are ways to summarize such data or test hypotheses with them that don’t require normality. Providing more information about the underlying scientific question you are addressing might lead to an answer with a better way to proceed. – EdM Jan 9 '19 at 11:06 • Note that if logarithm to one base is not successful, using a different base won't make any difference. Here as cover may well be defined as between 0 and 1, it's likely that if any transformation is a good idea, it will be something else, as @EdM is also hinting. Note that your supervisor not liking GLMs is an important detail to you, it's a recipe for neglecting valuable tools. – Nick Cox Jan 9 '19 at 13:51 ## 1 Answer For a linear model your predictor variables don't need to be normally distributed and your outcome variable does not not need to be distributed normally overall. What matters for standard statistical testing in a linear model is a normal distribution of residuals around the predicted values. Furthermore, much can be learned from linear modeling even if that assumption does not hold, providing ideas to deal with violations of that assumption. See this page for illustrations of why normality of the outcome variable is not needed, and this page for discussion of the ways in which normality of residuals might matter. From your description it seems that your data could be handled by some type of multiple regression rather than by classic ANOVA. With dormouse abundance as the outcome variable, a straightforward linear regression of abundance against your untransformed predictors might work quite well. Try that, then test whether the assumption of linearity in the values of the predictors holds. Only then do you need to pay attention to the distributions of residuals and whether further transformation of your abundance values, or some type of generalized linear model, need to be considered. • Thanks a lot! Yeah i decided to work with the data as they are without transforming them. One additional question. I would like to plot all my variables individually against the dormouse abundance using correlation plots. So I type into R the following code: plot(daten$Nr_Nests~daten$Cover_single, ylab = "Dormouse Abundance", xlab = "Cover Single") abline(lm(Nr_Nests~Cover_single, data=daten)) cor(daten$Nr_Nests, daten$Cover_single, method = "spearman") cor.test(daten$Nr_Nests, daten$Cover_single, method ="spearman") can I even do this now with my non-normal distributed data? – sonnisonja Jan 9 '19 at 16:43 • Note that dollar signs need special action if they are not to be interpreted as mark-up for mathematics. Spearman correlations don't require normal distributions as they ignore everything but rank. The test of a linear fit is whether it matches the data; marginal distributions are irrelevant as such. – Nick Cox Jan 9 '19 at 16:52 • @sonnisonja your most useful results are in the linear-regression coefficients for the predictors, as each takes the influences of all the other predictors into account. The Spearman method you propose for testing correlations does not require an assumption of normality, unlike the Pearson method. The plots and correlations of abundance against each individual predictor, however, do not take the other predictors into account and could end up being misleading. – EdM Jan 9 '19 at 16:53 • this is exactly what I mean. So if I do this correlation plot by "plot(daten$Nr_Nests~daten\$Cover_single)" and then the abline by "abline(lm(Nr_Nests~Cover_single, data=daten))" it might not be suitable or work properly because "lm" is used for normal distributed data? Because I want to include the plots in my thesis as well as the statistical evaluation using cor.test. But I can only do this if I can actually plot it with "plot(lm)" – sonnisonja Jan 9 '19 at 18:15
• There is excellent advice here (+1 from me), but the nature of the response, dormouse abundance, deserves more attention. Abundance usually can't be negative (if you have negative values, you're using an unusual scale) and is often better analysed with a GLM and log link function. If there is scope for posting your data, further advice may be possible. – Nick Cox Jan 10 '19 at 10:07