fit_red_Nmix_open: fit_red_Nmix_open

Description Usage Arguments Examples

View source: R/fit_reduced_count_models.R

Description

Find maximum likelihood estimates for model parameters log(lambda), log(gamma), logit(omega), and logit(pdet).

Usage

1
2
3
4
5
6
7
fit_red_Nmix_open(nit, lambda_site_covariates = NULL,
  gamma_site_covariates = NULL, omega_site_covariates = NULL,
  pdet_site_covariates = NULL, gamma_time_covariates = NULL,
  omega_time_covariates = NULL, pdet_time_covariates = NULL, red = 1,
  K, starts = NULL, VERBOSE = FALSE, PARALLELIZE = FALSE,
  APA = FALSE, precBits = 128, tolerance = 10^-6, method = "DFP",
  outFile = NULL, ...)

Arguments

nit

R by T matrix of full counts with R sites/rows and T sampling occassions/columns.

lambda_site_covariates

Either NULL (no lambda site covariates) or a list of vectors of length R, where each vector represents one site covariate, and where the vector entries correspond to covariate values for each site. Note that the covariate structure is assumed to be log(lambda_i) = B0 + B1 * V1_i + B2 * V2_i + ...

gamma_site_covariates

Either NULL (no gamma site covariates) or a list of vectors of length R, where each vector represents one site covariate, and where the vector entries correspond to covariate values for each site. Note that the covariate structure is assumed to be log(gamma_i) = B0 + B1 * V1_i + B2 * V2_i + ...

omega_site_covariates

Either NULL (no omega site covariates) or a list of vectors of length R, where each vector represents one site covariate, and where the vector entries correspond to covariate values for each site. Note that the covariate structure is assumed to be logit(omega_i) = B0 + B1 * V1_i + B2 * V2_i + ...

pdet_site_covariates

Either NULL (no pdet site covariates) or a list of vectors of length R, where each vector represents one site covariate, and where the vector entries correspond to covariate values for each site. Note that the covariate structure is assumed to be logit(pdet_i) = B0 + B1 * V1_i + B2 * V2_i + ...

gamma_time_covariates

Either NULL (no gamma time covariates) or a list of vectors of length T, where each vector represents one time covariate, and where the vector entries correspond to covariate values for each time. Note that the covariate structure is assumed to be log(gamma_i) = B0 + B1 * V1_i + B2 * V2_i + ...

omega_time_covariates

Either NULL (no omega time covariates) or a list of vectors of length T, where each vector represents one time covariate, and where the vector entries correspond to covariate values for each time. Note that the covariate structure is assumed to be logit(omega_i) = B0 + B1 * V1_i + B2 * V2_i + ...

pdet_time_covariates

Either NULL (no pdet time covariates) or a list of vectors of length T, where each vector represents one time covariate, and where the vector entries correspond to covariate values for each time. Note that the covariate structure is assumed to be logit(omega_i) = B0 + B1 * V1_i + B2 * V2_i + ...

red

Reduction factor r, either a number or a vector of length R (specifying reduction factors for each site), or an R by T matrix of reduction factors for each observation.

K

Upper bound on summations, will be reduced by reduction factor red. Either a single number, or a vector of length R (specifying K for each site).

starts

Vector with four elements (if no covariates), log(lambda), log(gamma), logit(omega), and logit(pdet). When there are X covariates B_x for a parameter, will need X+1 starting values for that parameter (+1 for the constant term B0).

VERBOSE

If TRUE, prints the log likelihood to console at each iteration of the optimization (unless optim is being used).

PARALLELIZE

If TRUE, calculation will be split over threads by sites and times. This will not improve computation time if there are no site or time covariates. Will use as many threads as have been made available (initialize with START_PARALLEL(num_cores)).

APA

If TRUE, will use arbitrary precision arithmetic in the likelihood calculations. Use precBits to specify the number of bits of precision.

precBits

If APA=TRUE, then this will specify the number of bits of precision for arbitrary precision arithmetic.

tolerance

Specifies tolerance for convergence (defulat is 10^-6), all components of estimated gradient must be less than tolerance for convergence. If APA=TRUE, then tolerance can be made very small (eg 10^-20) using: tolerance=Rmpfr::mpfr(10^-20, precBits=128). NOTE: currently tolerance is only used if method="DFP".

method

Optimization method to use. Default is "DFP", and is the only method implemented for APA. When APA=FALSE, can use method="BFGS" to use optim().

outFile

If not NULL, name of file for saving algorithm progress (overwritten at each iteration).

...

Additional input for optimization algorithm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Y   <- gen_Nmix_open(num_sites = 5, num_times = 5, lambda = 20, pdet = 0.7, omega = 0.7, gamma = 2)
out <- fit_red_Nmix_open(nit = Y$nit, red = 3, K = 40, starts = c(0.5, 0.5, 0.5, 0.5))

# lambda estimate:
exp(out$par[1])
# gamma estimate:
exp(out$par[2])
# omega estimate:
plogis(out$par[3])
# pdet estimate:
plogis(out$par[4])


# example with site covariates:
Y1 <- gen_Nmix_open(num_sites = 4, num_times = 5, lambda = 10, gamma = 5, omega = 0.50, pdet = 0.75)
Y2 <- gen_Nmix_open(num_sites = 4, num_times = 5, lambda = 5, gamma = 10, omega = 0.75, pdet = 0.50)
Y  <- rbind_pops(Y1, Y2)
START_PARALLEL(num_cores=4)
mod1 <- fit_red_Nmix_open(nit = Y$nit,
                          lambda_site_covariates = list(l1=c(0,0,0,0,1,1,1,1)),
                          gamma_site_covariates  = list(gs=c(0,0,0,0,1,1,1,1)),
                          gamma_time_covariates  = NULL,
                          omega_site_covariates  = list(os=c(0,0,0,0,1,1,1,1)),
                          omega_time_covariates  = NULL,
                          pdet_site_covariates   = list(ps=c(0,0,0,0,1,1,1,1)),
                          pdet_time_covariates   = NULL,
                          red = 4,
                          K   = 50,
                          starts  = NULL,
                          method  = "BFGS",
                          VERBOSE = FALSE,
                          PARALLELIZE = TRUE)
END_PARALLEL()
# lambda sites 1 and 2 estimate:
exp(mod1$par[1])
# lambda sites 3, 4, and 5 estimate:
exp(sum(mod1$par[1:2]))
# gamma sites 1 and 2 estimate:
exp(mod1$par[3])
# gamma sites 3, 4, and 5 estimate:
exp(sum(mod1$par[3:4]))
# omega sites 1 and 2 estimate:
plogis(mod1$par[5])
# omega sites 3, 4, and 5 estimate:
plogis(sum(mod1$par[5:6]))
# pdet sites 1 and 2 estimate:
plogis(mod1$par[7])
# pdet sites 3, 4, and 5 estimate:
plogis(sum(mod1$par[7:8]))

mrparker909/redNMix documentation built on April 4, 2020, 12:24 a.m.