if (FALSE) {
library(Distance)
# Need to have the readxl package installed from CRAN
require(readxl)
# Need to get the file path first
minke.filepath <- system.file("minke.xlsx", package="Distance")
# Load the Excel file, note that col_names=FALSE and we add column names after
minke <- read_xlsx(minke.filepath, col_names=FALSE)
names(minke) <- c("Region.Label", "Area", "Sample.Label", "Effort",
"distance")
# One may want to call edit(minke) or head(minke) at this point
# to examine the data format
## perform an analysis using the exact distances
pooled.exact <- ds(minke, truncation=1.5, key="hr", order=0)
summary(pooled.exact)
## Try a binned analysis
# first define the bins
dist.bins <- c(0,.214, .428,.643,.857,1.071,1.286,1.5)
pooled.binned <- ds(minke, truncation=1.5, cutpoints=dist.bins, key="hr",
order=0)
# binned with stratum as a covariate
minke$stratum <- ifelse(minke$Region.Label=="North", "N", "S")
strat.covar.binned <- ds(minke, truncation=1.5, key="hr",
formula=~as.factor(stratum), cutpoints=dist.bins)
# Stratified by North/South
full.strat.binned.North <- ds(minke[minke$Region.Label=="North",],
truncation=1.5, key="hr", order=0, cutpoints=dist.bins)
full.strat.binned.South <- ds(minke[minke$Region.Label=="South",],
truncation=1.5, key="hr", order=0, cutpoints=dist.bins)
## model summaries
model.sel.bin <- data.frame(name=c("Pooled f(0)", "Stratum covariate",
"Full stratification"),
aic=c(pooled.binned$ddf$criterion,
strat.covar.binned$ddf$criterion,
full.strat.binned.North$ddf$criterion+
full.strat.binned.South$ddf$criterion))
# Note model with stratum as covariate is most parsimonious
print(model.sel.bin)
}
Run the code above in your browser using DataLab