Title: | Modelling Framework for the Estimation of Salmonid Abundance |
---|---|
Description: | A set of functions to estimate capture probabilities and densities from multipass pass removal data. |
Authors: | Colin Millar [aut, cre], Rob Fryer [aut], Iain Malcolm [aut], Ross Glover [aut], Marine Scotland Science [cph] |
Maintainer: | Colin Millar <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.0 |
Built: | 2024-11-21 04:05:05 UTC |
Source: | https://github.com/cran/ef |
A set of functions to estimate capture probabilities and densities from multipass pass removal data.
Coversion of an efp fit to a gam fit for plotting
as.gam(object)
as.gam(object)
object |
an efp fitted model |
gam type object
Complete function for returning overdispersion estimates
BICadj(model, data, overdispersion.output)
BICadj(model, data, overdispersion.output)
model |
a fitted ef model |
data |
the data used to fit the model |
overdispersion.output |
output form the function overdispersion |
the adjusted BIC
When calling the function, you need to specify the data source for the model so that the number of site visits can be determined. You also need to specify the output from the overdispersion model to get the measure
A dataset containing counts from multipass electrofishing samples over three sites and 5 years.
ef_data
ef_data
A data frame with 90 rows and 9 variables:
Unique identifier for each elecrofishing site
year of data collection
date of data collections
the total number of electrofishing passes
the electrofishing pass on which the fish were caught
fish species, Salmon
fish lifestage, Fry or Parr
the number of fish caught per pass for each site visit and species, etc.
the area of river fished
https://www2.gov.scot/Topics/marine/Salmon-Trout-Coarse/Freshwater/Monitoring/temperature
This function uses the marginal likelihood of capture probabilities to estimate model parameters
efp( formula, data = NULL, pass = pass, id = id, offset = NULL, verbose = FALSE, init = "0", hessian = TRUE, fit = TRUE, sample_re = FALSE )
efp( formula, data = NULL, pass = pass, id = id, offset = NULL, verbose = FALSE, init = "0", hessian = TRUE, fit = TRUE, sample_re = FALSE )
formula |
a formula object |
data |
a data.frame containing all relavent info |
pass |
a vector of integers giving the pass number of the observation |
id |
a vector of integers identifying an observation (a set of electrofishing passes) |
offset |
an possible offset for the linear predictor of capture probability |
verbose |
if TRUE stan optimiser messages are printed to the screen |
init |
should initialisatiom be random? |
hessian |
if TRUE the hessian is computed and the covariance matrix of the parameters is returned via Vb |
fit |
if TRUE model is fitted if FALSE the data that would be passed to the optimiser is returned |
sample_re |
should sample random effects be included |
glm type object
# create two electrofishing site visits with 3 and 4 passes and 2 lifestages ef_data <- data.frame(n = c(100, 53, 24, 50, 26, 12, 100, 53, 24, 50, 26, 12), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)) ef_data2 <- data.frame(n = c(100, 53, 24, 50, 26, 12, 100, 53, 24, 12, 50, 26, 12, 6), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)) ef_data3 <- data.frame(n = c(100, 53, 24, 50, 26, 12, 40, 100, 53, 24, 12, 50, 26, 12, 6, 40), pass = c( 1, 2, 3, 1, 2, 3, 1, 1, 2, 3, 4, 1, 2, 3, 4, 1), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 5, 3, 3, 3, 3, 4, 4, 4, 4, 6)) # Fit a simple model m2 <- efp(n ~ 1 + factor(stage), data = ef_data, pass = pass, id = sample) cbind(ef_data, fit = fitted(m2)) m3 <- efp(n ~ 1 + factor(stage), data = ef_data2, pass = pass, id = sample) cbind(ef_data2, fit = fitted(m3)) m4 <- efp(n ~ 1 + factor(stage), data = ef_data3, pass = pass, id = sample) cbind(ef_data3, fit = fitted(m4)) # create two electrofishing site visits with 3 and 4 passes and 2 lifestages ef_data <- data.frame(n = c(200, 53, 24, 100, 26, 12, 200, 53, 24, 100, 26, 12), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)) # Fit a simple model m2 <- efp(n ~ 1 + factor(stage) + factor(replace(pass, pass> 2, 2)), data = ef_data, pass = pass, id = sample) out <- cbind(ef_data, p = fitted(m2, type = "p")) out
# create two electrofishing site visits with 3 and 4 passes and 2 lifestages ef_data <- data.frame(n = c(100, 53, 24, 50, 26, 12, 100, 53, 24, 50, 26, 12), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)) ef_data2 <- data.frame(n = c(100, 53, 24, 50, 26, 12, 100, 53, 24, 12, 50, 26, 12, 6), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)) ef_data3 <- data.frame(n = c(100, 53, 24, 50, 26, 12, 40, 100, 53, 24, 12, 50, 26, 12, 6, 40), pass = c( 1, 2, 3, 1, 2, 3, 1, 1, 2, 3, 4, 1, 2, 3, 4, 1), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 5, 3, 3, 3, 3, 4, 4, 4, 4, 6)) # Fit a simple model m2 <- efp(n ~ 1 + factor(stage), data = ef_data, pass = pass, id = sample) cbind(ef_data, fit = fitted(m2)) m3 <- efp(n ~ 1 + factor(stage), data = ef_data2, pass = pass, id = sample) cbind(ef_data2, fit = fitted(m3)) m4 <- efp(n ~ 1 + factor(stage), data = ef_data3, pass = pass, id = sample) cbind(ef_data3, fit = fitted(m4)) # create two electrofishing site visits with 3 and 4 passes and 2 lifestages ef_data <- data.frame(n = c(200, 53, 24, 100, 26, 12, 200, 53, 24, 100, 26, 12), pass = c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), stage = c( 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2), sample = c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)) # Fit a simple model m2 <- efp(n ~ 1 + factor(stage) + factor(replace(pass, pass> 2, 2)), data = ef_data, pass = pass, id = sample) out <- cbind(ef_data, p = fitted(m2, type = "p")) out
This function transforms values on the logistic scale to values on the probability scale.
invlogit(x)
invlogit(x)
x |
a numeric vector |
vector of values between 0 and 1
This function transforms values on the probability scale to values on the logistic scale.
logit(p)
logit(p)
p |
a numeric vector with values between 0 and 1 |
vector of values between -Inf and Inf
Complete function for returning overdispersion estimates
overdispersion( data, siteID, visitID, count = "count", pass = "pass", lifestage = "lifestage", pass12 = "pass12", id, largemodel )
overdispersion( data, siteID, visitID, count = "count", pass = "pass", lifestage = "lifestage", pass12 = "pass12", id, largemodel )
data |
dataframe containing EF data |
siteID |
site name or unique ID |
visitID |
a number identifying each unique visit |
count |
count of fish (defaults to "count") |
pass |
the EF pass number (defaults to "pass") |
lifestage |
the lifestage (defaults to "lifestage") |
pass12 |
categorical variable with 2 levels where the 1st pass and subsequent passes are treated separately (defaults to "pass12") |
id |
sample ID |
largemodel |
the large model that captures most of the systematic variation in the data - this is specified before running the overdispersion function |
a data.frame summarising overdispersion
ensure column names in function call are in inverted commas
The matrix G should be of dimension n x p, and the parameter vector should be length p
transpar(par, G)
transpar(par, G)
par |
fitted model parameters |
G |
The design matrix for a model |
a data frame