Description Usage Arguments Details Value FCS2 model Note See Also Examples
Fits the both the original EA FCS2 statistical model and
also SNIFFER's multiple-pass extension that allows multiple runs
per survey.
The model allows observations to be given either as fish
counts in each run of the survey, the total count over all runs or as an
upper and lower bound for the all runs total. The fish counts depend upon
abundance μ and prevalence ρ components that are each
modelled by a covariate regression of linear, non-linear and spatial
terms.
The Bayesian model is fitted by sampling a set of potential
parameter values from the posterior distribution using MCMC via
WinBUGS or OpenBUGS. However, this can take much time so an approximate
model fit can be quickly obtained using INLA.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | fcs2FitModel(
runTotalVars = NULL,
allRunsTotalVar = NULL,
allRunsRangeVars = NULL,
muFormula = ~1,
rhoFormula = ~1,
dataFrame,
surveyAreaVar = "SurveyArea",
nRunsVar = NULL,
subset = 1:nrow(dataFrame),
na.action,
prior.parameters = list(),
initial.values = list(),
runINLA,
runBUGS = FALSE,
estAllRunsTotalVar = NULL,
n.chains = 2,
n.iter = 2000,
n.burnin = floor(n.iter/2),
n.thin = max(1, floor(n.chains * (n.iter - n.burnin)/n.sims)),
n.sims = 1000,
bugsFilename = "model.bug",
bugsProgram = "OpenBUGS",
verbose = TRUE,
fit,
...
)
|
runTotalVars |
a character vector of columns in |
allRunsTotalVar |
the name of a column in |
allRunsRangeVars |
the names of two columns in |
muFormula |
a |
rhoFormula |
a |
dataFrame |
a data frame with surveys as rows and variables as columns. It should contain all variables specified through other arguments. |
surveyAreaVar |
the name of a column in |
nRunsVar |
the name of a column in |
subset |
an optional vector specifying a subset of surveys to be used in the fitting process. |
na.action |
a function which indicates what should happen when the data
contain missing values ( |
prior.parameters |
an optional named list of named vectors giving the
parameter values to use for the prior distribution of a variable. See
|
initial.values |
an optional named list of initial values to use for
variables when fitting the full model using WinBUGS or OpenBUGS. Initial
values that are not specified are estimated using the median estimate from
INLA, unless |
runINLA |
whether to run INLA to fit approximate abundance
and prevalence models. By default, INLA is run for both models
only if necessary for providing initial values for all variables.
|
runBUGS |
whether to run WinBUGS or OpenBUGS to fit the full
FCS2 model by sampling from the posterior distribution of the
parameters. Note that BUGS can often take weeks to run with a
large data set, many regression terms, and a large number of iterations
|
estAllRunsTotalVar |
the name of a column in |
n.chains |
the number of MCMC chains to run using
BUGS. The default is |
n.iter |
the total number of iterations per chain (including burn-in).
The default is |
n.burnin |
the length of burn-in, i.e. number of iterations to discard
at the beginning. The default is |
n.thin |
the thinning rate. Must be a positive integer. Set
|
n.sims |
the approximate number of simulations to keep after thinning. |
bugsFilename |
the name to use for the BUGS model file. The
default is |
bugsProgram |
the BUGS program, either |
verbose |
whether to print progress to screen. |
fit |
an |
... |
further arguments that are passed to |
The full model (described below) is fitted by drawing Monte Carlo samples from the posterior distribution of the unknown paramters. These represent equally plausable values of the parameters. Properties of the fitted model can be estimated by averaging with these values.
The values are sampled using Markov Chain Monte Carlo (MCMC) via
WinBUGS or OpenBUGS. This can take much time to run and convergence of the
markov chains should always be verified using plotBUGSTrace
before the posterior samples can be trusted.
Approximate parameter estimates can first be produced using Integrated
Nested Laplace Approximations (INLA). This method produces
estimates in seconds but cannot be used to fit the full FCS2
model. Instead INLA fits two approximate models, one for the
prevalence regression and one for the abundance. The INLA fits
may be used to predict the significance of regression terms in the model.
See fcs2RunINLA
for further details of these models.
Returns an "fcs2Fit"
object that contains the model
specification, the required data and any INLA and BUGS
model fits. The "fcs2Fit"
object is essentially a list with the
following items:
call |
the matched call. | |||||
modelMatrix |
a
matrix of variables required by the model, extracted from | |||||
muLinearVars |
a character vector of linear terms in the abundance
regression, each of which appears as a column in | |||||
muRW1Vars, muRW2Vars |
a character vector of variables with first and second-order random walk terms in the abundance regression. | |||||
muSpatialVar |
the name of the abundance spatial variable, if present. | |||||
muAdjacency |
the adjacency information for the abundance spatial term, if present. | |||||
rhoLinearVars, rhoRW1Vars, rhoRW2Vars,
rhoSpatialVar, rhoAdjacency |
as their | |||||
dataType |
a
| |||||
rwNoLevels |
a named list giving the number of discrete levels to use to represent each random walk term. | |||||
rwBoundaries |
a named list giving the locations of the discrete points that are used to represent each non-linear covariate term. | |||||
covariateMin, covariateMax |
the minimum and maximum value for each covariate in the model. | |||||
N |
the number of surveys. | |||||
multiRun |
whether the multiple-run extension to the
FCS2 model is used. This is necessary if more than one run total
variable is specified by | |||||
inlaFits |
if INLA has been run, a list with two components:
See | |||||
bugsFit |
if
BUGS has been run, a |
In addition, the
following arguments are stored: runTotalVars
, allRunsTotalVar
,
allRunsRangeVars
, muFormula
, rhoFormula
,
surveyAreaVar
and nRunsVar
. Also, prior.parameters
and
initial.values
are corrected and completed.
The FCS2 model is a Bayesian hierarchical
model of fish counts over a number of surveys. The original EA
FCS2 model assumes a single fish count C per survey that is
modelled by a zero-inflated Negative Binomial (ZINB) distribution
(see rzinbinom
). Specifically,
C ~ ZINB(r, m=a μ, z=1 - ρ)
where r is a shape parameter, a is the survey area, μ is the abundance (mean density) and ρ is the prevalence (probability present).
The SNIFFER multiple-pass extension to the FCS2 model
instead assumes that joint fish count C_1, …, C_d over d
runs follows a zero-inflated Negative Multinomial (ZINM)
distribution (see fcs2:::zinmultinom
). Specifically,
(C_1, …, C_d) ~ ZINM(r, m_j = a μ q (1 - q)^(j - 1), z=1 - ρ)
where the additional parameter q represents the catch probability.
The remaining components of the model are common to both the original and multiple-pass FCS2. The abundance and prevalence components are both modelled using regressions in terms of other covariates x_i,j. Specifically, for survey i,
log(μ_i) = β_0 + … + f_j(x_i,j; β_j) + …
log(μ_i) = γ_0 + … + g_j(x_i,j; γ_j) + …
where f_j and g_j are regression
terms that depend upon parameters β_j and γ_j
respectively. The functions log and logit are used to
transform the components to the real line. The regression equations are
specified by setting muFormula
and rhoFormula
using symbolic
formulae.
The terms can be either linear, non-linear or spatial. Linear terms such as
β_1 x + β_2 x^2 are specified as standard
formula
. Non-linear relationships may be constructed using
random walk terms using rw1
for first-order or
rw2
for second-order random walks. A single spatial term may
be added using spatial
. This relies upon a geographical
partition of the land into a number of spatial regions. The spatial
relationship is modelled by assuming correlations between neighbouring
regions.
Being a Bayesian model, prior distributions are required for every unknown
parameter. These should represent your beliefs about their values prior to
incorporating the information from the dataset. It is common to specify
wide uninformative prior distributions to represent prior ignorance. The
default priors attempt to do this but try to balance against too wide priors
which can cause WinBUGS to fail when fitting the model. The prior
distributions should always be checked before fitting the full model. See
fcs2Priors
for further details on the prior distributions and
how to specify prior parameters via prior.parameters
.
WinBUGS (http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml) or the newer OpenBUGS (http://www.openbugs.info/w/) must be separately installed in order to fit the full FCS2 model. If OpenBUGS is used, the package BRugs must also be installed. The latest version of BRugs comes with OpenBUGS bundled within it so that an external installation is no longer necessary.
Note that INLA only uses the priors for the shape parameter r and the hyperparameter for each non-linear term.
inla
from the package INLA which is used to
provide the approximate model fits using Integrated Nested Laplace
Approximation;
bugs
from the package BRUGS which
is used to provide the full model fit using Markov Chain Monte Carlo
(MCMC);
print.fcs2Fit
and summary.fcs2Fit
for
summarising "fcs2Fit"
objects;
plot.fcs2Fit
,
plotSpatialTerm
and plotCatchPMF
for plotting
the FCS2 model fit;
plotBUGSTrace
for assessing
the MCMC convergence;
ppplot
for assessing the model fit
with a P-P plot;
fcs2SingleEQR
, fcs2JointEQR
or
fcs2JointAndSingleEQR
for producing single or joint
EQR samples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | ### Example 1: Very simple example with no covariates
###
# simulate random dataset
Data <- data.frame(SurveyArea=rlnorm(100, 4.6, 0.5)) # random survey area
Data$Catch <- rzinbinom(100, size=1.1, zeroprob=0.3,
nbmean=0.3 * Data$SurveyArea) # single catch per survey
# fit approximate model with INLA - model contains no regression terms
fit1 <- fcs2FitModel("Catch", dataFrame=Data, surveyAreaVar="SurveyArea")
## Not run:
# fit full model with OpenBUGS
# (more iterations may be required to achieve convergence)
fit1 <- fcs2FitModel(fit=fit1, runBUGS=TRUE, n.iter=1000,
bugsProgram="OpenBUGS")
## End(Not run)
# summarise fit
summary(fit1)
### Example 2: Multiple-run data with prevalence affected by a barrier
###
# add to simulated dataset
Data$NumberOfRuns <- 3 # 3 runs
Data$Barrier <- runif(100) > 0.8 # 20% chance that Barrier = TRUE
# 3 run catch with barrier effecting chance of 0
Catch <- rzinmultinom(100, size=1.1,
zeroprob=expit(-1 + 2 * Data$Barrier),
nmmean=0.3 * Data$SurveyArea %o% 0.4^(0:2))
Data$Run1 <- Catch[,1]
Data$Run2 <- Catch[,2]
Data$Run3 <- Catch[,3]
# define model with a single barrier term in prevalence regression
# and run INLA to provide an approximate fit
fit2 <- fcs2FitModel(c("Run1", "Run2", "Run3"), dataFrame=Data,
surveyAreaVar="SurveyArea", nRunsVar="NumberOfRuns",
rhoFormula= ~ Barrier)
# summarise fit to see whether barrier term is significant
summary(fit2)
## Not run:
# fit full model with OpenBUGS
fit2 <- fcs2FitModel(fit=fit2, runBUGS=TRUE, n.iter=10000,
bugsProgram="OpenBUGS")
## End(Not run)
# plot the parameter estimates
plot(fit2, group=FALSE)
### Example 3: Detailed example with multiple terms
###
# define adjacency information for 3 spatial regions appearing in a line
adjacency <- list(num=c(1, 2, 1), # number of regions adjacent to each region
adj=c(2,
1, 3,
2), # indices of these regions
sumNumNeigh=4) # total number of adjacencies
# add to simulated dataset
# randomly place each survey in one of 3 regions
Data$RegionNumber <- sample(1:3, 100, replace=TRUE)
Data$Altitude <- rlnorm(100, 4.4, 1.1) # random altitude
Data$WetWidth <- rlnorm(100, 1.5, 0.6) # random wet width
# simulate catch that varies with barrier, region, altitude but not wet width
Data$Catch <- rzinbinom(100, size=1.1,
zeroprob=expit(-1.3 + 2.9 * Data$Barrier +
2.55 * (Data$RegionNumber == 1) -
3.7 * (Data$RegionNumber == 3)),
nbmean=0.3 * Data$SurveyArea *
exp(-9.5 + 4 * log(Data$Altitude) -
0.5 * log(Data$Altitude)^2))
# define model with barrier and spatial terms in prevalence and
# with log(altitude) and log(wet width) in abundance
# run INLA to provide an approximate fit
fit3 <- fcs2FitModel("Catch", dataFrame=Data, surveyAreaVar="SurveyArea",
rhoFormula= ~ Barrier + spatial(RegionNumber, adjacency),
muFormula= ~ log(Altitude) + I(log(Altitude)^2) +
rw2(log(WetWidth)))
# summarise fit
summary(fit3)
# plot fit
plot(fit3)
# fit again without wet width term and restrict the variability
# between regions in the spatial term
fit3 <- fcs2FitModel("Catch", dataFrame=Data, surveyAreaVar="SurveyArea",
rhoFormula= ~ Barrier +
spatial(RegionNumber, adjacency,
scale.parameters=c(mean=1, sd=3)),
muFormula= ~ log(Altitude) + I(log(Altitude)^2))
# summarise fit, showing each of the variables in the spatial term
summary(fit3, allVars=TRUE)
# plot fit
plot(fit3)
# adjust the priors to make sure non-informative and fit again
fit3 <- fcs2FitModel("Catch", dataFrame=Data, surveyAreaVar="SurveyArea",
rhoFormula= ~ Barrier +
spatial(RegionNumber, adjacency,
scale.parameters=c(mean=1, sd=3)),
muFormula= ~ log(Altitude) + I(log(Altitude)^2),
prior.parameters=list(beta.const=c(mean=0, sd=30),
"beta.log(Altitude)"=c(mean=0, sd=10),
gamma.BarrierTRUE=c(mean=0, sd=5)))
# plot fit
plot(fit3)
## Not run:
# fit full model with OpenBUGS using a large number of iterations
# - this may take some time or
# even crash if some terms are not significant
fit3 <- fcs2FitModel(fit=fit3, runBUGS=TRUE, n.iter=10000,
bugsProgram="OpenBUGS")
# check MCMC chains converged and mixed well
plotBUGSTrace(fit3)
# plot fit
plot(fit3)
# plot predicted catch distribution, for first 9 surveys
plotCatchPMF(fit3, Data, 1:9, boundaries=NULL)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.