Below are the solutions to these exercises on “Generalized Linear Modeling – Part 1.” if (!require(car)){install.packages(car, dep=T)} library(car) if (!require(MuMIn)){install.packages(“MuMIn”, dep=T)} ## Warning: package ‘MuMIn’ was built under R version 3.4.4 library(MuMIn) ############### # # # Exercise 1 # # # ############### #load data and check data structure gotelli<-read.csv(file.choose()) require(car) scatterplotMatrix(~Srich + Habitat * Latitude […]

# Solutions

## Facing The Facts About Factors: Solutions

Below are the solutions to these exercises on “Facing The Facts About Factors.” #################### # # # Exercise 1 # # # #################### library(gapminder) gp <- gapminder # How many factors? sum(sapply(gp, is.factor)) ## [1] 2 # How many levels does each have? lapply(Filter(is.factor, gp), nlevels) ## $country ## [1] 142 ## ## $continent ## […]

## Basic Generalized Additive Models In Ecology: Solutions

Below are the solutions to these exercises on “GAMs – Exercises.” if (!require(mgcv)){install.packages(mgcv, dep=T)} library(mgcv) if (!require(car)){install.packages(car, dep=T)} library(car) ############### # # # Exercise 1 # # # ############### Veg <- read.csv(file.choose()) str(Veg) ## ‘data.frame’: 58 obs. of 8 variables: ## $ SR : int 8 6 8 8 10 7 6 5 8 6 […]

## Melt and Cast The Shape of Your Data-Frame: Solutions

Below are the solutions to these exercises on “Melt and Cast The Shape of Your Data-Frame.” #################### # # # Exercise 1 # # # #################### suppressMessages(library(data.table)) df <- data.frame( id = 1:2, q1 = c(“A”, “B”), q2 = c(“C”, “A”), stringsAsFactors = FALSE ) df ## id q1 q2 ## 1 1 A C […]

## Non-Linear Models in R: Solutions

Below are the solutions to these exercises on “Non-Linear Model in R.” ############### # # # Exercise 1 # # # ############### # load data file Mussel <- read.csv(file.choose()) mussel.nls1 <- nls(SPECIES ~ a * AREA^b, start = list(a = 0.1, b = 1), data = Mussel) summary(mussel.nls1) ## ## Formula: SPECIES ~ a * […]

## Intro To Time Series Analysis Part 2 :Solutions

Below are the solutions to these exercises on Time Series ############### # # # Exercise 1 # # # ############### library(forecast) library(ggplot2) class(AirPassengers) ## [1] "ts" start(AirPassengers) ## [1] 1949 1 end(AirPassengers) ## [1] 1960 12 ############### # # # Exercise 2 # # # ############### cycle(AirPassengers) ## Jan Feb Mar Apr May Jun Jul […]

## Flexdashboard: Solutions

Below are the solutions to these exercises on “Data Visualization With Flexdashboard.” #################### # # # Exercise 1 # # # #################### rmarkdown::draft(“dashboard.Rmd”, template = “flex_dashboard”, package = “flexdashboard”) #################### # # # Exercise 2 # # # #################### — title: “Single Column (Fill)” output: flexdashboard::flex_dashboard: vertical_layout: fill — #################### # # # Exercise 3 […]

## Sharpening The Knives in The data.table Toolbox: Solutions

Below are the solutions to these exercises on “Sharpening The Knives in The data.table Toolbox.” #################### # # # Exercise 1 # # # #################### library(gapminder) library(data.table) gp <- gapminder # Set as data.table setDT(gp) gp[, uniqueN(country)] ## [1] 142 #################### # # # Exercise 2 # # # #################### gp[, gdpPercap_l1 := shift(gdpPercap), by […]

## Polynomial Model in R – Study Case: Solutions

Below are the solutions to these exercises on “Polynomial Models in R – Solutions.” if (!require(car)){install.packages(car, dep=T)} library(car) ############### # # # Exercise 1 # # # ############### # load data file mussel<-read.csv(file.choose()) str(mussel) ## ‘data.frame’: 25 obs. of 3 variables: ## $ AREA : num 516 469 462 939 1357 … ## $ SPECIES: […]

## Intro To Time Series Analysis – Part 1: Solutions

Below are the solutions to these exercises on “Time Series Part 1.” ############### # # # Exercise 1 # # # ############### library(forecast) library(ggplot2) autoplot(gold) ############### # # # Exercise 2 # # # ############### which.max(gold) ## [1] 770 ############### # # # Exercise 3 # # # ############### ggseasonplot(forecast::gas) ############### # # # Exercise […]