Skip to content

Commit

Permalink
version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusRowcliffe authored and gaborcsardi committed Sep 24, 2014
0 parents commit 07f050d
Show file tree
Hide file tree
Showing 24 changed files with 1,244 additions and 0 deletions.
19 changes: 19 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,19 @@
Package: activity
Title: Animal Activity Statistics
Version: 1.0
Date: 24/09/14
Author: Marcus Rowcliffe <marcus.rowcliffe@ioz.ac.uk>
Maintainer: Marcus Rowcliffe <marcus.rowcliffe@ioz.ac.uk>
Description: Provides functions to fit kernel density functions
to animal activity time data; plot activity distributions;
quantify overall levels of activity; statistically compare
activity metrics through bootstrapping; and evaluate variation
in linear variables with time (or other circular variables).
License: GPL-3
Depends: methods
Imports: circular, overlap, pbapply,
LazyData: true
Packaged: 2014-09-29 11:45:26 UTC; Rowcliffe.M
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2014-09-29 15:07:49
23 changes: 23 additions & 0 deletions MD5
@@ -0,0 +1,23 @@
40d5c94cd23318fbc87363e9427948a4 *DESCRIPTION
ef021064efc487f78f03bb169b1300c1 *NAMESPACE
9881a88260b37f46bf4eeaa7b54e5c06 *R/activity_code_1_0.r
601e4a0baf81c965b52eb2e420cccb89 *data/BCIspeed.rda
49d79fe17bc56762619f55a6e1c816b4 *data/BCItime.rda
23632c686b04f65b3ba0659438da72a7 *man/BCIspeed.Rd
8fece5a6347740d2ecf6d966d0efcf32 *man/BCItime.Rd
a3dd1b2211bbc46719fa788b272b76e2 *man/activity.Rd
58d4673d7ce89189bb6e69e77fee9005 *man/actmod-class.Rd
304bc226410f90c967ab24c7a449be28 *man/bwcalc.Rd
f592de34919415c25d9920a99f1e4a90 *man/compareAct.Rd
3f3b60002d9aa10159d68b374b084447 *man/compareCkern.Rd
bc7fa8d593ba975d1a741a4700c95537 *man/compareTimes.Rd
75b5390376081367007caa40d435c9cc *man/dvmkern.Rd
6639983acd43198d41df0db7c56e5954 *man/fitact.Rd
ea28e8ce8baaedf3289b8d119b260a36 *man/fitlincirc.Rd
aaaa3c2ea93d87e3aebcdba05e353d8e *man/lincircKern.Rd
bc022cf334bbf0ba9132df0f2f642c39 *man/lincircmod-class.Rd
781f1857cc84dbdc36980de91531587a *man/plot-actmod-methods.Rd
d0fa61437f96b9b9037bc7321524a65b *man/plot-lincircmod-methods.Rd
fc1842da36cded4a114cbe9914732bdc *man/rvmkern.Rd
3f03c2cb21ce9a19344f34bbdf17adc3 *man/show-actmod-method.Rd
7d774b6e9850cfd963d56d0bf37698be *man/yfromx.Rd
15 changes: 15 additions & 0 deletions NAMESPACE
@@ -0,0 +1,15 @@
import(methods)
export(bwcalc)
export(compareAct)
export(compareCkern)
export(compareTimes)
export(dvmkern)
export(fitact)
export(fitlincirc)
export(lincircKern)
export(rvmkern)
export(yfromx)
exportClasses(actmod)
exportClasses(lincircmod)
exportMethods(plot)
exportMethods(show)
622 changes: 622 additions & 0 deletions R/activity_code_1_0.r

Large diffs are not rendered by default.

Binary file added data/BCIspeed.rda
Binary file not shown.
Binary file added data/BCItime.rda
Binary file not shown.
15 changes: 15 additions & 0 deletions man/BCIspeed.Rd
@@ -0,0 +1,15 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\docType{data}
\name{BCIspeed}
\alias{BCIspeed}
\title{Animal speed data}
\format{A dataframe with 2204 observations and 3 variables.}
\source{
http://dx.doi.org/10.6084/m9.figshare.1160536
}
\description{
Barro Colorado Island 2008 data: speeds of animal passages past camera traps
(\code{speed}), together with species (\code{species}) and time of day (\code{time})
for each record.
}

14 changes: 14 additions & 0 deletions man/BCItime.Rd
@@ -0,0 +1,14 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\docType{data}
\name{BCItime}
\alias{BCItime}
\title{Animal record time of day data}
\format{A dataframe with 17820 observations and 2 variables.}
\source{
http://dx.doi.org/10.6084/m9.figshare.1160536
}
\description{
Barro Colorado Island 2008 data: times of day at which animal records occured
(\code{time}), together with species (\code{species}).
}

32 changes: 32 additions & 0 deletions man/activity.Rd
@@ -0,0 +1,32 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\docType{package}
\name{activity}
\alias{activity}
\alias{activity-package}
\title{Animal activity statistics}
\description{
Provides functions to estimate and compare activity parameters from sensor data.
}
\details{
Sensors that record active animals (eg camera traps) build up a record of
the distribution of activity over the course of the day. Records are more frequent
when animals are more active, and less frequent or absent when animals are inactive.
The area under the distribution of records thus contains information on the overall
level of activity in a sampled population. This package provides tools for plotting
activity distributions, quantifying the overall level of activity with error, and
statistically comparing distributions through bootstrapping.

The core function is \code{fitact}, which creates an \code{actmod} object containing
the circular kernel PDF, and the activity level estimate derived from this. The
generic plot function for \code{actmod} objects plots the distribution. Functions
starting with \code{compare} make statistical comparisons between distributions or
activity estimates. Note that all time or other circular data should be in radians
(in the range 0 to 2*pi).
}
\references{
Rowcliffe, M., Kays, R., Kranstauber, B., Carbone, C., Jansen, P.A. (2014) Quantifying animal activity level using camera trap data. Methods in Ecology and Evolution.
}
\seealso{
\code{\link{overlap}}
}

29 changes: 29 additions & 0 deletions man/actmod-class.Rd
@@ -0,0 +1,29 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\docType{class}
\name{actmod-class}
\alias{actmod-class}
\title{Activity model class.}
\description{
An S4 class describing activity models fitted to time of observation data.
}
\section{Slots}{

\describe{
\item{\code{data}}{Object of class \code{"numeric"}, the input data.}

\item{\code{wt}}{Object of class \code{"numeric"}, weights applied to the data.}

\item{\code{bw}}{Object of class \code{"numeric"}, kernel bandwidth.}

\item{\code{adj}}{Object of class \code{"numeric"}, kernel bandwidth adjustment multiplier.}

\item{\code{pdf}}{Object of class \code{"matrix"} describing fitted probability density function:
Column 1: Sequence of radian times at which PDF evaluated (specifically seq(0,2*pi,pi/256)).
Column 2: Corresponding circular kernel PDF values.
Additionally if errors boostrapped:
Column 3: PDF standard error.
Column 4: PDF lower confidence interval. Column 5: PDF upper confidence interval.}

\item{\code{act}}{Object of class \code{"numeric"} giving activity level estimate and, if errors boostrapped, standard error and 95 percent confidence limits.}
}}

25 changes: 25 additions & 0 deletions man/bwcalc.Rd
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{bwcalc}
\alias{bwcalc}
\title{Calculate circular kernel bandwidth.}
\usage{
bwcalc(dat, K = 3)
}
\arguments{
\item{dat}{Numeric data vector of radian times.}

\item{K}{Integer number of values of kappa over which to maximise (see references for details).}
}
\value{
Single numeric bandwidth value.
}
\description{
Uses an optimisation procedure to calculate the circular kernel bandwidth giving the best fit to the data.
}
\details{
Mainly for internal use.
}
\references{
Ridout, M.S. & Linkie, M. (2009) Estimating overlap of daily activity patterns from camera trap data. Journal of Agricultural Biological and Environmental Statistics, 14, 322-337.
}

32 changes: 32 additions & 0 deletions man/compareAct.Rd
@@ -0,0 +1,32 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{compareAct}
\alias{compareAct}
\title{Compare activity level estimates}
\usage{
compareAct(fits)
}
\arguments{
\item{fits}{A list of fitted \code{actmod} objects}
}
\value{
A matrix with 4 columns: 1. differences between estimates; 2. SEs of the differences; 3. Wald statistics; 4. p-values (H0 is no difference between estimates). Matrix rows give all possible pairwise comparisons, numbered in the order in which they entered in the list \code{fits}.
}
\description{
Wald test for the statistical difference between two or more activitiy level estimates.
}
\details{
Uses a Wald test to ask whether the difference between estimates a1 and a2 is
significantly different from 0: statistic W = (a1-a2)^2 / (SE1^2+SE2^2) tested
on chi-sq distribution with 1 degree of freedom.
}
\examples{
#Test whether paca have a sigificantly different activity level from rat.
#Bootstrap reps limited to speed up example.
data(BCItime)
tPaca <- 2*pi*BCItime$time[BCItime$species=="paca"]
tRat <- 2*pi*BCItime$time[BCItime$species=="rat"]
(fPaca <- fitact(tPaca, reps=10))
(fRat <- fitact(tRat, reps=10))
compareAct(list(fPaca,fRat))
}

35 changes: 35 additions & 0 deletions man/compareCkern.Rd
@@ -0,0 +1,35 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{compareCkern}
\alias{compareCkern}
\title{Compare circular distributions.}
\usage{
compareCkern(y1, y2, reps = 1000)
}
\arguments{
\item{y1,y2}{Numeric vectors of radian data.}

\item{reps}{Number of bootstrap iterations.}
}
\value{
A named 2-element vector: Overlap = observed overlap index; p = probability observed index arose by chance.
}
\description{
Test probability that two sets of circular observations come from the same distribution.
}
\details{
Bootstrap test calculates overlap index 2 (see references) for the observed data samples, then generates a null distribution of overlap indices using data sampled randomly with replacement from the combined data. This randomised distribution is then used to estimate the probability that the observed overlap arose by chance.
}
\examples{
#Example with bootstrap reps limited to speed up
data(BCItime)
tPaca <- 2*pi*BCItime$time[BCItime$species=="paca"]
tRat <- 2*pi*BCItime$time[BCItime$species=="rat"]
compareCkern(tPaca,tRat,reps=10)
}
\references{
Ridout, M.S. & Linkie, M. (2009) Estimating overlap of daily activity patterns from camera trap data. Journal of Agricultural Biological and Environmental Statistics, 14, 322-337.
}
\seealso{
\code{\link{overlapEst}}
}

29 changes: 29 additions & 0 deletions man/compareTimes.Rd
@@ -0,0 +1,29 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{compareTimes}
\alias{compareTimes}
\title{Compare activity across between times of day}
\usage{
compareTimes(fit, times)
}
\arguments{
\item{fit}{Fitted \code{actmod} object with errors boostrapped (fit using \code{fitact} with \code{sample} argument != "none").}

\item{times}{Numeric vector of radian times of day at which to compare activity levels. All pairwise comparisons are made.}
}
\value{
A matrix with 4 columns: 1. differences between PDF values; 2. SEs of the differences; 3. Wald statistics; 4. p-values (H0 is no difference between estimates). Matrix rows give all possible pairwise comparisons, numbered in the order in which they appear in vector \code{times}.
}
\description{
Uses a Wald test to statistically compare activity levels at given radian times of day for a fitted activity distribution.
}
\details{
Bootrapping the activity model yields standard error estimates for the PDF. This function uses these SEs to compute a Wald statistic for the difference between PDF values (by inference activity levels) at given times of day: statistic W = (a1-a2)^2 / (SE1^2+SE2^2) tested on chi-sq distribution with 1 degree of freedom.
}
\examples{
data(BCItime)
tPaca <- 2*pi*BCItime$time[BCItime$species=="paca"]
fPaca <- fitact(tPaca, reps=10)
plot(fPaca, hrs=FALSE, frq=FALSE)
compareTimes(fPaca, c(5.5,6,0.5,1))
}

38 changes: 38 additions & 0 deletions man/dvmkern.Rd
@@ -0,0 +1,38 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{dvmkern}
\alias{dvmkern}
\title{Circular kernel probability density function.}
\usage{
dvmkern(x, dat, wt = NULL, bw = NULL, adj = 1)
}
\arguments{
\item{x}{Numeric vector of radian times at which to evaluate the PDF.}

\item{dat}{Numeric vector of radian time data to which the PDF is fitted.}

\item{wt}{A numeric vector of weights for each \code{dat} value.}

\item{bw}{Numeric value for kernel bandwidth.}

\item{adj}{Numeric kernel bandwidth multiplier.}
}
\value{
Numeric vector of probability densities evaluated at \code{x}.
}
\description{
Optionally weighted Von Mises kernel probability densities.
}
\details{
If \code{bw} not provided it is calculated internally using \code{bw.calc}. The \code{adj} argument is used to adjust \code{bw} to facilitate exploration of fit flexibility.
}
\examples{
#Example with made up input
tt <- runif(100,0,2*pi)
xx <- seq(0,2*pi, pi/256)
pdf <- dvmkern(xx, tt)
plot(xx, pdf, type="l")
}
\seealso{
\code{\link{density.circular}, \link{bwcalc}}
}

63 changes: 63 additions & 0 deletions man/fitact.Rd
@@ -0,0 +1,63 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{fitact}
\alias{fitact}
\title{Fit activity model to time-of-day data}
\usage{
fitact(dat, wt = NULL, reps = 1000, bw = NULL, adj = 1,
sample = c("data", "model", "none"), show = TRUE)
}
\arguments{
\item{dat}{A numeric vector of radian time-of-day data.}

\item{wt}{A numeric vector of weights for each \code{dat} value.}

\item{reps}{Number of boostrap iterations to perform. Ignored if sample=="none".}

\item{bw}{Numeric value for kernel bandwidth. If NULL, calculated internally.}

\item{adj}{Numeric bandwidth adjustment multiplier.}

\item{sample}{Character string defining sampling method for bootstrapping errors (see details).}

\item{show}{Logical whether or not to show a progress bar while bootstrapping.}
}
\value{
An object of type \code{actmod}
}
\description{
Fits a circular kernel density to radian time-of-day data and estimates activity
level from this distribution. Optionally bootstraps the distribution, in which
case SEs and confidence limits are also stored for activity level and PDF.
}
\details{
The bandwidth adjustment multiplier \code{adj} is provided to allow
exploration of the effect of adjusting the internally calculated bandwidth on
accuracy of activity level estimates. The alternative bootstrapping methods
defined by \code{sample} are:
\code{data}: sample from the data;
\code{model}: sample from the fitted probability density distribution;
\code{none}: no bootstrapping.
Confidence interval coverage seems to be better at large sample size
(greater than 100-200) using \code{"model"}, but better at small sample size
when using \code{"data"}. The reason for this needs further investigation.
}
\examples{
#Fit without confidence limits
data(BCItime)
tdat <- 2*pi*BCItime$time[BCItime$species=="ocelot"]
mod1 <- fitact(tdat, sample="none")
plot(mod1)

#Fit with confidence limits (limited reps to speed up)
mod2 <- fitact(tdat, reps=10)
plot(mod2)

#Fit weighted function to correct for detection radius 1.21 times higher
#by day than by night, assuming day between pi/2 (6am) and pi*2/3 (6pm)
weight <- 1/ifelse(tdat>pi/2 & tdat<pi*3/2, 1.2, 1)
mod3 <- fitact(tdat, wt=weight, sample="none")
plot(mod3)
#Overplot unweighted version for comparison
plot(mod1, add=TRUE, lcol=3)
}

0 comments on commit 07f050d

Please sign in to comment.