## Topic: Growth

### Topic Description:

Functions for analyzing tree growth, designed for the standard CTFS R Analytical Tables.

## Function: defineBinBreaks

### Function Description: defineBinBreaks

This finds divisions of over the vector size which produce equal number of elements per division. In case any of those divisions are too short, it tries equal sized divisions. A default to use for start parameters when none are supplied.

### Function Arguments:

ArgumentDefault Value
size
nobin
...

### Function Source:

defineBinBreaks=function(size,nobin,...)
{
extra=list(...)
if(is.null(extra\$MINBINWIDTH)) MINBINWIDTH=0.1
else MINBINWIDTH=extra\$MINBINWIDTH
if(is.null(extra\$MINBINSAMPLE)) MINBINSAMPLE=5
else MINBINSAMPLE=extra\$MINBINSAMPLE

if(nobin==1) return(numeric(0))

quant=(1:(nobin-1))/nobin
internal=quantile(size,prob=quant)
breaks=c(min(size),internal,max(size))
if(wideEnoughBins(x=size,b=breaks,...)) return(internal)

breaks=seq(min(size),max(size),length=nobin+1)
internal=breaks[2:nobin]
if(enoughSamplePerBin(x=size,b=breaks,...)) return(internal)

internal=breaks=numeric()
breaks[1]=min(size)
minwidth=MINBINWIDTH*diff(range(size))
size=sort(size)
for(i in 1:(nobin-1))
{
whichnext=MINBINSAMPLE*i+1
if(whichnext<=length(size)) enough=size[whichnext]
else enough=max(size)

wide=breaks[i]+minwidth
internal[i]=breaks[i+1]=IfElse(enough>wide,enough,wide)
}

return(internal)
}