## Non-linear growth curves with Stan

I suppose the go to tool for fitting non-linear models in R is`nls`

of the `stats`

package. In this post I will show an alternative approach with Stan/RStan, as illustrated in the example, *Dugongs: "nonlinear growth curve"*, that is part of Stan's documentation.

The original example itself is taken from OpenBUGS. The data describes the length and age measurements for 27 captured dugongs (sea cows). Carlin and Gelfand (1991) model the data using a nonlinear growth curve with no inflection point and an asymptote as \(x_i\) tends to infinity:

\[

Y_i \sim \mathcal{N}(\mu_i, \sigma^2),\; i = 1,\dots,27\\

\mu_i = \alpha - \beta \lambda^{x_i},\; \alpha,\, \beta > 0;\, 0 < \lambda < 1 \] Fitting the curve with

`nls`

gives the following results:Writing the model in Stan requires a few more lines, but gives me also the opportunity to generate output from the posterior distributions.

The predicted parameters and errors are very much the same as in the least square output of

`nls`

, but with the Stan output I can also review the 90% credible intervals.### Session Info

```
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] rstan_2.8.0 ggplot2_1.0.1.9003 Rcpp_0.12.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-6 scales_0.3.0 plyr_1.8.3
[4] parallel_3.2.2 tools_3.2.2 inline_0.3.14
[7] gtable_0.1.2 gridExtra_2.0.0 codetools_0.2-14
[10] grid_3.2.2 stats4_3.2.2 munsell_0.4.2
```

## R in Insurance 2016

Following the successful 3rd R in Insurance conference in Amsterdam this year, we will return to London next year. We will be back at Cass Business School, 11 July 2016.

The event will focus again on the use of R in insurance, bringing together experts from industry and academia with a diverse background of disciplines, such as actuarial science, catastrophe modelling, finance, statistics and computer science.

We are delighted to announce or keynote speakers already: Dan Murphy and Mario V. Wüthrich.

More details about the event will be published in due course here. For now, save the date in your diary.

PS: The picture above is a cluster analysis of the Lloyd's building in R.

Subscribe to:
Posts
(
Atom
)

## No comments :

## Post a Comment