-
Notifications
You must be signed in to change notification settings - Fork 4
/
logisticdupbyx.R
37 lines (32 loc) · 1.13 KB
/
logisticdupbyx.R
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
#' Logistic for duplicates as a function of covariates
#'
#' Treats logistic for duplicates as a function of covariate z; for a given z
#' it computes the function at with those covariate values at a range of
#' distances.
#'
#' @param distance vector of distance values
#' @param x1 covariate data for fct 1
#' @param x2 covariate data for fct 2
#' @param models model list
#' @param beta logistic parameters
#' @param point \code{TRUE} for point transect data
#'
#' @return vector of probabilities
#' @author Jeff Laake
logisticdupbyx <- function(distance, x1, x2, models, beta, point){
# avoid using g0 which calls exp and matrix multiplication twice
ologit <- function(p) p/(1+p)
# Functions used: g0, setcov
xlist <- as.list(x1)
xlist$distance <- distance
xmat <- expand.grid(xlist)
gx1 <- ologit(exp(setcov(xmat, models$g0model) %*% beta))
xlist <- as.list(x2)
xlist$distance <- distance
xmat <- expand.grid(xlist)
if(!point){
return(gx1 * ologit(exp(setcov(xmat, models$g0model) %*% beta)))
}else{
return(gx1 * ologit(exp(setcov(xmat, models$g0model) %*% beta))*2*distance)
}
}