## Introduction

The size and scope of ecological data sets, and the computational power available to analyse them, have exploded in recent years; ecologists' ambition to understand complex ecological systems has expanded in proportion. As a result, ecologists are fitting ever more complicated models to their data. While quantitatively sophisticated ecologists are gleaning rich insights from cutting-edge techniques, ecologists without formal training in statistics or numerical computation can become horribly frustrated when trying to estimate the parameters of complex models:

- Software for fitting such models may be platform-dependent or prohibitively expensive.
- Inflexible software forces users either to change their models or to modify the software.
- The documentation for fitting complex models is often sparse – software developers assume that users who are fitting complex models understand the associated, highly technical, statistical and computational issues.
- Model fitting may stop with errors, or produce obscure warnings, or get stuck at an obviously bad fit, depending on subtle changes in the way the model or the starting values are specified.
- Software may get stuck at bad fits that are not obvious, or local optima, without reporting convergence problems; few diagnostics are provided to determine whether the model is appropriate.
- Debugging capabilities are often poorly developed.

These challenges are a far cry from the old-school procedure of designing a well-controlled field experiment with response variables that are normally distributed (or transformable: O'Hara & Kotze 2010; Warton & Hui 2011) and analysing them according to simple anova frameworks (Underwood 1996; Quinn & Keough 2002; Gotelli & Ellison 2004). Even when logistical constraints required an experiment to be performed in experimental blocks, the results could still be analysed by figuring out the right category of experimental design (e.g. nested or randomized block) and looking up the appropriate sums of squares and degrees of freedom for *F* tests. ‘New school’ ecologists want to handle data, often observational and unbalanced, that are intrinsically non-normal, may be heteroscedastic, display nonlinear responses to continuous predictor variables and involve complex correlation structures that do not fit into the classical framework of nested and partly nested designs. Rather than being restricted to models that fit into classical statistical frameworks, ecologists should be able to apply the model that seems most appropriate for their questions. Even well-behaved experimental data that are traditionally analysed using anova may be analysed with more appropriate models, such as time-structured population dynamics models (de Valpine 2003), to improve precision or accuracy or address more complex ecological questions. Of course, there is no free lunch: model complexity should always be constrained by the available data (Ludwig & Walters 1985; Adkison 2009).

In a nonlinear statistical model, the predicted values are nonlinear functions of the *parameters*, not necessarily of the predictor variables: thus, a quadratic model ( ) is linear in the statistical sense (*y* is a linear function of the parameters *a*,* b* and *c* even though it is a nonlinear function of the predictor variable *x*), while a power-law model () is not: in the linear regression model *y* = *a* + *bx*,* y* is a linear function of both the parameters *a* and *b* and the predictor variable *x*.

In the power-law example, the model could be linearized by taking logarithms – log *y* = log *a* + *b* log *x*. Note, however, that the nonlinear model y∼a*x^b (using nls() in R) is different from the linear model log(y)∼1 + log(x) (using lm()), because the former assumes an error term with a constant standard deviation, while the latter assumes a constant coefficient of variation. However, most nonlinear models, such as the supplementary examples listed in Table 1, require the use of more general numerical optimization algorithms to estimate best-fit parameter values. The user must explicitly define an *objective function* that measures the fit of the model – typically this computes the residual sum of squares, log-likelihood or posterior probability – and pass it to the software as input. The software then uses numerical methods to find either a single value representing the best fit (in the case of maximum likelihood estimation) or a sample of values from near the best fit that represent a sample from the posterior distribution (in the case of Bayesian estimation). In order to define the objective function properly, users generally need to understand the properties of a variety of probability distributions and deterministic response functions (Clark 2007; McCarthy 2007; Royle & Dorazio 2008; King *et al*. 2009; Link & Barker 2010). Even once a model has been properly formulated, however, fitting it to the data to estimate the parameters is often challenging.

Name | Description |
---|---|

OrangeTree | Nonlinear growth model (normal/least-squares) |

Theta | Theta-logistic population growth model (state-space) |

Tadpole | Size-dependence in predation risk (binomial response) |

Weeds | Simple population growth model |

Min | Time series of mineralization (matrix-exponential solution of ODEs): normal/least-squares |

Owls | Zero-inflated count data with random effects |

Skate | Bayesian state-space model of winter skate mortality (ADMB, BUGS only) |

Nmix | N-mixture model with random observer effects (ADMB, BUGS only) |

Wildflower | Flowering probability as a function of size; binomial GLMM with multiple random effects |

The bottom line is that if ecologists want to fit complex models to complex data, they will need powerful, flexible model-fitting tools. The good news is that these tools do exist: the bad news is that there is a dearth of worked examples and guidance for using them. In this paper, we report on the results of a National Center for Ecological Analysis and Synthesis (NCEAS) working group whose mission was to apply a set of different tools to a broad spectrum of nonlinear ecological modelling problems (Table 1), with the goals of (i) comparing the performance and applicability of the tools in different situations and (ii) producing a series of worked examples that could serve as guides for ecologists. The full results are available at https://groups.nceas.ucsb.edu/non-linear-modeling/projects; we encourage interested readers to browse and provide feedback.

In the interests of addressing the first problem above (expensive and/or platform-dependent tools), we restricted our scope to several general-purpose, powerful, but free and open-source software (FOSS) tools: R, AD Model Builder and BUGS, described below. Because they are free, they are available to researchers with restricted budgets – such as students and researchers in developing countries or at smaller, less research-intensive institutions. Because they are open-source, they offer transparency consistent with the philosophy of reproducible research (Peng 2009) and allow end-users to modify the code according to their particular needs. In practice, few working ecologists are likely to look at the underlying source code for these software tools, let alone modify it, but the availability of the code for modification does allow rapid diversification and improvement by more computationally sophisticated ecologists. In the same spirit, all the source code for the worked examples is available on the companion website to this article.

We chose a variety of problems to exercise the capabilities of these tools, to illustrate a wide range of challenges and to create examples that would be useful to a broad set of users (Table 1). All the problems are nonlinear, ranging from simple models of normally distributed data to more complex models incorporating random effects, unusual distributions (mixture distributions or zero-inflation), spatial and temporal correlation and imperfect detection. One way in which our scope is restricted is that all of our data sets are moderate-sized: the largest data set was around 3600 observations of 10 variables (size on disk *c*. 160 kB). Thus, we are not exploring ‘big data’ in this exercise, and our methods emphasize parametric model fitting rather than exploration of patterns (Breiman 2001). We also do not investigate highly complex models that are used in some applications such as fisheries stock assessment (Maunder *et al*. 2009; Fournier *et al*. 2012).

In the rest of this paper, we (i) describe the scientific and cultural context for our work – what tools exist, in which fields they are used and how the development of statistical methods, software tools and particular scientific research projects can interact for mutual benefit; (ii) provide details of our methodology for implementing the examples; and (iii) attempt to synthesize useful general lessons from our experience that will help nonstatistical ecologists with their model-fitting challenges. The authors of this paper are all experts in at least one area of computational or statistical ecology: while we tried conscientiously to see things from the perspective of mainstream, nonstatistically expert ecologists, readers are cautioned to take terms like ‘straightforward’ and ‘simple’ with a grain of salt.