Description Usage Arguments Value Author(s) Examples
This function allows, for each MCMC iteration, to simulate a
hypothetical replication of the dataset using the model; in other
words, for each simulated vector of parameters, it simulates a number
of relocations in each habitat type for each monitored animal. Such
simulated values can be used to compare the observed number of
relocations for each roe deer with the statistical distribution of
simulated numbers of relocations. THIS FUNCTION CAN ONLY BE USED WITH
THE RESULTS OF THE FIT OF MODEL f2 !!!!! i.e. using the dataset
coefficientsModel2
.
1 | simulateNewData(coefMatrix, availMatrix, Nlocs, site)
|
coefMatrix |
the matrix containing the simulated vectors of parameters, concatenated by rows (i.e. each row is a simulated vector of parameter). |
availMatrix |
A matrix containing the proportion of the 3 habitat types (columns) for each monitored animal (row) |
Nlocs |
A vector containing the number of relocations for each animal. |
site |
A vector containing the site corresponding to each animal. |
The result is a list with B elements (B being the number of MCMC
iterations, i.e. the number of rows in coefMatrix
), each
element being a matrix with 3 columns (the 3 habitat types) and N rows
(the N animals), containing the simulated number of relocations.
William Gaudry, Clement Calenge, Sonia Said, Jean-Michel Gaillard
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 58 59 60 61 62 63 64 65 66 67 68 69 | ######################################################
##
## 1. Load the data and fit the model
## We load the data used for the fit:
data(HS3sites)
## We remove the information concerning the meadows
## (negligible, see the paper)
HS3sites$locs$meadows <- NULL
HS3sites$hr$meadows <- NULL
## Calculates the total number of relocations
HS3sites$N <- apply(HS3sites$locs,1,sum)
## stores the number of animals
HS3sites$J <- nrow(HS3sites$locs)
## keeps the home-range information in another object
availhr <- HS3sites$hr
## For a better mixing, we scale the covariates
HS3sites$hr <- scale(HS3sites$hr)
## We have described in the example section of the help
## page of the dataset coefficientsModel2 how to fit the model.
## We just load the dataset:
data(coefficientsModel2)
######################################################
##
## 2. Simulate new datasets
## binds the three MCMC chains by row
cor2 <- do.call(rbind, coefficientsModel2)
## Not run:
## Simulate new datasets: warning! very slow!!
nd <- simulateNewData(cor2, HS3sites$hr, HS3sites$N, HS3sites$site)
## For every number of observed relocations
## identify whether it falls in the 95
## WARNING: can also be very slow!
deds <- matrix(0, nrow=nrow(HS3sites$hr), ncol=3)
for (i in 1:nrow(deds)) {
for (j in 1:ncol(deds)) {
## vector of simulated number of relocations
vec <- sapply(nd, function(x) x[i,j])
## The 95
qu <- quantile(vec, c(0.025,0.975))
## does the observed number fall in the CI?
deds[i,j] <- as.numeric((HS3sites$locs[i,j]>=qu[1]&HS3sites$locs[i,j]<=qu[2]))
}
}
## Finally, deds contains 1 if the corresponding number of relocations
## is in the CI. The proportion of CI containing the true value is:
sum(deds)/length(as.vector(deds))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.