Re: [R-sig-eco] Log transforming zero value data
The situation gives me little satisfaction. I am more or less content with substitutions in order to make use of exploratory graphical and multivariate methods. However, any substitution introduces some arbitrariness, and logarithms may be sensitive to the substituted value. A principled, likelihood based approach based on a stochastic model could be impractical for many data analyses and too narrowly specific. Here are a couple more comments, and a question of my own. * log(x + 1) is doubtful for an interval scale variable with units, e.g., a concentration, because changing the units of x changes the results of parametric tests. Substitutions that have the units of x (e.g., the suggested min(x)/2) address this invariance issue. * It is generally good to look for ways to avoid a substitution, e.g., by using rank based methods, quantiles, or perhaps censored data methods. * If a substitution is made, it could be good to check that the resulting values are not outliers. This could be important if the zeros are associated with a special population. Here is my question. Does anyone have any thoughts about the particular situation where x is a regressor, e.g., concentration of a pollutant in a regression to predict a measure of stream ecological quality. If a poor choice of substitution is viewed as a model miss-specification, I wonder about doing a a special test of fit, e.g., test the significance of a zero-one indicator of substitution. David [email protected] wrote on 06/24/2009 10:25:25 PM: > [image removed] > > Re: [R-sig-eco] Log transforming zero value data > > Nate Upham > > to: > > Ben Bolker > > 06/25/2009 06:39 AM > > Sent by: > > [email protected] > > Cc: > > r-sig-ecology > > Hey Ben, > In most of my data plots there is a "factor-ceiling"-type > distribution, which I have been describing > as "wedge-shaped" or "triangular-shaped." The data looks like a > right triangle with the central > tendency and variation decreasing as a linear function of the > habitat variable (X). This pattern of > data seems to be fairly common in ecology (either increasing or > decreasing), mostly as a result of > unmeasured habitat factors influencing the response variable. > Either way, Cade and others have been > advocating its uses in ecology for several years, so I thought I > would give it a try with my data. > In the quantreg package in R, the use of log() and exp() enable you > to model the different quantiles > with (in my case) a log-decay type function. > > Is the idea that since Y has a binomial distribution, that a GLM- > based approach could tease apart > specific impacts of the habitat variable on average densities in Y? > > Thanks, > --Nate > > > Original message > >Date: Wed, 24 Jun 2009 21:25:36 -0400 > >From: Ben Bolker > >Subject: Re: [R-sig-eco] Log transforming zero value data > >To: Nate Upham > >Cc: "[email protected]" > > > >Nate Upham wrote: > >> Hey there Ben, > >> I was just checking out your book actually. When you say that I > should do this as a binomial > >> analysis, is that because this variable is distributed similarly > to a "zero-inflated binomial > >> distribution"? > > > > It's not necessarily zero-inflated -- a moderately high proportion of > >zeros is a natural property of (non-inflated) binomial distributions > >with small p and small/moderate N. > > > >> > >> Since all my data are non-normal, and my comparisons have > heterogeneous variances, I have been using > >> quantile regression to tease apart the influence of a habitat > variable in upper quantiles as a > >> limiting factor (in the spirit of Cade et al 1999, 2003). I am > log transforming this response > >> variable for quantile regression, and then back-transforming it > when I plot the lines at different > >> quantiles. > >> > >> I do have access to the "denominator" as # of traps set per > night, but is it possible (or desirable) > >> to incorporate the binomial distribution here when my focus is on > quantile regression? > > > > If you're focusing on quantile regression because you're really > >interested in limiting factors or "ceilings" then I'd say stick with > >log-transforming (but you should definitely use additive constants that > >are "small" with respect to the variation in your data, according to one > >of the recipes specified earlier in this thread -- log(1+x) and > >log(0.5+x) really
Re: [R-sig-eco] Log transforming zero value data (+ quantile regression)
Nate, I sent you some material off the list, before I saw your more detailed discussion of quantile regression issue here on the list. Here are a couple points for benefit of other participants. 1. Since the R quantile regression package supports nonlinear quantile regression, so you might just fit y=exp(a + b*x) directly. 2. For the arguments being advanced in support of quantile regression, interesting points for discussion have to do with the generality of those arguments, and with criteria for deciding whether quantile regression is working better than "mean" regression. regards, David [email protected] wrote on 06/24/2009 10:25:25 PM: > [image removed] > > Re: [R-sig-eco] Log transforming zero value data > > Nate Upham > > to: > > Ben Bolker > > 06/25/2009 06:39 AM > > Sent by: > > [email protected] > > Cc: > > r-sig-ecology > > Hey Ben, > In most of my data plots there is a "factor-ceiling"-type > distribution, which I have been describing > as "wedge-shaped" or "triangular-shaped." The data looks like a > right triangle with the central > tendency and variation decreasing as a linear function of the > habitat variable (X). This pattern of > data seems to be fairly common in ecology (either increasing or > decreasing), mostly as a result of > unmeasured habitat factors influencing the response variable. > Either way, Cade and others have been > advocating its uses in ecology for several years, so I thought I > would give it a try with my data. > In the quantreg package in R, the use of log() and exp() enable you > to model the different quantiles > with (in my case) a log-decay type function. > > Is the idea that since Y has a binomial distribution, that a GLM- > based approach could tease apart > specific impacts of the habitat variable on average densities in Y? > > Thanks, > --Nate > > > Original message > >Date: Wed, 24 Jun 2009 21:25:36 -0400 > >From: Ben Bolker > >Subject: Re: [R-sig-eco] Log transforming zero value data > >To: Nate Upham > >Cc: "[email protected]" > > > >Nate Upham wrote: > >> Hey there Ben, > >> I was just checking out your book actually. When you say that I > should do this as a binomial > >> analysis, is that because this variable is distributed similarly > to a "zero-inflated binomial > >> distribution"? > > > > It's not necessarily zero-inflated -- a moderately high proportion of > >zeros is a natural property of (non-inflated) binomial distributions > >with small p and small/moderate N. > > > >> > >> Since all my data are non-normal, and my comparisons have > heterogeneous variances, I have been using > >> quantile regression to tease apart the influence of a habitat > variable in upper quantiles as a > >> limiting factor (in the spirit of Cade et al 1999, 2003). I am > log transforming this response > >> variable for quantile regression, and then back-transforming it > when I plot the lines at different > >> quantiles. > >> > >> I do have access to the "denominator" as # of traps set per > night, but is it possible (or desirable) > >> to incorporate the binomial distribution here when my focus is on > quantile regression? > > > > If you're focusing on quantile regression because you're really > >interested in limiting factors or "ceilings" then I'd say stick with > >log-transforming (but you should definitely use additive constants that > >are "small" with respect to the variation in your data, according to one > >of the recipes specified earlier in this thread -- log(1+x) and > >log(0.5+x) really don't make sense for your data set). [I don't really > >know what assumptions are required for inference in quantile regression, > >although I'm guessing they're pretty loose -- in particular, no > >assumption of normality -- but it may implicitly assume continuous > >distributions?] > > On the other hand, if you turned to QR as a way to get around > >heterogeneous variances etc., and you would really prefer to be able to > >draw conclusions about the average densities etc., then you might > >well be able to get farther with a binomial/GLM-based approach. Do your > >data look like "factor-ceiling" distributions as in Cade et al? > > > >-- > >Ben Bolker > >Associate professor, Biology Dep't, Univ. of Florida > >[email protected] / www.zoology
Re: [R-sig-eco] Log transforming zero value data
Hey Ben, In most of my data plots there is a "factor-ceiling"-type distribution, which I have been describing as "wedge-shaped" or "triangular-shaped." The data looks like a right triangle with the central tendency and variation decreasing as a linear function of the habitat variable (X). This pattern of data seems to be fairly common in ecology (either increasing or decreasing), mostly as a result of unmeasured habitat factors influencing the response variable. Either way, Cade and others have been advocating its uses in ecology for several years, so I thought I would give it a try with my data. In the quantreg package in R, the use of log() and exp() enable you to model the different quantiles with (in my case) a log-decay type function. Is the idea that since Y has a binomial distribution, that a GLM-based approach could tease apart specific impacts of the habitat variable on average densities in Y? Thanks, --Nate Original message >Date: Wed, 24 Jun 2009 21:25:36 -0400 >From: Ben Bolker >Subject: Re: [R-sig-eco] Log transforming zero value data >To: Nate Upham >Cc: "[email protected]" > >Nate Upham wrote: >> Hey there Ben, >> I was just checking out your book actually. When you say that I should do >> this as a binomial >> analysis, is that because this variable is distributed similarly to a >> "zero-inflated binomial >> distribution"? > > It's not necessarily zero-inflated -- a moderately high proportion of >zeros is a natural property of (non-inflated) binomial distributions >with small p and small/moderate N. > >> >> Since all my data are non-normal, and my comparisons have heterogeneous >> variances, I have been using >> quantile regression to tease apart the influence of a habitat variable in >> upper quantiles as a >> limiting factor (in the spirit of Cade et al 1999, 2003). I am log >> transforming this response >> variable for quantile regression, and then back-transforming it when I plot >> the lines at different >> quantiles. >> >> I do have access to the "denominator" as # of traps set per night, but is it >> possible (or desirable) >> to incorporate the binomial distribution here when my focus is on quantile >> regression? > > If you're focusing on quantile regression because you're really >interested in limiting factors or "ceilings" then I'd say stick with >log-transforming (but you should definitely use additive constants that >are "small" with respect to the variation in your data, according to one >of the recipes specified earlier in this thread -- log(1+x) and >log(0.5+x) really don't make sense for your data set). [I don't really >know what assumptions are required for inference in quantile regression, >although I'm guessing they're pretty loose -- in particular, no >assumption of normality -- but it may implicitly assume continuous >distributions?] > On the other hand, if you turned to QR as a way to get around >heterogeneous variances etc., and you would really prefer to be able to >draw conclusions about the average densities etc., then you might >well be able to get farther with a binomial/GLM-based approach. Do your >data look like "factor-ceiling" distributions as in Cade et al? > >-- >Ben Bolker >Associate professor, Biology Dep't, Univ. of Florida >[email protected] / www.zoology.ufl.edu/bolker >GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc > > >signature.asc (1k bytes) _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Hey there Ben, I was just checking out your book actually. When you say that I should do this as a binomial analysis, is that because this variable is distributed similarly to a "zero-inflated binomial distribution"? Since all my data are non-normal, and my comparisons have heterogeneous variances, I have been using quantile regression to tease apart the influence of a habitat variable in upper quantiles as a limiting factor (in the spirit of Cade et al 1999, 2003). I am log transforming this response variable for quantile regression, and then back-transforming it when I plot the lines at different quantiles. I do have access to the "denominator" as # of traps set per night, but is it possible (or desirable) to incorporate the binomial distribution here when my focus is on quantile regression? Thanks much, best, --Nate Original message >Date: Wed, 24 Jun 2009 17:13:07 -0400 >From: Ben Bolker >Subject: Re: [R-sig-eco] Log transforming zero value data >To: Nate Upham >Cc: Matthew Landis , "[email protected]" > > If you have percentage abundances (i.e. you can specify the >"denominator" for each data point) then it would probably >be best (if you can manage it) to do this as a binomial >analysis -- the data are unlikely to be normal (if your >analysis depends on this) after transformation. Based on the >data below, plot(table(Y)) shows that zero is in fact the >most common observation. If you can't get denominators >(although this would surprise me), you can try a beta regression, >although it will be harder to incorporate e.g. block >effects in the model. > > Ben Bolker > >Nate Upham wrote: >> Thanks very much indeed Carsten and Philippe! >> Lots to consider. I should have specified this before, but the >> variable with zero values that I would like to log (ln) transform does >> consist of many small values. The range is between 0.00 and 0.35, >> since this variable is the percentage abundance of bipedal rodents >> captured on a given night of trapping: >> >> Y <- c(0.040, 0.040, 0.030, 0.000, 0.030, 0.055, 0.120, 0.050, 0.160, >> 0.130, 0.150, 0.040, 0.080, 0.130, 0.150, 0.110, 0.280, 0.170, 0.000, >> 0.230, 0.140, 0.340, 0.000, 0.000, 0.000, 0.150, 0.020, 0.093, 0.065, >> 0.043, 0.030, 0.030, 0.055, 0.100, 0.007, 0.010, 0.030, 0.000, 0.140, >> 0.025, 0.090, 0.015, 0.078, 0.160, 0.010, 0.100, 0.000, 0.010, 0.050, >> 0.010, 0.000, 0.043, 0.087, 0.040, 0.020, 0.057, 0.107, 0.110, 0.190, >> 0.110, 0.055, 0.030, 0.091, 0.090, 0.020, 0.350, 0.200, 0.177, 0.350) >> >> From your "rules of thumb" advice, it sounds like adding 1 to this >> data through log1p() might be quite distorting to the analyses. This >> would deal with the issue of zero values (log(0+1)=0), but small >> positive values such as 0.01 would go from -4.605 to 0.00995 by log(x >> +1). Adding 0.5 is only slightly better (log(0.01+0.5)= -0.6733). >> Should I assume that this effect will "even out" over all values since >> the log(x+1) transformation is applied to the entire variable? >> >> Or, is it best to go with one of these alternatives for the c in log(x >> +c): >> 1. c <- signif(0.5*sort(unique(Y))[2], 2) #c=0.0035 >> 2. c <- (quantile(Y)[2]^2)/quantile(Y)[4] #c=0.0048 >> >> Does anyone have English references for alternatives 1 or 2? >> This is super helpful, many thanks! >> --Nate >> >> >> On Jun 24, 2009, at 6:59 AM, Matthew Landis wrote: >> >>> Many thanks to Carsten, Philippe, and Nate for a very informative >>> and entertaining discussion of something I have always wondered >>> about, having heard suggestions for both approaches. At least now I >>> have a better understanding of the rationale for each! >>> >>> Matt >>> >>> >>> Matthew Landis >>> Dept. Biology >>> Middlebury College >>> Middlebury VT 05753 >>> >> >> _ >> Nathan S. Upham >> Ph.D. student >> Committee on Evolutionary Biology >> University of Chicago >> 1025 E. 57th St., Culver 402 >> Chicago, IL 60637 >> [email protected] >> _ >> >> >> >> >> >> [[alternative HTML version deleted]] >> >> ___ >> R-sig-ecology mailing list >> [email protected] >> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > > >-- >Ben Bolker >Associate professor, Biology Dep't, Univ. of Florida >[email protected] / www.zoology.ufl.edu/bolker >GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc > > >signature.asc (1k bytes) _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Hi Nate, Here is my 2 cents worth after coming in late to this discussion. The fact that your data are proportions is important as it suggests how the data may vary. Do you have the numerator and denominator used to calculate the proportions? If so then I would suggest that you should be performing a binomial GLM with these data. If you don't have these data, or are disinclined to use them for some reason (why?) then I would strongly suggest considering a asin( sqrt( p)) transformation where p is in [0,1]. There is some justification for this: namely that this transformation stabilises the variance of a binomial variable. That is, it makes the use of un-weighted least squares more appropriate but, of course, the distributional assumptions leading to tests of significance etc may still require checking. The log transformation has similar motivation, but for a different situation. It is the variance stabilising transformation for when the data are Poisson. I find it interesting that these pieces of info were passed down to me by my PhD supervisor, who (like Carsten's supervisor) was right about so many things. HTH, Scott Nate Upham wrote: Thanks very much indeed Carsten and Philippe! Lots to consider. I should have specified this before, but the variable with zero values that I would like to log (ln) transform does consist of many small values. The range is between 0.00 and 0.35, since this variable is the percentage abundance of bipedal rodents captured on a given night of trapping: Y <- c(0.040, 0.040, 0.030, 0.000, 0.030, 0.055, 0.120, 0.050, 0.160, 0.130, 0.150, 0.040, 0.080, 0.130, 0.150, 0.110, 0.280, 0.170, 0.000, 0.230, 0.140, 0.340, 0.000, 0.000, 0.000, 0.150, 0.020, 0.093, 0.065, 0.043, 0.030, 0.030, 0.055, 0.100, 0.007, 0.010, 0.030, 0.000, 0.140, 0.025, 0.090, 0.015, 0.078, 0.160, 0.010, 0.100, 0.000, 0.010, 0.050, 0.010, 0.000, 0.043, 0.087, 0.040, 0.020, 0.057, 0.107, 0.110, 0.190, 0.110, 0.055, 0.030, 0.091, 0.090, 0.020, 0.350, 0.200, 0.177, 0.350) From your "rules of thumb" advice, it sounds like adding 1 to this data through log1p() might be quite distorting to the analyses. This would deal with the issue of zero values (log(0+1)=0), but small positive values such as 0.01 would go from -4.605 to 0.00995 by log(x +1). Adding 0.5 is only slightly better (log(0.01+0.5)= -0.6733). Should I assume that this effect will "even out" over all values since the log(x+1) transformation is applied to the entire variable? Or, is it best to go with one of these alternatives for the c in log(x +c): 1. c <- signif(0.5*sort(unique(Y))[2], 2) #c=0.0035 2. c <- (quantile(Y)[2]^2)/quantile(Y)[4] #c=0.0048 Does anyone have English references for alternatives 1 or 2? This is super helpful, many thanks! --Nate On Jun 24, 2009, at 6:59 AM, Matthew Landis wrote: Many thanks to Carsten, Philippe, and Nate for a very informative and entertaining discussion of something I have always wondered about, having heard suggestions for both approaches. At least now I have a better understanding of the rationale for each! Matt Matthew Landis Dept. Biology Middlebury College Middlebury VT 05753 _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] _ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology -- Scott Foster CSIRO Mathematical and Information Sciences GPO Box 1538 Castray Esplanade Hobart 7001 Tasmania Australia Phone: (03) 6232 5178 Fax: (03) 6232 5000 Email: [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Thanks very much indeed Carsten and Philippe! Lots to consider. I should have specified this before, but the variable with zero values that I would like to log (ln) transform does consist of many small values. The range is between 0.00 and 0.35, since this variable is the percentage abundance of bipedal rodents captured on a given night of trapping: Y <- c(0.040, 0.040, 0.030, 0.000, 0.030, 0.055, 0.120, 0.050, 0.160, 0.130, 0.150, 0.040, 0.080, 0.130, 0.150, 0.110, 0.280, 0.170, 0.000, 0.230, 0.140, 0.340, 0.000, 0.000, 0.000, 0.150, 0.020, 0.093, 0.065, 0.043, 0.030, 0.030, 0.055, 0.100, 0.007, 0.010, 0.030, 0.000, 0.140, 0.025, 0.090, 0.015, 0.078, 0.160, 0.010, 0.100, 0.000, 0.010, 0.050, 0.010, 0.000, 0.043, 0.087, 0.040, 0.020, 0.057, 0.107, 0.110, 0.190, 0.110, 0.055, 0.030, 0.091, 0.090, 0.020, 0.350, 0.200, 0.177, 0.350) From your "rules of thumb" advice, it sounds like adding 1 to this data through log1p() might be quite distorting to the analyses. This would deal with the issue of zero values (log(0+1)=0), but small positive values such as 0.01 would go from -4.605 to 0.00995 by log(x +1). Adding 0.5 is only slightly better (log(0.01+0.5)= -0.6733). Should I assume that this effect will "even out" over all values since the log(x+1) transformation is applied to the entire variable? Or, is it best to go with one of these alternatives for the c in log(x +c): 1. c <- signif(0.5*sort(unique(Y))[2], 2) #c=0.0035 2. c <- (quantile(Y)[2]^2)/quantile(Y)[4] #c=0.0048 Does anyone have English references for alternatives 1 or 2? This is super helpful, many thanks! --Nate On Jun 24, 2009, at 6:59 AM, Matthew Landis wrote: > Many thanks to Carsten, Philippe, and Nate for a very informative > and entertaining discussion of something I have always wondered > about, having heard suggestions for both approaches. At least now I > have a better understanding of the rationale for each! > > Matt > > > Matthew Landis > Dept. Biology > Middlebury College > Middlebury VT 05753 > _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] _ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Many thanks to Carsten, Philippe, and Nate for a very informative and entertaining discussion of something I have always wondered about, having heard suggestions for both approaches. At least now I have a better understanding of the rationale for each! Matt Matthew Landis Dept. Biology Middlebury College Middlebury VT 05753 ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Dear Philippe, while I don't like to quibble about rules-of-thumb (since they are, as you rightly point out, without foundation in statistical theory), I would like to correct the impression that you gave in your email. Let's take an hypothetical example along the lines you proposed (or at least of what I understand you proposed). x <- rnorm(100, mean=37, sd=1) # human body temperature How could we here have zeros? If we had zero (from a dead body in the snow, for example), then by transforming the values to Kelvin the value for c should indeed be 271, not 1! What a strange idea to argue that because a body was dead in the snow, we can assume it has the same temperature as the universe! No, sorry, I prefer to stick to the "VERY complicated" rule of thumb of using half the non-zero minimum. In my experience, zeros could arise in the following circumstance: We transplant seedlings into some treatments. Some don't survive, others thrive. So, at the end of the experiment, we have the choice of given the dead seedlings a weight of 0 or NA. If we choose 0, then we are confounding two processes: survival and growth under treatment conditions. That's what I meant when I wrote that the values come from different processes. We could/should opt for a mixed distribution approach (e.g what Zuur et al. refer to as ZAP models, in the book that Gavin mentioned). Or we could choose to transform the 0s to match the biomass of the surviving individuals. Here come's Philippe's criticism of the two rules-of-thumb: We can use grams, or milligrams, or tons, and all the time the c-value would change. Correct: it would. And rightly so, I think. Why should the value of c be some natural constant (such as 1)? Of course we seek to adjust it to the distribution of the data, because we are actually imputing (in a sense) a value we know that cannot be right as it is. Therefore it seems obvious to me that we must have rules of thumb that provide different values for different data sets. In fact, c=1 is not a constant value. Because we log-transform the data, the c=1 added to 1 is large (turning a log(1)=0 into a log(2)=0.7), while the same c=1 added to 28377 is small (turing a log(28377)=10.25333 into a 10.25337). I think this gives an impression of the distortion we add: negligible at the upper end, substantial at the lower. The second rule of thumb tries to balance that. And, really, these rules of thumb are not "VERY complicated": for c(342, 234, 132, 1441, 2, 4443, 23434, 0) rule 1 proposed c=1 (as in 2/2) and rule 2 proposes 4.5. quantile() yields: 0% 25% 50% 75%100% 0.099.5 288.0 2191.5 23434.0 99.5*99.5/2191.5 = 4.5 Do you think that is VERY complicated? Anyone volunteering for a little simulation study, analysing which rule-of-thumb would be best? Meet the candidates: 1. Eliminator (get rid of zeros) 2. Oner (log1p) 3. little-bitter (half of the smallest non-zero value) 4. quantiler (ratio of squared first and third quantile) set.seed(1) x1 <- rlnorm(100, 5, 2) x2 <- rlnorm(100, 5.5, 2) t.test(log(x1), log(x2)) x1[sample(1:100, size=40)] <- 0 x2[sample(1:100, size=40)] <- 0 1. Eliminator: t.test(log(x1[x1>0]), log(x2[x2>0])) #significant 2. Oner: t.test(log1p(x1), log1p(x2)) # not significant 3. little-bitter: sort(unique(c(x1,x2)))[2]/2 # approx. 0.6 t.test(log(x1+.6), log(x2+.6)) # not significant 4. quantiler quantile(c(x1,x2)) # Ah, now that is interesting: too many zeros and you cannot use this rule-of-thumb! quantile(c(x1,x2)[c(x1,x2)>0]) # (34^2)/541 = 2.1 t.test(log(x1+2.1), log(x2+2.1)) # not significant I wouldn't go so far as to claim that this is a real test of the contestants, it merely outlines a possible approach for doing so. In any case, neither rule-of-thump leads to "true" significance, only the eliminator! I'll be on holiday for the next weeks, in order to avoid all further discussions ... Carsten Philippe Grosjean wrote: Carsten Dormann wrote: Dear Nate, although I learned from Phillippe's response about the existence of log1p, I don't think I will use it (for reasons below). Thierry's response is true for Poisson data, but not for non-integer values. Still, it points into an important direction: All too often zeros emanate from a different process than the other values (see mixed distributions, zero-inflated, hurdle and all that). In that case, you should consult Ben Bolker's excellent book (which is probably still available as a draft on his homepage, but also worth buying). If you want to transform, here is my take: My folk-law guidelines on the c in log(x+c) are: 1. c should roughly be 1/2 of the smallest, non-zero value: signif(0.5*sort(unique(x))[2], 2) 2. c should be quadrat of the first quantile devided by the third quantile: (quantile(x)[2]^2)/quantile(x)[4] For example: set.seed(11011) x <- c(runif(95), rep(0,5)) Method 1: c=0.0015 Method 2: c=0.015 While this looks like a huge difference (an
Re: [R-sig-eco] Log transforming zero value data
Carsten Dormann wrote: Dear Nate, although I learned from Phillippe's response about the existence of log1p, I don't think I will use it (for reasons below). Thierry's response is true for Poisson data, but not for non-integer values. Still, it points into an important direction: All too often zeros emanate from a different process than the other values (see mixed distributions, zero-inflated, hurdle and all that). In that case, you should consult Ben Bolker's excellent book (which is probably still available as a draft on his homepage, but also worth buying). If you want to transform, here is my take: My folk-law guidelines on the c in log(x+c) are: 1. c should roughly be 1/2 of the smallest, non-zero value: signif(0.5*sort(unique(x))[2], 2) 2. c should be quadrat of the first quantile devided by the third quantile: (quantile(x)[2]^2)/quantile(x)[4] For example: set.seed(11011) x <- c(runif(95), rep(0,5)) Method 1: c=0.0015 Method 2: c=0.015 While this looks like a huge difference (an order of magnitude), it actually isn't all that much, given the range of the data: plot(density(x)) abline(v=c(0.0015, 0.015)) These are VERY complicated rules for just an empirical rule of thumb without connection to theoretical background. Moreover, c is depending on the dataset, and it is thus changing from dataset to dataset, which is NOT a desired behavior. So, providing maximum values are large (100s or more), and minimum value above zero not too small (let's 1, e.g., for countings), ln(x+1) alias log1p() is convenient because log1p(0) = 0. So, given we use rules of thumb, this one looks good because (1) it transforms zero to zero, and (2) transformation is independent from the content of the data. But I agree it is not a good choice when you deal with small values. Now, if you want to be more accurate, you have to determine the actual distribution of your data. If your data are (generalized) log-normally distributed, c must be defined according to what you know about the variable you measure. For instance, temperature expressed in °C would require to choose c as being 273.15 to be correct... very far away from 1, or from c that would be used with the rules you propose! Best, Philippe I do have a reference for method 2, but it is German (Stahel, W. A. (2002) Statistische Datenanalyse. Eine Einführung für Naturwissenschaftler. Vieweg, Braunschweig.). _ Method 1 is what my PhD's statistics adviser recommended. Since he was right in everything else, I rely on his advise here, too. That may, I acknowledge, not be good enough for you. But maybe someone else finds a proper reference. The key thing for any value of c is that it doesn't distort the analysis. But then, how do you detect distortion? I used a comparison of rank-transformed data and various values of c. When c was large (in the current example e.g. 0.5 or so), the analysis started to differ from the rank-analysis. To use log1p here would be a dramatic distortion! Another way to look at it is through Box-Cox-transformation. Since Box-Cox transforms towards symmetric (not necessarily normal) distribution, also c should be chosen in such a way as to facilitate the transformation towards symmetry. HTH, Carsten Nate Upham wrote: I have a general stats question for you guys: How does one normally deal with zero (0) values when log transforming data? I would like to log transform (natural log, ln) several response variables for use in quantile regression. But one of my variables includes several zero values. Since ln(0) = infinity, this is not readily possible. Is it best to remove all data with zero values? Or should I add a very small number to each value (e.g., 0.1)? This seems problematic. Is there an easy way to address this issue? Thanks much for your help, --Nate _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Dear Nate, although I learned from Phillippe's response about the existence of log1p, I don't think I will use it (for reasons below). Thierry's response is true for Poisson data, but not for non-integer values. Still, it points into an important direction: All too often zeros emanate from a different process than the other values (see mixed distributions, zero-inflated, hurdle and all that). In that case, you should consult Ben Bolker's excellent book (which is probably still available as a draft on his homepage, but also worth buying). If you want to transform, here is my take: My folk-law guidelines on the c in log(x+c) are: 1. c should roughly be 1/2 of the smallest, non-zero value: signif(0.5*sort(unique(x))[2], 2) 2. c should be quadrat of the first quantile devided by the third quantile: (quantile(x)[2]^2)/quantile(x)[4] For example: set.seed(11011) x <- c(runif(95), rep(0,5)) Method 1: c=0.0015 Method 2: c=0.015 While this looks like a huge difference (an order of magnitude), it actually isn't all that much, given the range of the data: plot(density(x)) abline(v=c(0.0015, 0.015)) I do have a reference for method 2, but it is German (Stahel, W. A. (2002) Statistische Datenanalyse. Eine Einführung für Naturwissenschaftler. Vieweg, Braunschweig.). _ Method 1 is what my PhD's statistics adviser recommended. Since he was right in everything else, I rely on his advise here, too. That may, I acknowledge, not be good enough for you. But maybe someone else finds a proper reference. The key thing for any value of c is that it doesn't distort the analysis. But then, how do you detect distortion? I used a comparison of rank-transformed data and various values of c. When c was large (in the current example e.g. 0.5 or so), the analysis started to differ from the rank-analysis. To use log1p here would be a dramatic distortion! Another way to look at it is through Box-Cox-transformation. Since Box-Cox transforms towards symmetric (not necessarily normal) distribution, also c should be chosen in such a way as to facilitate the transformation towards symmetry. HTH, Carsten Nate Upham wrote: I have a general stats question for you guys: How does one normally deal with zero (0) values when log transforming data? I would like to log transform (natural log, ln) several response variables for use in quantile regression. But one of my variables includes several zero values. Since ln(0) = infinity, this is not readily possible. Is it best to remove all data with zero values? Or should I add a very small number to each value (e.g., 0.1)? This seems problematic. Is there an easy way to address this issue? Thanks much for your help, --Nate _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology -- Dr. Carsten F. Dormann Department of Computational Landscape Ecology Helmholtz Centre for Environmental Research-UFZ Permoserstr. 15 04318 Leipzig Germany Tel: ++49(0)341 2351946 Fax: ++49(0)341 2351939 Email: [email protected] internet: http://www.ufz.de/index.php?de=4205 ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
Dear Nate, Much depend on the nature of your data. If they are counts, then I would recommend to use glm(count ~x + y + z, family = poisson) instead of lm(log(count) ~ x + y + z). Otherwise people tend to use a log(x+1) transformation. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [email protected] www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: [email protected] [mailto:[email protected]] Namens Nate Upham Verzonden: woensdag 24 juni 2009 2:31 Aan: [email protected] Onderwerp: [R-sig-eco] Log transforming zero value data I have a general stats question for you guys: How does one normally deal with zero (0) values when log transforming data? I would like to log transform (natural log, ln) several response variables for use in quantile regression. But one of my variables includes several zero values. Since ln(0) = infinity, this is not readily possible. Is it best to remove all data with zero values? Or should I add a very small number to each value (e.g., 0.1)? This seems problematic. Is there an easy way to address this issue? Thanks much for your help, --Nate _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Log transforming zero value data
See ?log1p Best, Philippe Grosjean ..<°}))>< ) ) ) ) ) ( ( ( ( (Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( (Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Belgium ( ( ( ( ( .. Nate Upham wrote: I have a general stats question for you guys: How does one normally deal with zero (0) values when log transforming data? I would like to log transform (natural log, ln) several response variables for use in quantile regression. But one of my variables includes several zero values. Since ln(0) = infinity, this is not readily possible. Is it best to remove all data with zero values? Or should I add a very small number to each value (e.g., 0.1)? This seems problematic. Is there an easy way to address this issue? Thanks much for your help, --Nate _ Nathan S. Upham Ph.D. student Committee on Evolutionary Biology University of Chicago 1025 E. 57th St., Culver 402 Chicago, IL 60637 [email protected] ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
