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 |
Example Frequency and Specimens data by year for each species to be used in 'PopulationGrowthR' package
fdata
fdata
An object of class data.frame
with 3771 rows and 4 columns.
Frequency plot for a lagphase fit
freqplot( fit1, fit2 = NULL, fit3 = NULL, fit4 = NULL, xlab = "Year", ylab = "Frequency", main = fit1$name, cols = 2:5, ... )
freqplot( fit1, fit2 = NULL, fit3 = NULL, fit4 = NULL, xlab = "Year", ylab = "Frequency", main = fit1$name, cols = 2:5, ... )
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 |
Produces a plot of observed and predicted frequencies for the species against year
Species = unique(fdata$Species) #List of all species fit1 = lagfit(fdata, yeardata, species=Species[1]) freqplot(fit1$fit)
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
growthplot( fit, ylim = NULL, xlab = "Year", ylab = "Adjusted Frequency", main = fit$name, ... )
growthplot( fit, ylim = NULL, xlab = "Year", ylab = "Adjusted Frequency", main = fit$name, ... )
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 |
Produces a plot of the fit with confidence bands
Species = unique(fdata$Species) #List of all species fit1 = lagfit(fdata, yeardata, species=Species[1]) growthplot(fit1$fit)
Species = unique(fdata$Species) #List of all species fit1 = lagfit(fdata, yeardata, species=Species[1]) growthplot(fit1$fit)
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.
lagfit( data, yeardata, species = NULL, knots = NULL, zeros = TRUE, plotlag = FALSE, plotfreq = FALSE )
lagfit( data, yeardata, species = NULL, knots = NULL, zeros = TRUE, plotlag = FALSE, plotfreq = FALSE )
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. |
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
#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)
#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
raw2freqdata(rawdata, species = "species", year = "year")
raw2freqdata(rawdata, species = "species", year = "year")
rawdata |
a dataframe containing species, year |
species |
name of the column containing species names |
year |
name of the column containing year |
Retirns a list of two dataframes
data - a dataframe conatining Species, Year, Freuqency and Specimens
yeardata - a dataframe containing Year and Specimens
cleandata = raw2freqdata(rawdata) fdata = cleandata$data yeardata = cleandata$yeardata
cleandata = raw2freqdata(rawdata) fdata = cleandata$data yeardata = cleandata$yeardata
Example raw GBIF data used in 'PopulationGrowthR' package
rawdata
rawdata
An object of class data.frame
with 34088 rows and 50 columns.
Example total Specimens data by year to be used in 'PopulationGrowthR' package
yeardata
yeardata
An object of class data.frame
with 60 rows and 2 columns.