finalModel: Bayesian Model To Identify Factors Affecting Wildlife-Vehicle...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/code.R

Description

Bayesian Model To Identify Factors Affecting Wildlife-Vehicle Collisions

Usage

1
finalModel(X, vectorFinalVariables, collisions, nYear, Area, departement)

Arguments

X

a data.frame containing the numeric variables supposed to have an effect on the wildlife-vehicle collisions (columns) for spatial unit (rows).

vectorFinalVariables

a vector of character strings containing the names of the final variables used in the combination.

collisions

an integer vector with length equal to nrow(X) defining the number of wildlife-ungulate collisions in each studied spatial unit.

nYear

an integer vector with length equal to nrow(X) defining the number of Years during which wildlife-ungulate collisions have been recorded in each studied spatial unit.

Area

a numeric vector with length equal to nrow(X) defining the area of each studied spatial unit.

departement

a character vector with length equal to nrow(X) defining the department of each studied spatial unit.

Details

finalModel fits the final Bayesian model used to predict the number of collisions between ungulates and vehicle as a function of a linear combination of a set of environmental variables.

Value

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.

Author(s)

Clement Calenge, clement.calenge@oncfs.gouv.fr

See Also

jags.model, coda.samples, prepareFit

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
## The data used for the fit
data("dataCollision")

## Consider the Kuo-Mallik model fit (see ?prepareFit to see how
## this model was fitted)
data("modelRedDeer")

## we consider the probability associated to each model
probabilityKM(modelRedDeer)

## The best model seems to be the model including forFrag and hunt

## Prepare the data
X <- dataCollision$RedDeer$X

## We scale the variables to improve mixing
X <- as.data.frame(scale(X))

## Prepare the final model, including only the variables forFrag and hunt
pfm <- finalModel(X, c("forFrag","hunt"), dataCollision$RedDeer$coll,
                  dataCollision$RedDeer$Y, dataCollision$RedDeer$Area,
                  dataCollision$RedDeer$departement)

## Not run: 
## WARNING: long execution (about 10 min)!!
## the results are stored in the dataset "finalModelRedDeer"
## But if you want to try it, the data are now ready for the fit:

mo <- jags.model(textConnection(pfm$modelstring), ini=pfm$ini, data=pfm$data4jags)
update(mo, n.iter=1000)
finalModelRedDeer <- coda.samples(mo, variable.names = pfm$coefnames,
                                  n.iter = 500000, thin=100)


## End(Not run)

ClementCalenge/ungulateCollisions documentation built on May 6, 2019, 12:05 p.m.