Title: | Size Biased Distributions |
---|---|
Description: | Fitting and plotting parametric or non-parametric size-biased non-negative distributions, with optional covariates if parametric. Rowcliffe, M. et al. (2016) <doi:10.1002/rse2.17>. |
Authors: | Marcus Rowcliffe [aut, cre] |
Maintainer: | Marcus Rowcliffe <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-10-25 04:46:42 UTC |
Source: | https://github.com/marcusrowcliffe/sbd |
Extracts the Akaike Information Criterion from a fitted parametric size biased distribution model.
## S3 method for class 'sbm' AIC(object, ..., k = 2)
## S3 method for class 'sbm' AIC(object, ..., k = 2)
object |
A size biased distribution model of class |
... |
Optional additional |
k |
Numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC. |
A dataframe of AIC values, NA if the model is non-parametric
(i.e. fitted with pdf = "none"
).
data(BCI_speed_data) lmod_null <- sbm(speed~1, BCI_speed_data, pdf="lnorm") lmod_mass <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") AIC(lmod_null, lmod_mass)
data(BCI_speed_data) lmod_null <- sbm(speed~1, BCI_speed_data, pdf="lnorm") lmod_mass <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") AIC(lmod_null, lmod_mass)
A set of animal speed observations recorded by camera traps on Barro Colorado Island, Panama (Rowcliffe et al. 2016).
A dataframe with 2158 rows and 3 variables:
character species common names
numeric travel speed observations, unit metres per second
numeric species average bodey mas, unit kg
https://zslpublications.onlinelibrary.wiley.com/doi/full/10.1002/rse2.17
Rowcliffe, J.M., Jansen, P.A., Kays, R., Kranstauber, B., and Carbone, C. (2016). Wildlife speed cameras: measuring animal travel speed and day range using camera traps. Remote Sensing in Ecology and Conservation 2, 84-94.
Calculates size biased gamma probability density - the underlying gamma probability density when the likelihood of recording an observation is proportional to its value.
dsbgamma(x, lmean, lrate, log = FALSE, xlog = FALSE)
dsbgamma(x, lmean, lrate, log = FALSE, xlog = FALSE)
x |
A vector of positive numbers. |
lmean |
The mean of the distribution on the log scale. |
lrate |
The log rate parameter of the underlying gamma distribution. |
log |
A logical indicating whether to return log densities. |
xlog |
A logical indicating whether to return densities for log transformed data. |
A vector of probability densities.
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsbgamma(agoutiData$speed, 0, 0.1)
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsbgamma(agoutiData$speed, 0, 0.1)
Calculates size biased log-normal probability density - the underlying log-normal probability density when the likelihood of recording an observation is proportional to its value.
dsblnorm(x, lmean, lsig, log = FALSE, xlog = FALSE)
dsblnorm(x, lmean, lsig, log = FALSE, xlog = FALSE)
x |
A vector of positive numbers. |
lmean |
The mean of the distribution on the log scale. |
lsig |
The standard deviation of the distribution on the log scale. |
log |
A logical indicating whether to return log densities. |
xlog |
A logical indicating whether to return densities for log transformed data. |
A vector of probability densities.
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsblnorm(agoutiData$speed, 0, 0.1)
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsblnorm(agoutiData$speed, 0, 0.1)
Calculates size biased Weibull probability density - the underlying Weibull probability density when the likelihood of recording an observation is proportional to its value.
dsbweibull(x, lmean, lshape, log = FALSE, xlog = FALSE)
dsbweibull(x, lmean, lshape, log = FALSE, xlog = FALSE)
x |
A vector of positive numbers. |
lmean |
The mean of the distribution on the log scale. |
lshape |
The log shape parameter of the underlying Weibull distribution. |
log |
A logical indicating whether to return log densities. |
xlog |
A logical indicating whether to return densities for log transformed data. |
A vector of probability densities.
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsbweibull(agoutiData$speed, 0, 0.1)
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") dsbweibull(agoutiData$speed, 0, 0.1)
Plots the frequency histogram of data from a size biased model, with fitted parametric distribution line if the model is parametric without covariates.
## S3 method for class 'sbm' hist(x, log = TRUE, add = FALSE, breaks = 20, lpar = list(col = "red"), ...)
## S3 method for class 'sbm' hist(x, log = TRUE, add = FALSE, breaks = 20, lpar = list(col = "red"), ...)
x |
A size biased model fit of class |
log |
A logical specifying whether to plot the log transformed or untransformed data distribution. |
add |
A logical specifying whether to create a new plot, or add a parametric distribution curve to an existing plot. |
breaks |
Integer defining number of breaks when generating histogram
(passed to |
lpar |
A list of plotting parameters controlling appearance of the
density curve line (if present - passed to |
... |
Additional parameters passed to |
None.
# Fit and plot log-normal and Weibull models data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") lmod <- sbm(speed~1, agoutiData, pdf="lnorm") wmod <- sbm(speed~1, agoutiData, pdf="weibull") hist(lmod, breaks = 40) hist(wmod, add=TRUE, lpar=list(col="blue"))
# Fit and plot log-normal and Weibull models data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") lmod <- sbm(speed~1, agoutiData, pdf="lnorm") wmod <- sbm(speed~1, agoutiData, pdf="weibull") hist(lmod, breaks = 40) hist(wmod, add=TRUE, lpar=list(col="blue"))
Calculates harmonic mean and its standard error.
hmean(x, na.rm = TRUE)
hmean(x, na.rm = TRUE)
x |
A vector of positive numbers. |
na.rm |
A logical ( |
A list with values mean
and se
.
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") hmean(agoutiData$speed)
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") hmean(agoutiData$speed)
Creates or converts a dataframe of covariates to pass to
predict.sbm
, based on the data
used in the model to be
used for prediction.
make_newdata(formula, data, newdata = NULL)
make_newdata(formula, data, newdata = NULL)
formula |
A two-sided formula of the form
|
data |
A dataframe containing the fields named in formula. |
newdata |
A dataframe of covariate values with fields matching variables
in |
When newdata
is missing, a new dataframe is created with
numeric variables held at their mean values, and all combinations of factors.
When a newdata
dataframe is provided it is checked for compatibility
with formula
variables, and character variables are converted to factors,
but otherwise passed unchanged.
A dataframe of covariate values.
data(BCI_speed_data) make_newdata(speed ~ species, BCI_speed_data)
data(BCI_speed_data) make_newdata(speed ~ species, BCI_speed_data)
Generates predicted underlying averages from a size biased model, given a set of covariates if these are used in the model.
## S3 method for class 'sbm' predict(object, newdata = NULL, reps = 999, ...)
## S3 method for class 'sbm' predict(object, newdata = NULL, reps = 999, ...)
object |
A size biased model fit of class |
newdata |
A dataframe of covariate values with fields matching
covariates used in |
reps |
Integer giving the number of random draws for variance estimation. |
... |
Additional arguments (unused). |
When newdata
is missing, make_table
is used to
generate a dataframe of covariates at which to predict, based on the
model formula and covariate data.
A dataframe of predictions with fields est
(estimated average),
se
(estimated standard error), and lcl
, ucl
(lower and
upper 95 percent confidence limits).
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") lmod_mass <- sbm(speed~mass, agoutiData, pdf="lnorm") nd <- data.frame(mass = c(1, 10, 100)) predict(lmod_mass, nd)
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") lmod_mass <- sbm(speed~mass, agoutiData, pdf="lnorm") nd <- data.frame(mass = c(1, 10, 100)) predict(lmod_mass, nd)
Fitting and plotting parametric or non-parametric size-biased non-negative distributions, with optional covariates in the case of parametric. Supports three parametric options, log-normal, Weibull, and gamma.
The core function is sbm
, which fits a model to
non-negative observations to estimate the average of the underlying
distribution assuming that the probability of making an observation is
proportional to the size of that observation. The default gives a
non-parametric fit (the harmonic mean), and three parametric options are
also available: log-normal, Weibull, and gamma. Covariates can be included
in parametric models. The output is a list of class sbm
, which has
methods plot
, predict
, summary
, and AIC
. The
functions were developed to support the analysis of speed observations from
camera trap data described by Rowcliffe et al. (2016).
Maintainer: Marcus Rowcliffe [email protected]
Patil, G. P. 2002 Weighted distributions. Pp. 2369–2377 in A.H. El-Shaarawi, W. W. Piegorsch, eds. Encycolpedia of Environmetrics. Wiley, Chichester.
Rowcliffe, J.M., Jansen, P.A., Kays, R., Kranstauber, B., and Carbone, C. (2016). Wildlife speed cameras: measuring animal travel speed and day range using camera traps. Remote Sensing in Ecology and Conservation 2, 84-94.
Useful links:
Fits a parametric or non-parametric size biased distribution model to a positive response variable.
sbm( formula, data, pdf = c("none", "lnorm", "gamma", "weibull"), var.range = c(-4, 4), trace = FALSE, ... )
sbm( formula, data, pdf = c("none", "lnorm", "gamma", "weibull"), var.range = c(-4, 4), trace = FALSE, ... )
formula |
A two-sided formula of the form response ~ covariate + ... |
data |
A dataframe containing the fields named in formula. |
pdf |
A text value naming the probability density function to use. |
var.range |
The range of log variance within which to search when fitting parametric distributions. |
trace |
Logical defining whether to show diagnostic information when
fitting parametric distributions (passed to |
... |
Arguments passed to |
Response values must be strictly positive. To fit a distribution without covariates use 1 on the right hand side of the formula. When pdf = "none", the harmonic mean and it's standard error are calculated, and no covariates can be used.
The contents of the the estimate
component of the result depends
on the type of model. When no covariates are used, it contains a single
overall average estimate. When covariates are used and newdata = NULL
,
it contains one estimate per unique combination of factor covariate levels,
with any quantitative covariates held at their mean values. When covariates
are used and a dataframe with valid covariate fields is supplied to
newdata
, it replicates newdata
appending averages estimated at
the covariate values supplied.
A list of class sbm
with methods summary.sbm
,
predict.sbm
, hist.sbm
, and
AIC.sbm
. The list has elements:
"estimate" |
A dataframe of estimated averages, their standard errors and 95% confidence limits. |
"data" |
A dataframe containing the data used to fit the model. |
"model" |
A model object of class |
"formula" |
The formula supplied to the function call. |
"pdf" |
Character string recording the probability density function used to fit the model. |
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") # harmonic mean estimate for agouti hmod <- sbm(speed~1, agoutiData) # lognormal estimate with or without a covariates lmod <- sbm(speed~1, agoutiData, pdf="lnorm") lmod_mass <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") lmod_spp <- sbm(speed~species, BCI_speed_data, pdf="lnorm") # inspect estimates hmod$estimate lmod$estimate lmod_mass$estimate lmod_spp$estimate
data(BCI_speed_data) agoutiData <- subset(BCI_speed_data, species=="agouti") # harmonic mean estimate for agouti hmod <- sbm(speed~1, agoutiData) # lognormal estimate with or without a covariates lmod <- sbm(speed~1, agoutiData, pdf="lnorm") lmod_mass <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") lmod_spp <- sbm(speed~species, BCI_speed_data, pdf="lnorm") # inspect estimates hmod$estimate lmod$estimate lmod_mass$estimate lmod_spp$estimate
For parametric models only, summarises the linear model coefficients from a
an sbm
object.
## S3 method for class 'sbm' summary(object, ...)
## S3 method for class 'sbm' summary(object, ...)
object |
A size biased model fit of class |
... |
Additional arguments (unused). |
A dataframe with fields estimate
, stdError
,
tValue
, and pValue
.
data(BCI_speed_data) mod <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") summary(mod)
data(BCI_speed_data) mod <- sbm(speed~mass, BCI_speed_data, pdf="lnorm") summary(mod)