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

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

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)

[Package PopulationGrowthR version 0.1.1 Index]