Tree Size Distribution: Fitting a Log-Normal to a Histogram

Tree sizes are right-skewed: many small trees, few giants. Pick countries from the Tallo database of nearly 500,000 measured trees, build a histogram of tree height, stem diameter or crown radius and fit a log-normal distribution to it – here is how.

The data

Every tree in this example was measured in the field and comes from the Tallo database (published under the CC BY 4.0 license; credited at the bottom of this page) compiled by Jucker et al. (2022) from 69 data sources. It holds 498,838 trees of 5,163 species, measured at 61,856 sites in 79 countries. For each tree, Tallo records:

  • the stem diameter in cm,
  • the height in m,
  • the crown radius in m, i.e. the mean radius of the crown seen from above.

Here, the tree position and sizes (diameter, height, crown radius) were taken from Tallo unchanged. However, in addition each tree is tagged with the country it grew in, using the country borders of Natural Earth. A tree site on the coast that lies just outside a border is given the nearest country within 25 km.

Objective

Here, we turn the data into a histogram and subsequently fit the data with a log-normal distribution.

Why a log-normal distribution?

... and not just a normal distribution? According to the central limit theorem, the sum of many independent random effects gives a normal distribution. However, the growth of a tree is rather the result of random multiplicative factors, i.e. a tree increases its size by a certain percentage as a result of precipitation, temperature, drought, ... The logarithm then turns these multiplicative factors into a sum and we end up again with the central limit theorem. Figure 1 shows the histogram of tree heights for all trees in the Tallo database.

Figure 1: Histogram of tree heights from all countries from the Tallo database.

Explore the data

You can explore the data of the Tallo database, enriched with country information, on the map below:

  1. Squares mark sites where trees were measured – not forest cover.
  2. You can filter by countries or select the trees (no filter) of the entire global Tallo database.
  3. Once you load the tree data, 3 histograms are calculated – stem diameter, height and crown radius based on the selection/filter above. Use the slider to set the number of bins.
  4. Fit this histogram opens the fitting page of the log-normal function with the calculated histograms pre-loaded. Continue reading below to learn more about the log-normal fit on Sci-eval.

Interactive map – loads in your browser

The log-normal function

Sci-eval's log-normal function describes this shape as a bell curve on a logarithmic x axis:

\(y = A e^{- \frac{\ln{\left(\frac{x}{x_{0}} \right)}^{2}}{2 w^{2}}} + y_{0}\)

A distribution with this shape appears whenever something grows by multiplication rather than by addition. Here, \(x\) is the size – the bin center of the height, the stem diameter or the crown radius – and \(y\) the number of trees in that bin. \(x_0\) is the peak position, the most common size (the mode). \(A\) is the height of the peak above the baseline. \(w\) is the width: the standard deviation of \(\ln x\). About two thirds of the trees lie within a factor \(e^{w}\) of the median size. \(y_0\) is a constant baseline; a histogram has none and so it stays at 0 here.

Statistics books write the log-normal distribution as a probability density with the parameters \(\mu\) and \(\sigma\):

\(f(x) = \frac{1}{x \sigma \sqrt{2\pi}} \, e^{- \frac{\left(\ln x - \mu\right)^{2}}{2 \sigma^{2}}}\)

The factor \(1/x\) shifts the peak to the left of \(e^{\mu}\). Written with the peak position instead, the density has exactly the shape of the function above, with \(\sigma = w\) and \(\mu = \ln x_0 + w^{2}\). So the fit gives the three typical sizes of a skewed distribution: the mode \(x_0\), the median \(x_0 \, e^{w^{2}}\) and the mean \(x_0 \, e^{3 w^{2} / 2}\).

From the textbook form to Sci-eval's form

Step 1: Move the 1/x into the exponent. Write \(1/x = e^{-\ln x}\) and let \(u = \ln x\):

\(f(x) = \frac{1}{\sigma \sqrt{2\pi}} \, e^{-u - \frac{\left(u - \mu\right)^{2}}{2 \sigma^{2}}}\)

Step 2: Complete the square in u. Put everything over \(2\sigma^{2}\):

\(\left(u - \mu\right)^{2} + 2 \sigma^{2} u = u^{2} - 2\left(\mu - \sigma^{2}\right) u + \mu^{2} = \left(u - \left(\mu - \sigma^{2}\right)\right)^{2} + 2 \mu \sigma^{2} - \sigma^{4}\)

So the exponent splits into a Gaussian in u plus a constant:

\(f(x) = \frac{1}{\sigma \sqrt{2\pi}} \, e^{-\mu + \sigma^{2}/2} \, e^{- \frac{\left(\ln x - \left(\mu - \sigma^{2}\right)\right)^{2}}{2 \sigma^{2}}}\)

Step 3: Rename the parameters. The Gaussian in \(\ln x\) peaks at \(\ln x = \mu - \sigma^{2}\). That point is the mode, so call it \(\ln x_0\):

\(\ln x_0 = \mu - \sigma^{2} \;\Leftrightarrow\; \mu = \ln x_0 + w^{2}, \quad \text{with } w = \sigma\)

Then \(\ln x - \ln x_0 = \ln(x/x_0)\), which gives Sci-eval's shape:

\(e^{- \frac{\ln{\left(\frac{x}{x_{0}} \right)}^{2}}{2 w^{2}}}\)

Step 4: Simplify the prefactor. Substitute \(\mu = \ln x_0 + w^{2}\):

\(e^{-\mu + w^{2}/2} = e^{-\ln x_0 - w^{2} + w^{2}/2} = \frac{e^{-w^{2}/2}}{x_0}\)

So the textbook density, written exactly in the new parameters, is:

\(f(x) = \frac{e^{-w^{2}/2}}{x_0 \, w \sqrt{2\pi}} \, e^{- \frac{\ln{\left(\frac{x}{x_{0}} \right)}^{2}}{2 w^{2}}}\)

The fraction in front is the density at the peak, \(f(x_0)\).

Width at half maximum

At the sizes \(x_-\) and \(x_+\) where the curve has dropped to half its peak, \(y = A/2\) (with \(y_0 = 0\)):

\(e^{- \frac{\ln{\left(\frac{x_{\pm}}{x_{0}} \right)}^{2}}{2 w^{2}}} = \frac{1}{2} \;\Rightarrow\; \ln{\left(\frac{x_{\pm}}{x_{0}} \right)} = \pm \, w \sqrt{2 \ln 2}\)

Subtracting the two solutions gives the width, and \(x_0\) is the geometric mean of \(x_-\) and \(x_+\):

\(w = \frac{\ln{\left(x_{+} / x_{-} \right)}}{2 \sqrt{2 \ln 2}} \approx \frac{\ln{\left(x_{+} / x_{-} \right)}}{2.355}, \qquad x_0 = \sqrt{x_{-} \, x_{+}}\)

For a normal distribution, the same derivation gives \(\sigma = (x_+ - x_-) / 2.355\) and \(x_0 = (x_- + x_+) / 2\): the same factor, but a difference instead of a ratio.

Fitting the data

It is not the trees themselves that are fitted, but instead the histograms computed from them (stem diameter, tree height or crown radius). With the data-explorer from above, all 3 have the same number of bins, while the bin widths differ.

Each bin is plotted at its center, and its count is the number of trees inside that bin. The table handed to the fitting page has two columns per type of tree size representing x and y, respectively:

  • Stem diameter: stem_diameter_cm and n_stem_diameter
  • Tree height: height_m and n_height
  • Crown radius: crown_radius_m and n_crown_radius

Setting up the fit

Fit this histogram opens the fitting page of the log-normal function. As a default, the histogram of the tree height is plotted using the keys height_m as \(x\) and n_height as \(y\), see Figure 2.

Figure 2: Select the x-Key and y-Key to determine which values are fitted. Here, the keys for fitting the tree height are chosen.

Alternatively, the mapping can directly be made above the data table, see Figure 3. In particular, you can assign a column of your data table to any parameter used within the function. Here, we assign height_m to the x-parameter. The column n_height is assigned to the dependent variable – the function's name, here "Log-normal".

Figure 3: Mapping of the column names to the parameter names used within the function can be made above the data table (red rectangle).

Starting values

Next, starting values need to be defined, see Figure 4. All parameters can be read/calculated from the histogram itself.

  • \(y_0 = 0\): the baseline is 0 for a histogram. Untick "do fit" for \(y_0\) to keep it constant at 0. This parameter is not fitted.
  • \(A = 70{,}000\): the count of the tallest bar.
  • \(x_0 = 5\): the center of the tallest bar. You can add a small positive lower bound, such as 0.01, to protect against invalid (zero or negative) numbers for this parameter.
  • \(w = 0.5\): a rough starting value. For a closer estimate, find the positions \(x_-\) and \(x_+\), where the histogram drops to half the tallest bar, then use \(w \approx \ln(x_+ / x_-) / 2.35\) – for the heights of all trees, about 0.7.
  • \(x\) does not need a starting value as it is read from the data table. The column height_m is mapped onto x, see above.
Figure 4: Start parameters need to be defined for all parameters of the fit-function. The parameter 'x' is taken from the data table (see mapping above).

You can check if the starting values make sense by calculating an initial guess, see Figure 5. Decrease the field "for every x-th datapoint" as needed to increase the resolution of the initial guess. Once calculated, it is displayed in the plotting frame.

Figure 5: Calculate the initial guess from the starting values (red rectangle). Here, it is calculated for every 3rd data point.

Starting the fit

If the initial guess roughly follows the data, you can start the fit by clicking "All set - start fitting" (actually it is noted mandatory to calculate an initial guess). Optionally, you can give the fit a name for your own reference later on. By default, the residuals are minimized on a linear scale as:

\(S = \sum_{i=1}^{M} \left( y(x_{i}) - n_{i} \right)^{2}\)

with the bin centers \(x_i\) and the tree counts \(n_i\) of the \(M\) bins. At the top of the page, the y-Scale can also be changed, for instance to "log". Here we keep "lin". Otherwise, on a log scale, the nearly empty bins of the tail would weigh as much as the peak.

The fit runs in the background and shows up as a new entry in the section "Fit executions" further down the page. Once the entry says SUCCESS, click it to see the fitted values and the fit statistics.

Results

The fit of the heights of all trees (using 40 bins of 2 m) is shown in Figure 6.

Figure 6: Results from fitting the tree heights of all trees in the Tallo database.

The most common tree height is \(x_0\) = 6.1 m. Half of the trees are shorter than the median, \(x_0 \, e^{w^{2}}\) = 10.3 m, and the mean is \(x_0 \, e^{3 w^{2} / 2}\) = 13.5 m. The three differ because the distribution is skewed: the long tail of tall trees pulls the median and, even more, the mean above the peak.

Comparing regions shows how forests differ. Fitted with 30 bins, the heights of Finland and Sweden (4,412 trees) give \(x_0\) = 14.9 m and \(w\) = 0.34, those of Australia (66,831 trees) \(x_0\) = 10.6 m and \(w\) = 0.61. The Nordic trees cluster tightly: two thirds of them lie within a factor of 1.4 of the median height. Australia's heights spread almost twice as wide, and the whole world, which mixes all forests, wider still (\(w\) = 0.73).

Fitted with

Data: Tallo database v1.0.0 – Jucker et al. (2022), Global Change Biology 28(17), 5254–5268, doi:10.1111/gcb.16302; dataset doi:10.5281/zenodo.6637599, CC BY 4.0. Changes: columns extracted, outlier-flagged values left empty, country tags added from Natural Earth.

Browse all examples