From e240238b102407f53497114906c4b1fe6e990999 Mon Sep 17 00:00:00 2001 From: colin millar Date: Mon, 1 Aug 2016 16:00:22 +0200 Subject: [PATCH] help files and import fixes for overdispersion functions --- NAMESPACE | 3 + ...erdispersion_function_annotated_complete.R | 86 ++++++++----------- R/Package.R | 1 + man/BICadj.Rd | 28 ++++++ man/overdispersion.Rd | 41 +++++++++ 5 files changed, 110 insertions(+), 49 deletions(-) create mode 100644 man/BICadj.Rd create mode 100644 man/overdispersion.Rd diff --git a/NAMESPACE b/NAMESPACE index 8a0314b..5e339de 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ importFrom(mgcv,gam) importFrom(mgcv,smooth.construct) importFrom(rstan,optimizing) importFrom(stats,AIC) +importFrom(stats,aggregate) importFrom(stats,as.formula) importFrom(stats,binomial) importFrom(stats,deviance) @@ -30,6 +31,8 @@ importFrom(stats,drop.scope) importFrom(stats,fitted) importFrom(stats,formula) importFrom(stats,model.matrix) +importFrom(stats,pchisq) +importFrom(stats,qlogis) importFrom(stats,simulate) importFrom(stats,update.formula) importFrom(utils,capture.output) diff --git a/R/Overdispersion_function_annotated_complete.R b/R/Overdispersion_function_annotated_complete.R index c0937be..7818cc7 100644 --- a/R/Overdispersion_function_annotated_complete.R +++ b/R/Overdispersion_function_annotated_complete.R @@ -1,35 +1,25 @@ -########################################### -# -# ESTIMATING OVERDISPERSION -# -########################################### - -# Complete function for returning overdispersion estimates - - -# DEPENDENCIES -# ef -# dplyr - - -# NOTE - ensure column names in function call are in inverted -# commas - - -# REQUIRED FIELDS: -# data = dataframe containing EF data -# siteID = site name or unique ID -# visitID = a number identifying each unique visit -# count = count of fish (defaults to "count") -# pass = the EF pass number(defaults to "pass") -# pass12 = categorical variable with 2 levels where the 1st pass -# and subsequent passes are treated separately (defaults to "pass12") -# id = sample ID -# largemodel = the large model that captures most of the systematic -# variation in the data - this is specified before -# running the overdispersion function - +#' Estimating overdispersion +#' +#' Complete function for returning overdispersion estimates +#' +#' +#' @param data dataframe containing EF data +#' @param siteID site name or unique ID +#' @param visitID a number identifying each unique visit +#' @param count count of fish (defaults to "count") +#' @param pass the EF pass number (defaults to "pass") +#' @param lifestage the lifestage (defaults to "lifestage") +#' @param pass12 categorical variable with 2 levels where the 1st pass +#' and subsequent passes are treated separately (defaults to "pass12") +#' @param id sample ID +#' @param largemodel the large model that captures most of the systematic +#' variation in the data - this is specified before +#' running the overdispersion function +#' @return a data.frame summarising overdispersion +#' +#' @note ensure column names in function call are in inverted commas +#' #' @export overdispersion <- function(data, siteID, visitID, count = "count", pass = "pass", lifestage = "lifestage", @@ -315,27 +305,25 @@ overdispersion <- function(data, siteID, visitID, count = "count", } -################################################################################################# -################################################################################################# -################################################################################################# -################################################################################################# -################################################################################################# -################################################################################################# -################################################################################################# -################################################################################################# -#################### -# -# ADJUSTED BIC FUNCTION -# -#################### -# When calling the function, you need to specify the data source for -# the model so that the number of site visits can be determined. -# You also need to specify the output from the overdispersion model -# to get the measure +#' Adjusted BIC function +#' +#' Complete function for returning overdispersion estimates +#' +#' +#' @param model a fitted ef model +#' @param data the data used to fit the model +#' @param overdispersion.output output form the function \link{overdispersion} +#' @return the adjusted BIC +#' +#' @note When calling the function, you need to specify the data source for +#' the model so that the number of site visits can be determined. +#' You also need to specify the output from the overdispersion model +#' to get the measure +#' #' @export -BICadj <- function(model, data, overdispersion.output){ +BICadj <- function(model, data, overdispersion.output) { # The adjusted BIC value is calculated in a similar way to BIC, however the # loglikelihood of the model is divided by the measure of between sample diff --git a/R/Package.R b/R/Package.R index 27872f4..adab616 100644 --- a/R/Package.R +++ b/R/Package.R @@ -7,6 +7,7 @@ #' @importFrom utils capture.output #' @importFrom stats simulate AIC fitted as.formula formula binomial deviance #' @importFrom stats update.formula drop.scope model.matrix +#' @importFrom stats aggregate pchisq qlogis #' @importFrom mgcv gam smooth.construct Predict.matrix #' @importFrom rstan optimizing #' @importFrom dplyr left_join diff --git a/man/BICadj.Rd b/man/BICadj.Rd new file mode 100644 index 0000000..30efbc5 --- /dev/null +++ b/man/BICadj.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Overdispersion_function_annotated_complete.R +\name{BICadj} +\alias{BICadj} +\title{Adjusted BIC function} +\usage{ +BICadj(model, data, overdispersion.output) +} +\arguments{ +\item{model}{a fitted ef model} + +\item{data}{the data used to fit the model} + +\item{overdispersion.output}{output form the function \link{overdispersion}} +} +\value{ +the adjusted BIC +} +\description{ +Complete function for returning overdispersion estimates +} +\note{ +When calling the function, you need to specify the data source for + the model so that the number of site visits can be determined. + You also need to specify the output from the overdispersion model + to get the measure +} + diff --git a/man/overdispersion.Rd b/man/overdispersion.Rd new file mode 100644 index 0000000..5ca2c1b --- /dev/null +++ b/man/overdispersion.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Overdispersion_function_annotated_complete.R +\name{overdispersion} +\alias{overdispersion} +\title{Estimating overdispersion} +\usage{ +overdispersion(data, siteID, visitID, count = "count", pass = "pass", + lifestage = "lifestage", pass12 = "pass12", id, largemodel) +} +\arguments{ +\item{data}{dataframe containing EF data} + +\item{siteID}{site name or unique ID} + +\item{visitID}{a number identifying each unique visit} + +\item{count}{count of fish (defaults to "count")} + +\item{pass}{the EF pass number (defaults to "pass")} + +\item{lifestage}{the lifestage (defaults to "lifestage")} + +\item{pass12}{categorical variable with 2 levels where the 1st pass +and subsequent passes are treated separately (defaults to "pass12")} + +\item{id}{sample ID} + +\item{largemodel}{the large model that captures most of the systematic + variation in the data - this is specified before +running the overdispersion function} +} +\value{ +a data.frame summarising overdispersion +} +\description{ +Complete function for returning overdispersion estimates +} +\note{ +ensure column names in function call are in inverted commas +} +