BANOVA.Multinomial {BANOVA} | R Documentation |
Estimation of BANOVA with a Multinomial dependent variable
Description
BANOVA.Multinomial
implements a Hierarchical Bayesian ANOVA for multinomial response variable using a logit link and a normal heterogeneity distribution.
Usage
BANOVA.Multinomial(l1_formula = "NA", l2_formula = "NA",
dataX, dataZ, y, id, l2_hyper = c(1, 1, 0.0001), burnin = 5000, sample = 2000,
thin = 10, adapt = 0, conv_speedup = F, jags = runjags.getOption('jagspath'))
## S3 method for class 'BANOVA.Multinomial'
summary(object, ...)
## S3 method for class 'BANOVA.Multinomial'
predict(object, Xsamples = NULL, Zsamples = NULL,...)
## S3 method for class 'BANOVA.Multinomial'
print(x, ...)
Arguments
l1_formula |
formula for level 1 e.g. '~X1+X2', response variable must not be included |
l2_formula |
formula for level 2 e.g. '~Z1+Z2', response variable must not be included |
dataX |
a list of data frames(each corresponds to the choice set of each observation) that includes all covariates and factors |
dataZ |
a data frame(long format) that includes all level 2 covariates and factors |
y |
choice responses, 1,2,3... |
id |
subject id |
l2_hyper |
level 2 hyperparameters, c(a, b, |
burnin |
the number of burn in draws in the MCMC algorithm, default 5000 |
sample |
target samples in the MCMC algorithm after thinning, default 2000 |
thin |
the number of samples in the MCMC algorithm that needs to be thinned, default 10 |
adapt |
the number of adaptive iterations, default 0 (see run.jags) |
conv_speedup |
whether to speedup convergence, default F |
jags |
the system call or path for activating 'JAGS'. Default calls findjags() to attempt to locate 'JAGS' on your system |
object |
object of class |
Xsamples |
new data samples in level one, must be a list( the same format with the traning data), numeric variables must be mean centered. |
Zsamples |
new data samples in level two( the same format with the traning data), numeric variables must be mean centered. |
x |
object of class |
... |
additional arguments,currently ignored |
Details
Level 1 model:
P(y_i = \ell) = \frac{exp(\eta_{i\ell})}{\sum_{\ell=1}^L exp(\eta_{i\ell})}
where \eta_{i\ell} = \sum_{p = 0}^{P}\sum_{j=1}^{J_p}X_{i,j}^{k,p} \beta_{j,s_i}^p
, s_i
is the subject id of response i
, see BANOVA-package
. X_{i,j}^{k,p}
is the design matrix corresponding to each class \ell(\ell=1,.,L)
of y_i
.
The first level of the response is the base level, thus the intercept corresponding to this level will not be included.
Value
BANOVA.Multinomial
returns an object of class "BANOVA.Multinomial"
. The returned object is a list containing:
anova.table |
table of effect sizes |
coef.tables |
table of estimated coefficients |
pvalue.table |
table of p-values |
dMatrice |
design matrices at level 1 and level 2 |
samples_l2_param |
posterior samples of level 2 parameters |
dataX |
original dataX |
dataZ |
original dataZ |
mf1 |
model.frame of level 1 |
mf2 |
model.frame of level 2 |
n_categories |
the number of categories of the response |
JAGSmodel |
'JAGS' model |
Examples
# see 'choicedata'
data(choicedata)
# generate dataX(convert the within-subject variables to a list)
dataX <- list()
for (i in 1:nrow(choicedata)){
logP <- as.numeric(log(choicedata[i,3:8]))
# all numeric variables must be mean centered
dataX[[i]] <- as.data.frame(logP) - mean(logP)
}
dataZ <- choicedata[,9:13]
res <- BANOVA.Multinomial(~ logP, ~ college, dataX, dataZ,
choicedata$choice, choicedata$hhid, burnin = 100, sample = 100, thin = 10)
# or use BANOVA.run based on 'Stan'
require(rstan)
res <- BANOVA.run(~ logP, ~ college, dataX = dataX, dataZ = dataZ,
model_name = 'Multinomial', y_value = choicedata$choice,
id = choicedata$hhid, iter = 100, thin = 1, chains = 2)