lagfit {PopulationGrowthR} | R Documentation |
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)