Non-Linear Model in R Exercises

June 21, 2018

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

A mechanistic model for the relationship between x and y sometimes needs parameter estimation. When model linearisation does not work,we need to use non-linear modelling.
There are three main differences between non-linear and linear modelling in R:
1. specify the exact nature of the equation
2. replace the lm() with nls() which means nonlinear least squares
3. sometimes we also need to specify the model parameters a,b, and c.

In this exercise, we will use the same dataset as the previous exercise in polynomial regression here. Download the data-set here.
A quick overview of the dataset.
Response variable = number of invertebrates (INDIV)
Explanatory variable = the area of each clump (AREA)
Additional possible response variables = Species richness of invertebrates (SPECIES)
Answers to these exercises are available here. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.

Exercise 1
Load dataset. Specify the model, try to use power function with nls() and a=0.1 and b=1 as initial parameter number

Exercise 2
A quick check by creating plot residual versus fitted model since normal plot will not work

Exercise 3
Try to build self start function of the powered model

Exercise 4
Generate the asymptotic model

Exercise 5
Compared the asymptotic model to the powered one using AIC. What can we infer?

Exercise 6
Plot the model in one graph

Exercise 7
Predict across the data and plot all three lines

To leave a comment for the author, please follow the link and comment on their blog: R-exercises. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)