data(wigger)
data(dataC)
data(dataRead)
## fit eDNA concentration data - use AEMs as covariates
set.seed(9)
out <- run_eDITH_optim(dataC, wigger, n.AEM = 10,
n.attempts = 1) # reduced n.AEM, n.attempts for illustrative purposes
# it is recommended to attempt optimization several times to ensure convergence
# \donttest{
library(rivnet)
# best-fit map of eDNA production rates
plot(wigger, out$p)
# best-fit map of detection probability
plot(wigger, out$probDet)
# compare best-fit vs observed eDNA concentrations
plot(out$C[dataC$ID], dataC$values,
xlab = "Modelled concentrations", ylab = "Observed concentrations")
abline(a=0, b=1)
## fit eDNA read number data - use AEMs as covariates
set.seed(5)
out <- run_eDITH_optim(dataRead, wigger, ll.type = "nbinom",
par.AEM = list(weight = "gravity"),
n.attempts = 1) # reduced n.attempts for illustrative purposes
## use user-defined covariates
covariates <- data.frame(urban = wigger$SC$locCov$landcover_1,
agriculture = wigger$SC$locCov$landcover_2,
forest = wigger$SC$locCov$landcover_3,
elev = wigger$AG$Z,
log_drainageArea = log(wigger$AG$A))
set.seed(2)
out.cov <- run_eDITH_optim(dataC, wigger, covariates, n.attempts = 1)
# reduced n.attempts for illustrative purposes
# use user-defined covariates and AEMs
set.seed(1)
out.covAEM <- run_eDITH_optim(dataC, wigger, covariates, use.AEM = TRUE,
par.AEM = list(weight = "gravity"),
n.attempts = 1) # reduced n.attempts for illustrative purposes
# use AEMs with significantly positive spatial autocorrelation
set.seed(1)
out.AEM.moran <- run_eDITH_optim(dataC, wigger, use.AEM = TRUE,
par.AEM = list(weight = "gravity", moranI = TRUE),
n.attempts = 1) # reduced n.attempts for illustrative purposes
# define sampler function when the first 10 AEMs are used as covariates
samp_fun <- function(n){ # input argument needed but not used
mins = c(0, -20, rep(-5,10), 0)
maxs = c(10, 0, rep(5,10), 5e-12)
nams = c("tau", "log_p0", paste0("beta_AEM",1:10), "sigma")
vec <- runif(numeric(13), min=mins, max=maxs)
names(vec) <- nams
return(vec)}
set.seed(1)
out.samp <- run_eDITH_optim(dataC, wigger, n.AEM = 10,
sampler = samp_fun,
n.attempts = 1) # reduced n.attempts for illustrative purposes
# }
Run the code above in your browser using DataLab