1 | run.ord(Y, Treat, Covs, ncat, model = "cumlogit", nChains = 3, conv.limit = 1.05, niters = 50000, nruns = 5000, setsize = 4000, betaprior, dcprior, c1prior, path)
|
Y |
|
Treat |
|
Covs |
|
ncat |
|
model |
|
nChains |
|
conv.limit |
|
niters |
|
nruns |
|
setsize |
|
betaprior |
|
dcprior |
|
c1prior |
|
path |
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 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (Y, Treat, Covs, ncat, model = "cumlogit", nChains = 3,
conv.limit = 1.05, niters = 50000, nruns = 5000, setsize = 4000,
betaprior, dcprior, c1prior, path)
{
nobs = length(Y)
if (!is.null(Covs))
Covs = as.matrix(Covs)
prior = prior.ord(Covs, betaprior, dcprior, c1prior, slopeprior = list("norm",
0, 0.1))
inInits = inits.ord(Y, Covs, Treat, ncat)
inData <- data.ord(Y, Covs, ncat, prior, Treat)
model.ord(Covs, prior, path)
pars.to.save <- c("beta", "or", "c", "p")
if (!is.null(Covs))
pars.to.save = c(pars.to.save, "slope")
jags.out <- jags.fit(inData, inInits, pars.to.save, model,
"model.txt", nChains, niters, conv.limit, setsize, nruns,
Covs)
burn.in <- jags.out[[1]]
no.runs <- jags.out[[2]]
samples <- jags.out[[3]]
varnames <- dimnames(samples)[[3]]
nvars <- dim(samples)[3]
beta.vars <- grep("beta", varnames)
beta <- as.vector(samples[, , beta.vars])
or.vars <- grep("or", varnames)
or <- as.vector(samples[, , or.vars])
c.vars <- grep("c", varnames)
c <- matrix(samples[, , c.vars], c(no.runs * nChains, length(c.vars)))
p.vars <- grep("p", varnames)
p <- array(matrix(samples[, , p.vars], c(no.runs * nChains,
length(p.vars))), c(no.runs * nChains, nobs, ncat))
if (!is.null(Covs)) {
slope.vars <- grep("slope", varnames)
slope <- samples[, , slope.vars]
}
if (is.null(Covs)) {
out <- list(burn.in, no.runs, Y, beta, or, c, p)
names(out) <- c("Burn In", "Number runs per chain", "Y",
"beta", "or", "c", "p")
}
else {
out <- list(burn.in, no.runs, Y, beta, or, p, slope)
names(out) <- c("Burn In", "Number runs per chain", "Y",
"beta", "or", "p", "Slopes")
}
return(out)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.