Description Usage Arguments Details Value Author(s) See Also Examples
Bayesian Model To Identify Factors Affecting Wildlife-Vehicle Collisions
1 | prepareFit(X, alphas, collisions, nYear, Area, departement)
|
X |
a data.frame containing the numeric variables supposed to have an effect on the wildlife-vehicle collisions (columns) for spatial unit (rows). |
alphas |
a character string vector with length equal to
|
collisions |
an integer vector with length equal to
|
nYear |
an integer vector with length equal to |
Area |
a numeric vector with length equal to |
departement |
a character vector with length equal to
|
prepareFit prepares the elements required for the
fit of the Kuo-Mallik model (a Bayesian model used to identify
factors affecting wildlife-vehicle collisions).
a list with all elements required for the fit of the model
with JAGS, that is: (i) data4jags: the list of the data
required by the model, to be passed to the argument data of
the function jags.model of the package rjags, (ii)
ini: list of starting values for the parameters, to be
passed to the argument init of the function
jags.model, (iii) modelstring: a character string
containing the model fit by JAGS, (iv) coefnames: vector of
character strings containing the names of the coefficients of
interest in the model, to be passed to the argument
variable.names of the function coda.samples of the
package rjags.
Clement Calenge, clement.calenge@oncfs.gouv.fr
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 50 51 52 53 54 55 56 57 | ## Load the data:
data("dataCollision")
## Prepare the data
X <- dataCollision$RedDeer$X
## Sets the elevation <600 to NULL (redundant with other elevations:
## if the elevation is neither >1500, nor between 600 and 1500,
## it is necessarily < 600
X$elev600 <- NULL
## Set the variable roads to NULL (not useful here, as noted in the
## paper)
X$roads <- NULL
## prepares the alpha:
## vector alphas: the name of alphas is the same as the columns of X...
alphas <- names(X)
## ... except for elevation and habitat,
## which correspond to several variables in X
alphas[7:8] <- "elev"
alphas[11:14] <- "hab"
## Note that the variables Agriculture, Open, Urban, and Forest
## are strongly correlated together. To reduce the correlation and
## improve mixing, we transform these variables with the help of a PCA
## (package ade4)
hab <- X[,11:14]
X <- X[,-c(11:14)]
pc <- ade4::dudi.pca(hab,scannf = FALSE, nf=4)
## We scale the variables to improve mixing
X <- as.data.frame(scale(X))
## and we add the transformed habitat variables from the PCA:
li1 <- pc$l1
X$AX1 <- li1[,1]
X$AX2 <- li1[,2]
X$AX3 <- li1[,3]
X$AX4 <- li1[,4]
## Use of the function preparefit
pf <- prepareFit(X, alphas, dataCollision$RedDeer$coll,
dataCollision$RedDeer$Y, dataCollision$RedDeer$Area,
dataCollision$RedDeer$departement)
## Not run:
## WARNING: very long execution (about 1 hour)!!
## the results are stored in the dataset "modelRedDeer"
## But if you want to try it, the data are now ready for the fit:
mo <- jags.model(textConnection(pf$modelstring), ini=pf$ini, data=pf$data4jags)
update(mo, n.iter=1000)
modelRedDeer <- coda.samples(mo, variable.names = pf$coefnames,
n.iter = 500000, thin=100)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.