| Title: | Shiny User Interface for Multiple Source Capture Recapture Models |
|---|---|
| Description: | Implements user interfaces for log-linear models, Bayesian model averaging and Bayesian Dirichlet process mixture models. |
| Authors: | Ian E. Fellows [aut, cre] |
| Maintainer: | Ian E. Fellows <[email protected]> |
| License: | MIT + file LICENCE |
| Version: | 0.2.0 |
| Built: | 2026-09-28 07:36:17 UTC |
| Source: | https://github.com/fellstat/shinyrecap |
Implements user interfaces for log-linear models, bayesian model averaging and bayesian dirichlet process mixture models.
Ian E. Fellows [email protected]
disaggregate data
disaggregate(dat, counts)disaggregate(dat, counts)
dat |
a data.frame |
counts |
frequency counts for each row |
Convert Unique Event Identifier Event Data into Multiple Source Capture Recapture Histories
extract_histories(datasets, count_name, cov_names = c())extract_histories(datasets, count_name, cov_names = c())
datasets |
An ordered list of capture event datasets. The first j-1 columns of the jth dataset should be a 0 or 1 indicator of beng captured in a previous event. |
count_name |
The name of the column holding the counts of the number of individuals. |
cov_names |
A character vector of column names for covariates to stratify by. |
A dataframe. The first length(datasets) columns of which contain all possible permutations of capture histories. The "__count__" column contains the number of observed cases. Other columns are the stratifying covariates.
# First sample dat1 <- data.frame( count=c(55,43), c1=c("m","f"), stringsAsFactors = FALSE ) # Second sample dat2 <- data.frame( id1=c(1,0,1,0), count=c(10,11,5,12), c1=c("m","m","f","f"), stringsAsFactors = FALSE ) # Third Sample dat3 <- data.frame( id1=c(1,0,1,0,1,0,1,0), id2=c(1,1,1,1,0,0,0,0), count=c(2,3,4,3,2,30,4,30), c1=c("m","m","f","f","m","m","f","f"), stringsAsFactors = FALSE ) # Fourth Sample dat4 <- data.frame( id1=c(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0), id2=c(1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0), id3=c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0), count=c(1,1,1,1,0,1,0,0,1,1,1,1,1,0,1,10), c1=c("m","m","f","f","m","m","f","f","m","m","f","f","m","m","f","f"), stringsAsFactors = FALSE ) # Combine 4 capture recatpure events together datasets <- list(dat1,dat2,dat3,dat4) # Get four sample capture recapture histories from unique event observations extract_histories(datasets, "count") # Stratify by a covariate extract_histories(datasets, "count", cov_names="c1") # Two sample capture recapture extract_histories(datasets[1:2], "count", cov_names="c1")# First sample dat1 <- data.frame( count=c(55,43), c1=c("m","f"), stringsAsFactors = FALSE ) # Second sample dat2 <- data.frame( id1=c(1,0,1,0), count=c(10,11,5,12), c1=c("m","m","f","f"), stringsAsFactors = FALSE ) # Third Sample dat3 <- data.frame( id1=c(1,0,1,0,1,0,1,0), id2=c(1,1,1,1,0,0,0,0), count=c(2,3,4,3,2,30,4,30), c1=c("m","m","f","f","m","m","f","f"), stringsAsFactors = FALSE ) # Fourth Sample dat4 <- data.frame( id1=c(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0), id2=c(1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0), id3=c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0), count=c(1,1,1,1,0,1,0,0,1,1,1,1,1,0,1,10), c1=c("m","m","f","f","m","m","f","f","m","m","f","f","m","m","f","f"), stringsAsFactors = FALSE ) # Combine 4 capture recatpure events together datasets <- list(dat1,dat2,dat3,dat4) # Get four sample capture recapture histories from unique event observations extract_histories(datasets, "count") # Stratify by a covariate extract_histories(datasets, "count", cov_names="c1") # Two sample capture recapture extract_histories(datasets[1:2], "count", cov_names="c1")
Format graphs
formatGraphs(graphs)formatGraphs(graphs)
graphs |
the graphs |
Launches the Shiny Application for Population Size
launchShinyPopSize(app = c("estimation", "power", "convert"))launchShinyPopSize(app = c("estimation", "power", "convert"))
app |
Which application to launch. |
The manual for this shiny application is located at https://fellstat.github.io/shinyrecap/
Perform LCMCR sampling with a monitor function
lcmcrSample( object, burnin = 10000, samples = 1000, thinning = 10, clear_buffer = FALSE, output = TRUE, nMonitorBreaks = 100, monitorFunc = function(subs, tot) { } )lcmcrSample( object, burnin = 10000, samples = 1000, thinning = 10, clear_buffer = FALSE, output = TRUE, nMonitorBreaks = 100, monitorFunc = function(subs, tot) { } )
object |
the samples |
burnin |
MCMC burn in |
samples |
number of samples |
thinning |
MCMC thinning |
clear_buffer |
buffer clear buffer of object |
output |
output progress |
nMonitorBreaks |
number of times to call the monitor function |
monitorFunc |
A function called nMonitorBreaks times taking the number of samples to be taken, and the total samples |
An edited version of lcmCR_PostSampl
Simulate Capture Re-capture with heterogeneity
simulateCapture(hetero, p)simulateCapture(hetero, p)
hetero |
The heterogineity |
p |
A vector of capture event probabilities |
het <- simulateHeteroNormal(1000, 1.1) cap <- simulateCapture(het, p = c(.05,.1,.05,.1)) summary(cap)het <- simulateHeteroNormal(1000, 1.1) cap <- simulateCapture(het, p = c(.05,.1,.05,.1)) summary(cap)
Simulates capture re-capture estimates
simulateEstimates( nsim, N, p, htype = "None", heteroPerc = 1, monitorFunc = function(i) { } )simulateEstimates( nsim, N, p, htype = "None", heteroPerc = 1, monitorFunc = function(i) { } )
nsim |
number of simulations |
N |
Population size |
p |
A vector of capture event probabilities |
htype |
The type of capture heterogeneity. Either "None" or "Normal" |
heteroPerc |
The increase in odds of capture for the perc 90th percentile most likely to be captured individuals, compared to the average individual. |
monitorFunc |
A function called after every iteration. Useful for monitoring simulation progress. |
library(ggplot2) # Simulate estimates from the Mt model with no population heterogeneity ests <- simulateEstimates(15,500,c(.1,.1,.1)) # Simulate estimates from the Mth (Normal) model with no population heterogeneity. ests2 <- simulateEstimates(20,500,c(.1,.1,.1), htype="Normal") df <- data.frame(est = ests[[1]],type="Mt") df <- rbind(df, data.frame(est = ests2[[1]],type="Mth (Normal)")) qplot(x=est, color=type, data=df, geom="density") + geom_vline(xintercept=500,color="purple")library(ggplot2) # Simulate estimates from the Mt model with no population heterogeneity ests <- simulateEstimates(15,500,c(.1,.1,.1)) # Simulate estimates from the Mth (Normal) model with no population heterogeneity. ests2 <- simulateEstimates(20,500,c(.1,.1,.1), htype="Normal") df <- data.frame(est = ests[[1]],type="Mt") df <- rbind(df, data.frame(est = ests2[[1]],type="Mth (Normal)")) qplot(x=est, color=type, data=df, geom="density") + geom_vline(xintercept=500,color="purple")
simulate capture heterogineity
simulateHeteroNormal(N, heteroPerc = 1, perc = 0.9)simulateHeteroNormal(N, heteroPerc = 1, perc = 0.9)
N |
Population size |
heteroPerc |
The increase in odds of capture for the perc 90th percentile most likely to be captured individuals, compared to the average individual. |
perc |
The percentile to use. |
het <- simulateHeteroNormal(100, 1.1) hist(het)het <- simulateHeteroNormal(100, 1.1) hist(het)
A simple wrapper for shinyhelper::helper
srhelp(x, content, ...)srhelp(x, content, ...)
x |
The shiny object to decorate |
content |
the name of the help |
... |
additional parameters for shinyhelper::helper |