Basic Generalised Additive Model In Ecology; Exercise

July 5, 2018

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

Generalised Additive Models (GAM) are non-parametric models that add smoother to the data. On this exercise, we will look at GAMs using cubic spline using the mgcv package. Dataset used can be downloaded here. The dataset is the experiment result at grassland richness over time in Yellowstone National Park (Skkink et al. 2007).
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. Load dataset and required package before running the exercise.

Exercise 1
observe the dataset and try to classify the response and explanatory variables. We will focus on ROCK as an explanatory variable.

Exercise 2
do some scatter plot

Exercise 3
since it is not linear, try to do GAM with ROCK variables

Exercise 4
check the result. what can be inferred

Exercise 5
do some validation plots

Exercise 6
plot base graph

Exercise 7
add predict across the data and add some lines

Exercise 8
plot the fitted values

Why we only use ROCK variables? Because it is proofed to give the most fitted data without incorporation all the explanatory variables. Try to play around with other explanatory variables to see the difference.

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)