aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2023-12-12 11:18:42 -0500
committerKen Kellner <ken@kenkellner.com>2023-12-12 11:18:42 -0500
commit409b80f9a6a9e750dfa29a2d6e887a33053e324c (patch)
tree48014d0e6c08606f01cac4a6c1a61e4d58e627c9
parent8c8fd4163236534985ade87518543b1ca374e262 (diff)
Fix R CMD check problems
-rw-r--r--NAMESPACE5
-rw-r--r--R/occuCOP.R41
-rw-r--r--_pkgdown.yml2
-rw-r--r--man/fitted-methods.Rd1
-rw-r--r--man/getP-methods.Rd3
-rw-r--r--man/nonparboot-methods.Rd1
-rw-r--r--man/occuCOP.Rd18
-rw-r--r--man/predict-methods.Rd115
-rw-r--r--man/ranef-methods.Rd1
-rw-r--r--man/simulate-methods.Rd1
-rw-r--r--man/unmarkedFit-class.Rd2
-rw-r--r--man/unmarkedFrame-class.Rd7
-rw-r--r--man/unmarkedFrameOccuCOP.Rd (renamed from man/unmarkedFrameCOP.Rd)29
-rw-r--r--src/nll_occuCOP.cpp8
-rw-r--r--tests/testthat/test_occuCOP.R58
-rw-r--r--vignettes/contributing_to_unmarked.Rmd2
16 files changed, 103 insertions, 191 deletions
diff --git a/NAMESPACE b/NAMESPACE
index b5aaf9f..6df95c0 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -40,8 +40,7 @@ exportClasses(unmarkedFit, unmarkedFitOccu, unmarkedFitOccuFP, unmarkedFitDS,
unmarkedFrameGPC, unmarkedEstimate, unmarkedFitList,
unmarkedModSel, unmarkedRanef, unmarkedFrameOccuMulti,
unmarkedFrameOccuMS, unmarkedFrameGDR, unmarkedCrossVal,
- unmarkedPostSamples, unmarkedPower, unmarkedPowerList,
- unmarkedFrameCOP, unmarkedFitCOP)
+ unmarkedPostSamples, unmarkedPower, unmarkedPowerList)
# Methods
exportMethods(backTransform, coef, confint, coordinates, fitted, getData,
@@ -64,7 +63,7 @@ export(unmarkedEstimate, fitList, mapInfo, unmarkedFrame,
unmarkedFramePCO, unmarkedFrameGDS, unmarkedFrameGPC, unmarkedFrameOccuMulti,
unmarkedFrameOccuMS, unmarkedFrameOccuTTD, unmarkedFrameDSO,
unmarkedFrameMMO, unmarkedFrameGDR, unmarkedFrameGOccu,
- unmarkedFrameCOP)
+ unmarkedFrameOccuCOP)
# Formatting
export(csvToUMF, formatLong, formatWide, formatMult, formatDistData)
diff --git a/R/occuCOP.R b/R/occuCOP.R
index 63480f4..6879576 100644
--- a/R/occuCOP.R
+++ b/R/occuCOP.R
@@ -22,9 +22,9 @@
# CLASSES ----------------------------------------------------------------------
-## unmarkedFrameCOP class ----
+## unmarkedFrameOccuCOP class ----
setClass(
- "unmarkedFrameCOP",
+ "unmarkedFrameOccuCOP",
representation(L = "matrix"),
contains = "unmarkedFrame",
validity = function(object) {
@@ -60,7 +60,7 @@ setClass("unmarkedFitCOP",
## getDesign method ----
setMethod(
- "getDesign", "unmarkedFrameCOP",
+ "getDesign", "unmarkedFrameOccuCOP",
function(umf, formlist, na.rm = TRUE) {
"
@@ -191,13 +191,13 @@ setMethod(
## getL method ----
setGeneric("getL", function(object) standardGeneric("getL"))
-setMethod("getL", "unmarkedFrameCOP", function(object) {
+setMethod("getL", "unmarkedFrameOccuCOP", function(object) {
return(object@L)
})
## show method ----
-setMethod("show", "unmarkedFrameCOP", function(object) {
+setMethod("show", "unmarkedFrameOccuCOP", function(object) {
J <- ncol(object@L)
df_unmarkedFrame <- as(object, "data.frame")
df_L <- data.frame(object@L)
@@ -217,8 +217,8 @@ setMethod("show", "unmarkedFrameCOP", function(object) {
## summary method ----
-setMethod("summary", "unmarkedFrameCOP", function(object,...) {
- cat("unmarkedFrameCOP Object\n\n")
+setMethod("summary", "unmarkedFrameOccuCOP", function(object,...) {
+ cat("unmarkedFrameOccuCOP Object\n\n")
cat(nrow(object@y), "sites\n")
cat("Maximum number of sampling occasions per site:",obsNum(object),"\n")
@@ -249,7 +249,7 @@ setMethod("summary", "unmarkedFrameCOP", function(object,...) {
## umf[i, j] ----
-setMethod("[", c("unmarkedFrameCOP", "numeric", "numeric", "missing"),
+setMethod("[", c("unmarkedFrameOccuCOP", "numeric", "numeric", "missing"),
function(x, i, j) {
# Gey dimensions of x
M <- numSites(x)
@@ -306,7 +306,7 @@ setMethod("[", c("unmarkedFrameCOP", "numeric", "numeric", "missing"),
# Recreate umf
new(
- Class = "unmarkedFrameCOP",
+ Class = "unmarkedFrameOccuCOP",
y = y,
L = L,
siteCovs = siteCovs,
@@ -318,13 +318,13 @@ setMethod("[", c("unmarkedFrameCOP", "numeric", "numeric", "missing"),
## umf[i, ] ----
-setMethod("[", c("unmarkedFrameCOP", "numeric", "missing", "missing"),
+setMethod("[", c("unmarkedFrameOccuCOP", "numeric", "missing", "missing"),
function(x, i) {
x[i, 1:obsNum(x)]
})
## umf[, j] ----
-setMethod("[", c("unmarkedFrameCOP", "missing", "numeric", "missing"),
+setMethod("[", c("unmarkedFrameOccuCOP", "missing", "numeric", "missing"),
function(x, j) {
x[1:numSites(x), j]
})
@@ -447,7 +447,7 @@ setMethod("simulate_fit", "unmarkedFitCOP",
function(object, formulas, guide, design, ...){
# Generate covariates and create a y matrix of zeros
parts <- get_umf_components(object, formulas, guide, design, ...)
- umf <- unmarkedFrameCOP(y = parts$y, siteCovs = parts$siteCovs, obsCovs=parts$obsCovs)
+ umf <- unmarkedFrameOccuCOP(y = parts$y, siteCovs = parts$siteCovs, obsCovs=parts$obsCovs)
fit <- suppressMessages(
occuCOP(
data = umf,
@@ -557,7 +557,7 @@ check.integer <- function(x, na.ignore = F) {
# unmarkedFrame ----------------------------------------------------------------
-unmarkedFrameCOP <- function(y, L, siteCovs = NULL, obsCovs = NULL, mapInfo = NULL) {
+unmarkedFrameOccuCOP <- function(y, L, siteCovs = NULL, obsCovs = NULL) {
# Verification that they are non-NA data in y
if (all(is.na(y))) {
@@ -566,7 +566,7 @@ unmarkedFrameCOP <- function(y, L, siteCovs = NULL, obsCovs = NULL, mapInfo = NU
# Verification that these are count data (and not detection/non-detection)
if (max(y, na.rm = T) == 1) {
- warning("unmarkedFrameCOP is for count data. ",
+ warning("unmarkedFrameOccuCOP is for count data. ",
"The data furnished appear to be detection/non-detection.")
}
@@ -591,15 +591,14 @@ unmarkedFrameCOP <- function(y, L, siteCovs = NULL, obsCovs = NULL, mapInfo = NU
numSites = nrow(y)
)
- # Create S4 object of class unmarkedFrameCOP
+ # Create S4 object of class unmarkedFrameOccuCOP
umf <- new(
- Class = "unmarkedFrameCOP",
+ Class = "unmarkedFrameOccuCOP",
y = y,
L = L,
siteCovs = siteCovs,
obsCovs = obsCovs,
- obsToY = diag(J),
- mapInfo = mapInfo
+ obsToY = diag(J)
)
return(umf)
@@ -683,8 +682,8 @@ occuCOP <- function(data,
}
# Check arguments ------------------------------------------------------------
- if (!is(data, "unmarkedFrameCOP")) {
- stop("Data is not an unmarkedFrameCOP object. See ?unmarkedFrameCOP if necessary.")
+ if (!is(data, "unmarkedFrameOccuCOP")) {
+ stop("Data is not an unmarkedFrameOccuCOP object. See ?unmarkedFrameOccuCOP if necessary.")
}
stopifnot(class(psiformula) == "formula")
stopifnot(class(lambdaformula) == "formula")
@@ -716,7 +715,7 @@ occuCOP <- function(data,
formlist <- mget(c("psiformula", "lambdaformula"))
# Get the design matrix (calling the getDesign method for unmarkedFrame)
- # For more informations, see: getMethod("getDesign", "unmarkedFrameCOP")
+ # For more informations, see: getMethod("getDesign", "unmarkedFrameOccuCOP")
designMats <- getDesign(umf = data, formlist = formlist, na.rm = na.rm)
# y is the count detection data (matrix of size M sites x J observations)
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 8b37a79..831489f 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -59,7 +59,7 @@ reference:
- unmarkedFrameOccuMulti
- unmarkedFramePCount
- unmarkedFrameMPois
- - unmarkedFrameCOP
+ - unmarkedFrameOccuCOP
- unmarkedFrameOccuMS
- unmarkedFrameOccuTTD
- unmarkedFrameG3
diff --git a/man/fitted-methods.Rd b/man/fitted-methods.Rd
index 8868565..98e343b 100644
--- a/man/fitted-methods.Rd
+++ b/man/fitted-methods.Rd
@@ -16,6 +16,7 @@
\alias{fitted,unmarkedFitGDR-method}
\alias{fitted,unmarkedFitDailMadsen-method}
\alias{fitted,unmarkedFitGOccu-method}
+\alias{fitted,unmarkedFitCOP-method}
\title{Methods for Function fitted in Package `unmarked'}
\description{Extracted fitted values from a fitted model.
}
diff --git a/man/getP-methods.Rd b/man/getP-methods.Rd
index 030c02d..ba26ee6 100644
--- a/man/getP-methods.Rd
+++ b/man/getP-methods.Rd
@@ -18,6 +18,7 @@
\alias{getP,unmarkedFitMMO-method}
\alias{getP,unmarkedFitGDR-method}
\alias{getP,unmarkedFitGOccu-method}
+\alias{getP,unmarkedFitCOP-method}
\title{Methods for Function getP in Package `unmarked'}
\description{
Methods for function \code{getP} in Package `unmarked'. These methods return a matrix of the back-transformed detection parameter (\eqn{p} the detection probability or \eqn{\lambda} the detection rate, depending on the model). The matrix is of dimension MxJ, with M the number of sites and J the number of sampling periods; or of dimension MxJT for models with multiple primary periods T.
@@ -28,6 +29,6 @@ Methods for function \code{getP} in Package `unmarked'. These methods return a m
\item{\code{signature(object = "unmarkedFitDS")}}{A fitted model object}
\item{\code{signature(object = "unmarkedFitMPois")}}{A fitted model object}
\item{\code{signature(object = "unmarkedFitGMM")}}{A fitted model object}
-\item{\code{signature(object = "unmarkedFitCOP")}}{With \code{\link{unmarkedFitCOP}} the object of a model fitted with \code{\link{occuCOP}}. Returns a matrix of \eqn{\lambda} the detection rate.}
+\item{\code{signature(object = "unmarkedFitCOP")}}{With \code{unmarkedFitCOP} the object of a model fitted with \code{occuCOP}. Returns a matrix of \eqn{\lambda} the detection rate.}
}}
\keyword{methods}
diff --git a/man/nonparboot-methods.Rd b/man/nonparboot-methods.Rd
index 720f241..7dd2c54 100644
--- a/man/nonparboot-methods.Rd
+++ b/man/nonparboot-methods.Rd
@@ -18,6 +18,7 @@
\alias{nonparboot,unmarkedFitNmixTTD-method}
\alias{nonparboot,unmarkedFitGDR-method}
\alias{nonparboot,unmarkedFitDailMadsen-method}
+\alias{nonparboot,unmarkedFitCOP-method}
\title{ Nonparametric bootstrapping in unmarked }
\description{
diff --git a/man/occuCOP.Rd b/man/occuCOP.Rd
index 03f58df..1693b25 100644
--- a/man/occuCOP.Rd
+++ b/man/occuCOP.Rd
@@ -2,6 +2,8 @@
\alias{occuCOP}
+\encoding{UTF-8}
+
\title{Fit the occupancy model using count dta}
\usage{
@@ -14,7 +16,7 @@ occuCOP(data,
\arguments{
- \item{data}{An \code{\linkS4class{unmarkedFrameCOP}} object created with the \code{\link{unmarkedFrameCOP}} function.}
+ \item{data}{An \code{\link{unmarkedFrameOccuCOP}} object created with the \code{\link{unmarkedFrameOccuCOP}} function.}
\item{psiformula}{Formula describing the occupancy covariates.}
@@ -32,7 +34,7 @@ occuCOP(data,
\item{engine}{Code to use for optimisation. Either \code{"C"} for fast C++ code, or \code{"R"} for native R code.}
- \item{na.rm}{Logical specifying whether to fit the model (\code{na.rm=TRUE}) or not (\code{na.rm=FALSE}) if there are NAs in the \code{\link{unmarkedFrameCOP}} object.}
+ \item{na.rm}{Logical specifying whether to fit the model (\code{na.rm=TRUE}) or not (\code{na.rm=FALSE}) if there are NAs in the \code{\link{unmarkedFrameOccuCOP}} object.}
\item{return.negloglik}{A list of vectors of parameters (\code{c(psiparams, lambdaparams)}). If specified, the function will not maximise likelihood but return the negative log-likelihood for the those parameters in the \code{nll} column of a dataframe. See an example below.}
@@ -45,7 +47,7 @@ occuCOP(data,
\details{
- See \code{\link{unmarkedFrameCOP}} for a description of how to supply data to the \code{data} argument. See \code{\link{unmarkedFrame}} for a more general documentation of \code{unmarkedFrame} objects for the different models implemented in \pkg{unmarked}.
+ See \code{\link{unmarkedFrameOccuCOP}} for a description of how to supply data to the \code{data} argument. See \code{\link{unmarkedFrame}} for a more general documentation of \code{unmarkedFrame} objects for the different models implemented in \pkg{unmarked}.
\subsection{The COP occupancy model}{
@@ -101,7 +103,7 @@ Pautrel, L., Moulherat, S., Gimenez, O. & Etienne, M.-P. Submitted. \emph{Analys
\seealso{
\code{\link{unmarked}},
- \code{\link{unmarkedFrameCOP}},
+ \code{\link{unmarkedFrameOccuCOP}},
\code{\link{unmarkedFit-class}}
}
@@ -115,8 +117,8 @@ nSites <- 100
nObs <- 3
# For an occupancy covariate, we associate each site to a land-use category.
-landuse <- sample(factor(c("Forest", "Grassland", "City"), ordered = T),
- size = nSites, replace = T)
+landuse <- sample(factor(c("Forest", "Grassland", "City"), ordered = TRUE),
+ size = nSites, replace = TRUE)
simul_psi <- ifelse(landuse == "Forest", 0.8,
ifelse(landuse == "Grassland", 0.4, 0.1))
z <- rbinom(n = nSites, size = 1, prob = simul_psi)
@@ -130,8 +132,8 @@ L = matrix(7, nrow = nSites, ncol = nObs)
y <- matrix(rpois(n = nSites * nObs, lambda = simul_lambda * L),
nrow = nSites, ncol = nObs) * z
-# We create our unmarkedFrameCOP object
-umf <- unmarkedFrameCOP(
+# We create our unmarkedFrameOccuCOP object
+umf <- unmarkedFrameOccuCOP(
y = y,
L = L,
siteCovs = data.frame("landuse" = landuse),
diff --git a/man/predict-methods.Rd b/man/predict-methods.Rd
index 4a5478f..8b1fb38 100644
--- a/man/predict-methods.Rd
+++ b/man/predict-methods.Rd
@@ -19,52 +19,14 @@
\alias{predict,unmarkedFitList-method}
\alias{predict,unmarkedRanef-method}
\title{ Methods for Function predict in Package `unmarked' }
-
-\usage{
-predict(object, type, newdata,
- backTransform = TRUE, na.rm = TRUE,
- appendData = FALSE, level = 0.95,
- re.form = NULL, ...)
-}
-
\description{
These methods return predicted values from fitted model objects.
}
-
-\arguments{
-
- \item{object}{An \linkS4class{unmarkedFit} object or an \linkS4class{unmarkedFitList} object. See methods.}
-
- \item{type}{A character string that depends upon the fitted models. You can see the possible types with \code{names(umfit)}, with \code{umfit} your \code{unmarkedFit} object.}
-
- \item{newdata}{Facultative: if no newdata, uses the actual data (\code{\link{getData}(umfit)}). When specified, \code{newdata} must be \code{\link{unmarkedFrame}}, \code{\link{data.frame}}, \code{\link{RasterLayer}}, \code{\link{RasterStack}}, or \code{\link{SpatRaster}}. See example.}
-
- \item{backTransform}{Logical specifying whether to back-transform parameters (\code{backTransform=TRUE}) or not (\code{backTransform=FALSE}).}
-
- \item{na.rm}{Logical specifying whether to remove NAs (\code{na.rm=TRUE}) or not (\code{na.rm=FALSE}).}
-
- \item{appendData}{Logical specifying whether to append the data (covariates) used for the prediction (\code{appendData=TRUE}) or not (\code{appendData=FALSE}).}
-
- \item{level}{Numeric specifying the confidence interval level.}
-
- \item{re.form}{}
-
- \item{\dots}{Unused.}
-
-}
-
-
\section{Methods}{
\describe{
\item{\code{signature(object = "unmarkedFit")}}{
-"type" depends upon the fitted models. You can see the possible types with \code{names(umfit), with \code{umfit} your \code{unmarkedFit} object.}
-}
-\item{\code{signature(object = "unmarkedFitList")}}{
-"type" depends upon the fitted models. You can see the possible types with \code{names(fl), with \code{fl} your \code{unmarkedFitList} object.}
-}
-\item{\code{signature(object = "unmarkedFitOccu")}}{
-"type" must be either 'state' or 'det'.
+"type" must be either `state' or `det'.
}
\item{\code{signature(object = "unmarkedFitColExt")}}{
"type" must be 'psi', 'col', 'ext', or 'det'.
@@ -72,6 +34,9 @@ These methods return predicted values from fitted model objects.
\item{\code{signature(object = "unmarkedFitGMM")}}{
"type" must be 'lambda', 'psi', 'det'
}
+\item{\code{signature(object = "unmarkedFitList")}}{
+"type" depends upon the fitted models
+}
\item{\code{signature(object = "unmarkedRanef")}}{
Use this method to generate the empirical Bayes posterior predictive distribution
for functions of the random variables (latent abundance or occurrence).
@@ -98,77 +63,7 @@ Alternatively, you can use the \code{\link{posteriorSamples}} function on the
This is useful if you are having trouble designing your custom function or if
you want to obtain multiple different derived parameters from the same posterior
predictive distribution.
-}
-\item{\code{signature(object = "unmarkedFitCOP")}}{
-"type" must be either 'psi' or 'lambda'.
-}
-
-}}
-
-\examples{
-set.seed(123)
-options(max.print = 100)
-
-# Simulate an unmarkedFrame with count data in 100 sites for 3 sampling occasions
-(umf <- simulate(
- "COP",
- formulas = list(psi = ~ habitat, lambda = ~ rain),
- coefs = list(
- psi = c(intercept = qlogis(.2), habitatForest = .5, habitatGrassland = .8),
- lambda = c(intercept = log(1), rain = -1)
- ),
- design = list(M = 100, J = 3),
- guide = list(habitat = factor(levels = c("City", "Forest", "Grassland")))
-))
-
-# Fit the model
-(umfit <- occuCOP(umf, psiformula = ~ habitat, lambdaformula = ~ rain, L1 = TRUE))
-
-# See the possible types for this unmarkedFit object
-names(umfit)
-# Back-transform the occupancy probability
-# = predict with the data furnished to the model
-predict(object = umfit, type = "psi", appendData = TRUE)
-
-# Because occupancy only depends on the habitat,
-# we have the same information in a more concise form by specifying newdata
-# as the 3 habitat types in our covariates data.
-predict(
- object = umfit,
- type = "psi",
- newdata = data.frame("habitat" = c("Forest", "Grassland", "City")),
- appendData = TRUE
-)
-
-# We can look at the 90% confidence interval (instead of the default 95% CI)
-predict(
- object = umfit,
- type = "psi",
- newdata = data.frame("habitat" = c("Forest", "Grassland", "City")),
- level = 0.90,
- appendData = TRUE
-)
-
-# Back-transform the detection rate
-predict(object = umfit, type = "lambda", appendData = TRUE)
-
-## This is not easily readable. We can show the results in a clearer way, by:
-## - adding the site and observation
-## - printing only the wind covariate used to get the predicted lambda
-cbind(
- data.frame(
- "site" = rep(1:numSites(umf), each = obsNum(umf)),
- "obs" = rep(1:obsNum(umf), times = numSites(umf)),
- "rain" = getData(umfit)@obsCovs
- ),
- predict(umfit, "lambda", appendData = FALSE)
-)
-
-# We can predict the detection rate with new detection covariates
-predict(umfit, "lambda",
- newdata = data.frame("rain" = c(0, 1, 2)),
- appendData = TRUE)
}
-
+}}
\keyword{methods}
diff --git a/man/ranef-methods.Rd b/man/ranef-methods.Rd
index c38e82e..d24ed2a 100644
--- a/man/ranef-methods.Rd
+++ b/man/ranef-methods.Rd
@@ -21,6 +21,7 @@
\alias{ranef,unmarkedFitGDR-method}
\alias{ranef,unmarkedFitDailMadsen-method}
\alias{ranef,unmarkedFitGOccu-method}
+\alias{ranef,unmarkedFitCOP-method}
\title{ Methods for Function \code{ranef} in Package \pkg{unmarked} }
\description{
Estimate posterior distributions of the random variables (latent
diff --git a/man/simulate-methods.Rd b/man/simulate-methods.Rd
index fc8a008..2678812 100644
--- a/man/simulate-methods.Rd
+++ b/man/simulate-methods.Rd
@@ -19,6 +19,7 @@
\alias{simulate,unmarkedFitGDR-method}
\alias{simulate,unmarkedFitDailMadsen-method}
\alias{simulate,unmarkedFitGOccu-method}
+\alias{simulate,unmarkedFitCOP-method}
\alias{simulate,character-method}
\title{Methods for Function simulate in Package `unmarked'}
\description{
diff --git a/man/unmarkedFit-class.Rd b/man/unmarkedFit-class.Rd
index 4d7aa8f..f7da3b0 100644
--- a/man/unmarkedFit-class.Rd
+++ b/man/unmarkedFit-class.Rd
@@ -18,6 +18,7 @@
\alias{plot,unmarkedFit,missing-method}
\alias{plot,unmarkedFitOccuMulti,missing-method}
\alias{plot,unmarkedFitGDR,missing-method}
+\alias{plot,unmarkedFitCOP,missing-method}
\alias{profile,unmarkedFit-method}
\alias{residuals,unmarkedFit-method}
\alias{residuals,unmarkedFitOccu-method}
@@ -26,6 +27,7 @@
\alias{residuals,unmarkedFitOccuMulti-method}
\alias{residuals,unmarkedFitOccuTTD-method}
\alias{residuals,unmarkedFitGDR-method}
+\alias{residuals,unmarkedFitCOP-method}
\alias{update,unmarkedFit-method}
\alias{update,unmarkedFitColExt-method}
\alias{update,unmarkedFitGMM-method}
diff --git a/man/unmarkedFrame-class.Rd b/man/unmarkedFrame-class.Rd
index 7118ccb..ab41506 100644
--- a/man/unmarkedFrame-class.Rd
+++ b/man/unmarkedFrame-class.Rd
@@ -51,11 +51,13 @@
\alias{show,unmarkedFrameOccuMulti-method}
\alias{show,unmarkedFrameOccuTTD-method}
\alias{show,unmarkedMultFrame-method}
+\alias{show,unmarkedFrameOccuCOP-method}
\alias{summary,unmarkedFrame-method}
\alias{summary,unmarkedFrameDS-method}
\alias{summary,unmarkedMultFrame-method}
\alias{summary,unmarkedFrameOccuMulti-method}
\alias{summary,unmarkedFrameOccuTTD-method}
+\alias{summary,unmarkedFrameOccuCOP-method}
\alias{[,unmarkedFrameOccuMulti,missing,numeric,missing-method}
\alias{[,unmarkedFrameOccuTTD,missing,numeric,missing-method}
\alias{[,unmarkedFrameGDR,missing,numeric,missing-method}
@@ -65,6 +67,9 @@
\alias{[,unmarkedFrameDSO,numeric,missing,missing-method}
\alias{[,unmarkedFrameGDR,numeric,missing,missing-method}
\alias{[,unmarkedFrameGDR,logical,missing,missing-method}
+\alias{[,unmarkedFrameOccuCOP,missing,numeric,missing-method}
+\alias{[,unmarkedFrameOccuCOP,numeric,missing,missing-method}
+\alias{[,unmarkedFrameOccuCOP,numeric,numeric,missing-method}
\title{Class "unmarkedFrame" }
\description{Methods for manipulating, summarizing and viewing
@@ -120,7 +125,7 @@ argument of the fitting functions.
modify site-level covariates }
\item{summary}{\code{signature(object = "unmarkedFrame")}: summarize
data }
- \item{getL}{\code{signature(object = "unmarkedFrameCOP")}: extract L }
+ \item{getL}{\code{signature(object = "unmarkedFrameOccuCOP")}: extract L }
}
}
\note{ This is a superclass with child classes for each fitting function.}
diff --git a/man/unmarkedFrameCOP.Rd b/man/unmarkedFrameOccuCOP.Rd
index a901b81..3bc1cb0 100644
--- a/man/unmarkedFrameCOP.Rd
+++ b/man/unmarkedFrameOccuCOP.Rd
@@ -1,9 +1,11 @@
-\name{unmarkedFrameCOP}
-\alias{unmarkedFrameCOP}
+\name{unmarkedFrameOccuCOP}
+\alias{unmarkedFrameOccuCOP}
+\alias{getL}
+\alias{getL,unmarkedFrameOccuCOP-method}
\title{Organize data for the occupancy model using count data fit by \code{occuCOP}}
-\usage{unmarkedFrameCOP(y, L, siteCovs = NULL, obsCovs = NULL)}
+\usage{unmarkedFrameOccuCOP(y, L, siteCovs = NULL, obsCovs = NULL)}
\description{Organizes count data along with the covariates. The \linkS4class{unmarkedFrame} S4 class required by the \code{data} argument of \code{\link{occuCOP}}.}
@@ -21,10 +23,10 @@
}
\details{
- unmarkedFrameCOP is the \linkS4class{unmarkedFrame} S4 class that holds data to be passed to the \code{\link{occuCOP}} model-fitting function.
+ unmarkedFrameOccuCOP is the \linkS4class{unmarkedFrame} S4 class that holds data to be passed to the \code{\link{occuCOP}} model-fitting function.
}
-\value{an object of class \code{unmarkedFrameCOP}}
+\value{an object of class \code{unmarkedFrameOccuCOP}}
\seealso{
\code{\link{unmarkedFrame-class}},
@@ -45,7 +47,7 @@ J <- 3 # Number of observation periods
1, NA, 0),
nrow = M,
ncol = J,
- byrow = T
+ byrow = TRUE
))
# Length of observation periods
@@ -56,7 +58,7 @@ J <- 3 # Number of observation periods
7, 1, 3),
nrow = M,
ncol = J,
- byrow = T
+ byrow = TRUE
))
# Site covariates
@@ -69,18 +71,21 @@ J <- 3 # Number of observation periods
(obs.covs.list <- list(
"rain" = matrix(rexp(M * J), nrow = M, ncol = J),
"wind" = matrix(
- sample(letters[1:3], replace = T, size = M * J),
+ sample(letters[1:3], replace = TRUE, size = M * J),
nrow = M, ncol = J)
))
-# Organise data in a unmarkedFrameCOP object
-umf <- unmarkedFrameCOP(
+# Organise data in a unmarkedFrameOccuCOP object
+umf <- unmarkedFrameOccuCOP(
y = y,
L = L,
siteCovs = site.covs,
obsCovs = obs.covs.list
)
+# Extract L
+getL(umf)
+
# Look at data
print(umf) # Print the whole data set
print(umf[1, 2]) # Print the data of the 1st site, 2nd observation
@@ -89,12 +94,12 @@ plot(umf) # Plot the count of detection events
# L is optional, if absent, it will be replaced by a MxJ matrix of 1
-unmarkedFrameCOP(
+unmarkedFrameOccuCOP(
y = y,
siteCovs = site.covs,
obsCovs = obs.covs.list
)
# Covariates are optional
-unmarkedFrameCOP(y = y)
+unmarkedFrameOccuCOP(y = y)
}
diff --git a/src/nll_occuCOP.cpp b/src/nll_occuCOP.cpp
index 5ce374e..8c18bbf 100644
--- a/src/nll_occuCOP.cpp
+++ b/src/nll_occuCOP.cpp
@@ -4,11 +4,11 @@
using namespace Rcpp ;
// [[Rcpp::export]]
-double nll_occuCOP(arma::icolvec y, arma::icolvec L,
+double nll_occuCOP(arma::icolvec y, arma::icolvec L,
arma::mat Xpsi, arma::mat Xlambda,
arma::colvec beta_psi, arma::colvec beta_lambda,
Rcpp::LogicalVector removed) {
-
+
// Number of sites M and obs J
int M = Xpsi.n_rows;
int J = y.n_elem / M;
@@ -18,7 +18,7 @@ double nll_occuCOP(arma::icolvec y, arma::icolvec L,
//Calculate lambda back-transformed from log
arma::colvec lambda = exp(Xlambda*beta_lambda);
-
+
double ll=0.0;
int k=0; // counter
// for each site i in 1:M
@@ -36,7 +36,7 @@ double nll_occuCOP(arma::icolvec y, arma::icolvec L,
}
k++;
}
- if (!NbRemoved < J) {
+ if ((!NbRemoved) < J) {
if(iN>0) {
ll += log(psi(i) * pow(iLambdaL, iN) / tgamma(iN + 1) * exp(-iLambdaL));
} else {
diff --git a/tests/testthat/test_occuCOP.R b/tests/testthat/test_occuCOP.R
index eca1130..54445bb 100644
--- a/tests/testthat/test_occuCOP.R
+++ b/tests/testthat/test_occuCOP.R
@@ -19,7 +19,7 @@ COPsimul <- function(psi = 0.5,
}
-test_that("unmarkedFrameCOP is constructed correctly", {
+test_that("unmarkedFrameOccuCOP is constructed correctly", {
set.seed(123)
# Simulate data
@@ -71,9 +71,9 @@ test_that("unmarkedFrameCOP is constructed correctly", {
)
- # Creating a unmarkedFrameCOP object
- expect_warning(umf <- unmarkedFrameCOP(y = y))
- expect_no_error(umf <- unmarkedFrameCOP(y = y, L = L))
+ # Creating a unmarkedFrameOccuCOP object
+ expect_warning(umf <- unmarkedFrameOccuCOP(y = y))
+ expect_no_error(umf <- unmarkedFrameOccuCOP(y = y, L = L))
# Create subsets
@@ -81,14 +81,14 @@ test_that("unmarkedFrameCOP is constructed correctly", {
expect_no_error(umf_sub_j <- umf[, 1:2])
expect_no_error(umf_sub_ij <- umf[1:3, 1:2])
- # unmarkedFrameCOP organisation ----------------------------------------------
- expect_true(inherits(umf, "unmarkedFrameCOP"))
+ # unmarkedFrameOccuCOP organisation ----------------------------------------------
+ expect_true(inherits(umf, "unmarkedFrameOccuCOP"))
expect_equivalent(numSites(umf_sub_i), 3)
expect_equivalent(obsNum(umf_sub_j), 2)
expect_equivalent(numSites(umf_sub_ij), 3)
expect_equivalent(obsNum(umf_sub_ij), 2)
- # unmarkedFrameCOP display ---------------------------------------------------
+ # unmarkedFrameOccuCOP display ---------------------------------------------------
# print method
expect_output(print(umf), "Data frame representation of unmarkedFrame object")
@@ -97,29 +97,29 @@ test_that("unmarkedFrameCOP is constructed correctly", {
expect_output(print(umf[,1]), "Data frame representation of unmarkedFrame object")
expect_output(print(umf[1,1]), "Data frame representation of unmarkedFrame object")
- # summary method for unmarkedFrameCOP
- expect_output(summary(umf), "unmarkedFrameCOP Object")
- expect_output(summary(umf_sub_ij), "unmarkedFrameCOP Object")
+ # summary method for unmarkedFrameOccuCOP
+ expect_output(summary(umf), "unmarkedFrameOccuCOP Object")
+ expect_output(summary(umf_sub_ij), "unmarkedFrameOccuCOP Object")
- # plot method for unmarkedFrameCOP
+ # plot method for unmarkedFrameOccuCOP
expect_no_error(plot(umf))
expect_no_error(plot(umf_sub_ij))
# Input handling: covariates -------------------------------------------------
- expect_no_error(umfCovs <- unmarkedFrameCOP(
+ expect_no_error(umfCovs <- unmarkedFrameOccuCOP(
y = y,
L = L,
siteCovs = psiCovs,
obsCovs = lambdaCovs
))
expect_output(print(umfCovs), "Data frame representation of unmarkedFrame object")
- expect_output(summary(umfCovs), "unmarkedFrameCOP Object")
+ expect_output(summary(umfCovs), "unmarkedFrameOccuCOP Object")
expect_no_error(plot(umfCovs))
# Input handling: NA ---------------------------------------------------------
- # NA should not pose problems when creating the unmarkedFrameCOP object.
+ # NA should not pose problems when creating the unmarkedFrameOccuCOP object.
# The warnings and potential errors will be displayed when fitting the model.
# Except when y only contains NA: then there's an error.
@@ -128,9 +128,9 @@ test_that("unmarkedFrameCOP is constructed correctly", {
yNA[1:2,] <- NA
yNA[3:5, 3:4] <- NA
yNA[,3] <- NA
- expect_no_error(umfNA <- unmarkedFrameCOP(y = yNA, L = L))
+ expect_no_error(umfNA <- unmarkedFrameOccuCOP(y = yNA, L = L))
expect_output(print(umfNA), "Data frame representation of unmarkedFrame object")
- expect_output(summary(umfNA), "unmarkedFrameCOP Object")
+ expect_output(summary(umfNA), "unmarkedFrameOccuCOP Object")
expect_no_error(plot(umfNA))
## NA in L
@@ -138,9 +138,9 @@ test_that("unmarkedFrameCOP is constructed correctly", {
obsLengthNA[1:2,] <- NA
obsLengthNA[3:5, 3:4] <- NA
obsLengthNA[,5] <- NA
- expect_no_error(umfNA <- unmarkedFrameCOP(y = y, L = obsLengthNA))
+ expect_no_error(umfNA <- unmarkedFrameOccuCOP(y = y, L = obsLengthNA))
expect_output(print(umfNA), "Data frame representation of unmarkedFrame object")
- expect_output(summary(umfNA), "unmarkedFrameCOP Object")
+ expect_output(summary(umfNA), "unmarkedFrameOccuCOP Object")
expect_no_error(plot(umfNA))
@@ -153,33 +153,33 @@ test_that("unmarkedFrameCOP is constructed correctly", {
lambdaCovsNA[[1]][1:5,] <- NA
lambdaCovsNA[[1]][,3] <- NA
lambdaCovsNA[[3]][,5] <- NA
- expect_no_error(umfCovsNA <- unmarkedFrameCOP(
+ expect_no_error(umfCovsNA <- unmarkedFrameOccuCOP(
y = yNA,
L = obsLengthNA,
siteCovs = psiCovsNA,
obsCovs = lambdaCovsNA
))
expect_output(print(umfCovsNA), "Data frame representation of unmarkedFrame object")
- expect_output(summary(umfCovsNA), "unmarkedFrameCOP Object")
+ expect_output(summary(umfCovsNA), "unmarkedFrameOccuCOP Object")
expect_no_error(plot(umfCovsNA))
## all NA in y
yallNA <- y
yallNA[1:M, 1:J] <- NA
- expect_error(unmarkedFrameCOP(y = yallNA, L = L))
+ expect_error(unmarkedFrameOccuCOP(y = yallNA, L = L))
# Input handling: error and warnings -----------------------------------------
# Error when there are decimals in y
y_with_decimals = y
y_with_decimals[1, 1] = .5
- expect_error(unmarkedFrameCOP(y = y_with_decimals, L = L))
+ expect_error(unmarkedFrameOccuCOP(y = y_with_decimals, L = L))
# Warning if y is detection/non-detection instead of count
y_detec_nodetec = (y > 0) * 1
- expect_warning(unmarkedFrameCOP(y = y_detec_nodetec, L = L))
+ expect_warning(unmarkedFrameOccuCOP(y = y_detec_nodetec, L = L))
# Error if the dimension of L is different than that of y
- expect_error(unmarkedFrameCOP(y = y, L = L[1:2, 1:2]))
+ expect_error(unmarkedFrameOccuCOP(y = y, L = L[1:2, 1:2]))
})
@@ -195,7 +195,7 @@ test_that("occuCOP can fit simple models", {
L = y * 0 + 1
# Create umf
- umf <- unmarkedFrameCOP(y = y, L = L)
+ umf <- unmarkedFrameOccuCOP(y = y, L = L)
# Fitting options ----
@@ -274,7 +274,7 @@ test_that("occuCOP can fit simple models", {
## psi = 0.50, lambda = 1 ----
psi_test = .5
lambda_test = 1
- fit_accur <- occuCOP(data = unmarkedFrameCOP(
+ fit_accur <- occuCOP(data = unmarkedFrameOccuCOP(
y = COPsimul(
psi = psi_test,
lambda = lambda_test,
@@ -299,7 +299,7 @@ test_that("occuCOP can fit simple models", {
## psi = 0.25, lambda = 5 ----
psi_test = 0.25
lambda_test = 5
- fit_accur <- occuCOP(data = unmarkedFrameCOP(
+ fit_accur <- occuCOP(data = unmarkedFrameOccuCOP(
y = COPsimul(
psi = psi_test,
lambda = lambda_test,
@@ -324,7 +324,7 @@ test_that("occuCOP can fit simple models", {
## psi = 0.75, lambda = 0.5 ----
psi_test = 0.75
lambda_test = 0.5
- fit_accur <- occuCOP(data = unmarkedFrameCOP(
+ fit_accur <- occuCOP(data = unmarkedFrameOccuCOP(
y = COPsimul(
psi = psi_test,
lambda = lambda_test,
@@ -352,7 +352,7 @@ test_that("occuCOP can fit simple models", {
yNA[3, 1] <- NA
yNA[4, 3] <- NA
yNA[, 5] <- NA
- expect_no_error(umfNA <- unmarkedFrameCOP(y = yNA, L = L))
+ expect_no_error(umfNA <- unmarkedFrameOccuCOP(y = yNA, L = L))
expect_warning(fit_NA <- occuCOP(data = umfNA, psistarts = 0, lambdastarts = 0, L1=T))
expect_error(occuCOP(data = umfNA, psistarts = 0, lambdastarts = 0, na.rm = F))
diff --git a/vignettes/contributing_to_unmarked.Rmd b/vignettes/contributing_to_unmarked.Rmd
index e9f7ec6..e9802a4 100644
--- a/vignettes/contributing_to_unmarked.Rmd
+++ b/vignettes/contributing_to_unmarked.Rmd
@@ -101,7 +101,7 @@ Here are methods that you should test but probably will not have to rewrite. The
You may also need to add specific methods to allow users to access an attribute you added to your `unmarkedFrame` subclass.
-- For example, `getL` for `unmarkedFrameCOP`
+- For example, `getL` for `unmarkedFrameOccuCOP`
# Fitting the model