Files
RPresence/man/occMod_2SP.Rd
Jens Laufer 4f637e83b9 initial
2019-07-12 15:19:27 +02:00

203 lines
11 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/occ.mod.2sp.R
\name{occMod_2SP}
\alias{occMod_2SP}
\title{Fit two species, static occupancy (single season), or dynamic occupancy (multi-season) model}
\usage{
occMod_2SP(psi = call(), psi.cov = data$unitcov, p = call(),
p.cov = cbind(data$unitcov, data$survcov), gamma = call(),
gamma.cov = cbind(data$unitcov, data$survcov), epsilon = call(),
epsilon.cov = cbind(data$unitcov, data$survcov), param = "nu",
sp.contr = TRUE, modname = NULL, paoname = NULL, outfile,
model = 3000, fixed = NULL, initvals = NULL, data,
miscopts = miscopts)
}
\arguments{
\item{psi}{The right-hand side of the formula for the model to fit for occupancy probability.
The terms \code{SP} and \code{INT} can be used to define a species effect on occupancy and an
occurrence-level interaction between species accordingly, without them being defined in \code{psi.cov}.}
\item{psi.cov}{A data frame containing the unit-specific covariates to use for the occupancy component
of the model.}
\item{p}{The right-hand side of the formula for the model to fit for detection probability. The terms
\code{SP}, \code{INT_o} and \code{INT_d} can be used to define a species effect on detection, a
detection-level interaction where the occurrence of one species changes the detection probability of
the other species and a second detection-level interaction where the detection of one species changes
the detection probability of the other species in the same survey. These terms do not have to be
defined as variables in \code{p.cov}.}
\item{p.cov}{A data frame containing the survey-specific covariates to use for the detection component
of the model.}
\item{gamma}{The right-hand side of the formula for the model to fit for colonization probability. The
following terms can be used to define effects on colonization:
\itemize{
\item{\code{SP}}{ species effect on colonization (gammaB != gammaA)}
\item{\code{SEASON}}{ seasonal effect on colonization (gammaXX(t))}
\item{\code{INT_Ba}}{ interaction of effect on colonization for species B when species A was, or was
not present (gammaBA != gammaBa)}
\item{\code{INT_B_a}}{ interaction of effect on colonization for species B when species A was present
in the previous season and was, or was not present in succeeding season (gammaB?A != gammaB?a)}
\item{\code{INT_Baa}}{ interaction of effect on colonization for species B when species A was not present
in the previous season and was, or was not present in succeeding season (gammaBaA != gammaBaa)}
\item{\code{INT_Ab}}{ interaction of effect on colonization for species A when species B was, or was
not present in the previous season (gammaAB != gammaAb)}
}
These terms do not have to be
defined as variables in \code{p.cov}. For single-season model, set gamma to NULL.}
\item{gamma.cov}{A data frame containing the site-season-specific covariates to use for the colonization
component of the model. This should be a NxK data frame, where N=number of sites, and
K=number of sites*number of seasons.}
\item{epsilon}{The right-hand side of the formula for the model to fit for extinction probability.
The terms \code{SP}, \code{INT_Ba}, \code{INT_B_a}, \code{INT_Baa}, \code{INT_Ab}, \code{SEASON}
can be used to define effects on extinction, similar to those defined for colonization.
These terms do not have to be defined as variables in \code{p.cov}.}
\item{epsilon.cov}{A data frame containing the site-specific covariates to use for the extinction
component of the model, similar to gaam.cov.}
\item{param}{The parameterisation to be used, either "\code{psiBA}" or "\code{nu}", which relate to
\code{type="so.2sp.1"} and \code{type="so.2sp.2"} in the function \code{\link{occMod}} respectively.}
\item{sp.contr}{\code{TRUE} (default) or \code{FALSE}. Specifies the type of contrast used for the
\code{SP} term. It it used as the \code{contrasts} input in the function \code{\link{contr.treatment}}.}
\item{modname}{(optional) a string containing the model name}
\item{paoname}{(optional) a string containing the filename for the temporary PRESENCE data file.}
\item{outfile}{name for output file (use outfile='modname') for outfile named via model name}
\item{model}{The PRESENCE model code. DO NOT CHANGE.}
\item{fixed}{A single-column matrix containing values for real parameters to be fixed at.
\code{rownnames(fixed)} should contain the index of the real parameters to be fixed.}
\item{initvals}{Initial values for the beta parameters at which PRESENCE begins the optimisation.
The default values in PRESENCE is 0.}
\item{data}{The \code{pao} data object containing the detection data and other information.}
\item{VCoutopt}{option for PRESENCE computation/output of beta/real var-cov matrices}
\item{noDerived}{if TRUE, doesn't print derived estimates from model}
\item{randinit}{number of random init value vectors to try for optimization}
}
\value{
returns a list of class \code{"occMod"} and \code{"do.1"}.
\code{occMod$beta} contains the objects:
\item{psi}{estimated logistic regression coefficients and standard errors for probability of
occurrence in the first year.}
\item{psi.VC}{variance-covariance matrix for logistic regression coefficients for probability
of occurrence in the first year.}
\item{p}{estimated logistic regression coefficients and standard errors for probability of detection.}
\item{p.VC}{variance-covariance matrix for logistic regression coefficients for probability of detection.}
\item{gamma}{estimated logistic regression coefficients and standard errors for probability of colonization.}
\item{gamma.VC}{var-cov matrix for logistic regression coefficients for probability of colonization.}
\item{epsilon}{estimated logistic regression coefficients and standard errors for probability of extinction.}
\item{epsilon.VC}{var-cov matrix for logistic regression coefficients for probability of extinction.}
\item{VC}{the full variance-covariance matrix for all logistic regression coefficients.}
\code{occMod$real} contains the objects:
\item{psi}{estimated probabilities of occurrence for each sampling unit, along with standard errors
and limits of 95\% confidence interval. Estimates are provided for the first season (calculated
directly from the estimated \code{beta} parameters). Estimates for later seasons are provided as
derived parameters. The season for which an estimate applies to can be identified from the final
number of the row names (\code{rownames(psi)}).}
\item{p}{estimated probabilities of detection for each survey, along with standard errors and limits
of 95\% confidence interval.}
\item{gamma}{estimated probabilities of colonization for each sampling unit and season, along with standard errors and limits
of 95\% confidence interval.}
\item{epsilon}{estimated probabilities of extinction for each sampling unit and season, along with standard errors and limits
of 95\% confidence interval.}
\code{occMod$derived} contains the object:
\item{psi}{estimated probabilities of occurrence for each sampling unit for second season onwards,
along with standard errors and limits of 95\% confidence interval. The season for which an estimate
applies to can be identified from the final number of the row names (\code{rownames(psi)}).}
}
\description{
This is not intended for direct use, but instead the \code{\link{occMod}} function should be used with \code{type="so.2sp.1"} or \code{type="so.2sp.2"} depending on the parameterisation required. NOTE THAT THERE MAY BE SOME CHANGES TO HOW THIS MODEL IS IMPLEMENTED IN THE NEAR FUTURE.
}
\details{
Note: This function assumes data are in "compressed" format (ie.,\cr
0=neither species detected,\cr
1=only species A detected,\cr
2=only species B detected,\cr
3=both species detected)\cr
"Stacked" format can easily be converted to "compressed" format by:\cr
\code{nsites=nrow(det.data)/2\cr
new.det.data=det.data[1:nsites,]+2*det.data[nsites+1:nsites,]}
choices for \code{VCoutopt} are:
\itemize{
\item{"nose"}{only compute likelihood and beta estimates, no beta var-cov matrix or beta SE's (useful for faster model selection of big models or simulations)}
\item{"betavc"}{compute but don't print beta var-cov matrix so we get beta SE's, don't compute real params}
\item{"noreal"}{compute and print beta beta var-cov matrix, don't compute real params (I think this is what you want for RPresence)}
\item{"(default)"}{compute real params and real var-cov matrix, don't print either var-cov matrix.}
\item{"realbetavc"}{compute real params and real var-cov matrix, print only beta var-cov matrix.}
\item{"bothvc"}{print both var-cov matrices.}
}
}
\examples{
# load a csv data file
filename<-system.file("extdata/twosp_exmpl.csv",package="RPresence")
csv<-read.csv(filename,as.is=T,header=F)
##
nsites=nrow(dethist); nsrvys=ncol(dethist) # set number of sites,surveys from det. history data
dethist=matrix(as.integer(unlist(dethist)),nrow=nsites) # replace missing values (-) with NA
cov1=cov2=NULL
## create input "pao" object, for use with occMod function
data=createPao(dethist,unitcov=cov1,survcov=cov2,title="twosp example")
## fit some models
## occupancy: species-specific, no interaction, parameters: psiA, psiBA=psiBa
## detection: species-specific, p=r
mod1<-occMod(model=list(psi~SP,p~SP),data=data,type="so.2sp.1",param="PsiBA")
## occupancy: species-specific, interaction, parameters: psiA, psiBA, psiBa
## detection: species-specific, p=r
mod2<-occMod(model=list(psi~SP+INT,p~SP),data=data,type="so.2sp.1",param="PsiBA")
## occupancy: species-specific, interaction,
## detection: species=specific, interaction p,r (INT_o) and rBA,rBA (INT_d)
## Note: this is default 2 sp. model (psiA,psiBA,psiBa,pA,pB,rA,rBA,rBa)
mod3<-occMod(model=list(psi~SP+INT,p~SP+INT_o+INT_d+SP:INT_o),data=data,type="so.2sp.1",param="PsiBA")
#
\dontrun{
m1<-occMod(model=list(psi~SP,p~SP,data=data,type="so.2sp.1",param="PsiBA")
## fit some multi-season, 2-species models (using different data)
mod0<-occMod(model=list(psi=psi~SP+INT, # PsiA,psiB,psiBa
gamma =gamma~SP+INT_Ab+INT_Ba+INT_B_a+INT_Baa, # gamAB,gamAb,gamBAA,gamBAa,gamBaA,gamBaa
epsilon=epsilon~SP+INT_Ab+INT_Ba+INT_B_a+INT_Baa, # epsAB,epsAb,epsBAA,epsBAa,epsBaA,epsBaa
p =p~SP+INT_o+INT_d+SP:INT_o), # pA,pB,rA,rBA,rBa
data=data,type="do.2sp.1")
mod1<-occMod(model=list(psi=psi~SP+INT, # PsiA,psiB,psiBa
gamma =gamma~SP+INT_Ab+INT_Ba, # gamAB,gamAb,gamBA.,gamBa.
epsilon=epsilon~SP+INT_Ab+INT_Ba, # epsAB,epsAb,epsBA.,epsBa.
p =p~SP+INT_o+INT_d+SP:INT_o), # pA,pB,rA,rBA,rBa
data=data,type="do.2sp.1")
mod2<-occMod(model=list(psi=psi~SP+INT, # PsiA,psiB,psiBa
gamma =gamma~SP, # gamA.,gamB..
epsilon=epsilon~SP, # epsA.,epsB..
p =p~SP+INT_o+INT_d+SP:INT_o), # pA,pB,rA,rBA,rBa
data=data,type="do.2sp.1")
tbl=create_aic_table(list(mod0,mod1,mod2))
print(tbl$table)
}
}
\seealso{
\code{\link{occMod}}
}
\author{
Darryl MacKenzie
}