Package 'PopulationGrowthR'

Title: Linear Population Growth Scenarios
Description: Fit linear splines to species time series to detect population growth scenarios based on Hyndman, R J and Mesgaran, M B and Cousens, R D (2015) <doi:10.1007/s10530-015-0962-8>.
Authors: Philipp Robeck [aut], Biman Chakraborty [cre]
Maintainer: Biman Chakraborty <[email protected]>
License: GPL-3
Version: 0.1.1
Built: 2024-11-23 03:16:34 UTC
Source: https://github.com/cran/PopulationGrowthR

Help Index


Frequency and Specimens Data

Description

Example Frequency and Specimens data by year for each species to be used in 'PopulationGrowthR' package

Usage

fdata

Format

An object of class data.frame with 3771 rows and 4 columns.


Frequency plot for a lagphase fit

Description

Frequency plot for a lagphase fit

Usage

freqplot(
  fit1,
  fit2 = NULL,
  fit3 = NULL,
  fit4 = NULL,
  xlab = "Year",
  ylab = "Frequency",
  main = fit1$name,
  cols = 2:5,
  ...
)

Arguments

fit1, fit2, fit3, fit4

"lagphase" fit objects to plot

xlab

Label for the $x$-axis

ylab

Label for the $y$-axis

main

Title of the plot

cols

Colors to be used to draw the lines

...

(optional) parameters to pass to plot

Value

Produces a plot of observed and predicted frequencies for the species against year

Examples

Species = unique(fdata$Species) #List of all species
fit1 = lagfit(fdata, yeardata, species=Species[1])
freqplot(fit1$fit)

Produces plot of the fitted spline function after adjusting for number of Specimens

Description

Produces plot of the fitted spline function after adjusting for number of Specimens

Usage

growthplot(
  fit,
  ylim = NULL,
  xlab = "Year",
  ylab = "Adjusted Frequency",
  main = fit$name,
  ...
)

Arguments

fit

a "lagphase" fit object to plot

ylim

vector of size 2 - limits of the $y$-axis

xlab

Label for the $x$-axis

ylab

Label for the $y$-axis

main

Title of the plot

...

(optional) parameters to pass to plot

Value

Produces a plot of the fit with confidence bands

Examples

Species = unique(fdata$Species) #List of all species
fit1 = lagfit(fdata, yeardata, species=Species[1])
growthplot(fit1$fit)

Fits a piecewise glm model with lags

Description

This function fits a piecewise poisson model to the frequency data of different Species. It assumes that the data contains columns Year, Frequency and Specimens.

Usage

lagfit(
  data,
  yeardata,
  species = NULL,
  knots = NULL,
  zeros = TRUE,
  plotlag = FALSE,
  plotfreq = FALSE
)

Arguments

data

a dataframe containing the columns Species (optional), Year, Frequency and Specimens.

yeardata

a dataframe containing the columns Year and Specimens giving the total number of Specimens for each Year.

species

list of species for which the model is to be fitted. Default is NULL, which fits the model for all species in the data.

knots

a list of knots to be used for the piecewise model. Default is NULL, which chooses the optimal model with 0-4 knots.

zeros

logical. Specifies whether missing year for the species will be filled with zeros. Default is TRUE.

plotlag

logical. If TRUE a plot of the fitted model will be produced for each species.

plotfreq

logical. If TRUE frquency plots will be created for each species.

Value

If the model is fit for a single species following are returned as a list

  • Species - Species name

  • Scene - Different scenario of the fit between the knots. A sequence of 0, + or - is returned. A 0 indicates constant, + indicates increasing and a - indicates decreasing.

  • Lag - Logical. Is there a lag present or not.

  • Laglength - Length of the first lag. Position of the First Knot - the first year for that species

  • FirstYear - The first year for that species for which data is available.

  • EndYear - The first knot position.

  • fit - the fitted model.

If the number of species is more than one, then a list is returned with following items:

  • fitdata - dataframe is returned with the items in the above list except for the fitted model.

  • fitcoefs - list of coefficients for the piecewise fits for each Species

Examples

#Run lagfit for 1 species only
Species = unique(fdata$Species) #List of all species

fit1 = lagfit(fdata, yeardata, species=Species[1])
#Run lagfit for multiple species
fit2 = lagfit(fdata, yeardata, species=Species[1:3])
fitdata = fit2$fitdata  #Dataframe containing fits
fitcoefs = fit2$fitcoefs #List containing slopes of the fitted splines

## Not run: 
#Run lagfit for the whole dataset
fitall = lagfit(fdata, yeardata)

## End(Not run)

Extract Frequency and Specimen data from the raw data

Description

Extract Frequency and Specimen data from the raw data

Usage

raw2freqdata(rawdata, species = "species", year = "year")

Arguments

rawdata

a dataframe containing species, year

species

name of the column containing species names

year

name of the column containing year

Value

Retirns a list of two dataframes

  • data - a dataframe conatining Species, Year, Freuqency and Specimens

  • yeardata - a dataframe containing Year and Specimens

Examples

cleandata = raw2freqdata(rawdata)
fdata = cleandata$data
yeardata = cleandata$yeardata

Raw GBIF Data

Description

Example raw GBIF data used in 'PopulationGrowthR' package

Usage

rawdata

Format

An object of class data.frame with 34088 rows and 50 columns.


Total Specimens Data

Description

Example total Specimens data by year to be used in 'PopulationGrowthR' package

Usage

yeardata

Format

An object of class data.frame with 60 rows and 2 columns.