tmcd82070 / Rdistance

An R package for simple, regression-like, distance-based analyses
8 stars 3 forks source link

Helper function to automate fitting/comparing multiple models #62

Open jcarlis3 opened 6 years ago

jcarlis3 commented 6 years ago

The development version of the package currently has an autoDistSamp function that will use AIC(c) to compare different detection functions and run abundEstim on the highest-ranked one. This function can compare different likelihood-expansion combos (halfnorm with 0 expansions vs halfnorm with 1 expansion vs hazrate with 0 expansions vs hazrate with 1 expansion, etc.), but cannot compare different model formulas (dist ~1 vs dist ~ myCovariate). I suspect many users would like the option to compare different model formulas (models with varying covariates included). Diem wrote a wrapper function that does this (with the added perk of model-averaging estimates of p instead of assuming the highest-ranked model). We could likely start there.

require(Rdistance)
data("sparrowDetectionData")
data("sparrowSiteData")

# Demo the current functionality of comparing likelihood-expansion combos
autoDistSamp(dist ~ 1, detectionData=sparrowDetectionData, siteData=sparrowSiteData,
             likelihoods=c("halfnorm", "hazrate"),
             series=c("cosine", "simple"), expansions=0:1,
             area=1e4, w.hi=100, R=3, plot.bs=TRUE)

# Try comparing likelihood combos for a model function that includes a covariate
# Errors (message below).
# I suspect this errors in the plotting stage (looks like it fits the first dfunc fine),
# but haven't looked much into it
# Error: object of type 'symbol' is not subsettable
autoDistSamp(dist ~ bare, detectionData=sparrowDetectionData, siteData=sparrowSiteData,
             likelihoods=c("halfnorm", "hazrate"),
             expansions=0,
             area=1e4, w.hi=100, R=3, plot=TRUE, plot.bs=TRUE)

# If you disable the plots, it will run and compare models with covariates
autoDistSamp(dist ~ bare, detectionData=sparrowDetectionData, siteData=sparrowSiteData,
             likelihoods=c("halfnorm", "hazrate"),
             expansions=0,
             area=1e4, w.hi=60, R=3, plot=FALSE, plot.bs=FALSE)
tmcd82070 commented 6 years ago

@ashoffman is working on this