Steps: (1) Fit a model using functions from the MCMCpack
package such as MCMCirt1d
or
MCMCirtKd
. (2) Do diagnostics and convergence
checks on the resulting MCMC objects. (3) Separate the three
types of parameters (site scores, x
, species intercepts,
a
, and species scores, b
), by passing the MCMC
through the getBO
function. (4) Use the other
functions of this package to analyze the results
(BOeta
; BOflip
; BOp
;
BOrotate
; BOswitch
).
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 | ## simulate data
nSite <- 25
nSpec <- 10
nIter <- 10000
set.seed(1)
x <- rnorm(nSite)
a <- rnorm(nSpec)
b <- rnorm(nSpec)
eta <- cbind(1, x) %*% rbind(a, b)
e <- matrix(rnorm(nSite*nSpec), nSite, nSpec)
p <- pnorm(eta + e)
Y <- matrix(rbinom(nSite*nSpec, 1, p), nSite, nSpec)
rownames(Y) <- letters[1:nSite]
colnames(Y) <- LETTERS[1:nSpec]
## fit model
Yirt <- MCMCirt1d(Y, mcmc = nIter, store.item = TRUE)
## getBO
BO <- getBO(Yirt, Y)
## fix identifiability
(refSite <- findRefSite(BO))
BO <- BOflip(BO, refSite)
## get fitted values
pFit <- BOp(BO)
pFitMean <- apply(pFit, c(2, 3), mean)
boxplot(pFitMean ~ Y)
## ordination plot
ordInt <- t(apply(BO$x, c(2, 3), quantile, probs = c(0.025, 0.975))[,,1])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.