BANOVA.run | R Documentation |
BANOVA.run
implements Hierarchical Bayesian ANOVA models using 'Stan'
BANOVA.run(l1_formula = "NA", l2_formula = "NA", fit = NULL, model_name = 'NA', dataX = NULL, dataZ = NULL, data = NULL, y_value = NULL, id, iter = 2000, num_trials = 1, contrast = NULL, y_lowerBound = -Inf, y_upperBound = Inf, ...) ## S3 method for class 'BANOVA' summary(object, ...) ## S3 method for class 'BANOVA' predict(object, newdata = NULL, Xsamples = NULL, Zsamples = NULL, ...) ## S3 method for class 'BANOVA' print(x, ...)
l1_formula |
formula for level 1 e.g. 'Y~X1+X2' |
l2_formula |
formula for level 2 e.g. '~Z1+Z2', response variable must not be included. If NULL, the single-level model is used |
fit |
a fitted BANOVA models, an object of class |
model_name |
a character string in c('Normal', 'T', 'Bernoulli', 'Binomial', 'Poisson', 'ordMultinomial', 'Multinomial', 'multiNormal', 'truncNormal') |
dataX |
a list of data frames (each corresponds to the choice set of each observation) that includes all covariates and factors, for the Multinomial model only, default NULL |
dataZ |
a data frame (long format) that includes all level 2 covariates and factors, for the Multinomial model only, default NULL |
data |
a data.frame in a long format including all features in level 1 and level 2 (covariates and categorical factors) and responses, default NULL. For the Multivariate Normal model the data must be specially prepared: first, combine the set of dependent variables in a single matrix; next, add this matrix to an original data frame used in the analysis. For an example of the specification of the data, please, see below. |
id |
subject ID (string) of each response unit |
y_value |
choice responses, 1,2,3..., for the Multinomial model only, default NULL |
iter |
target samples in the 'Stan' algorithm after thinning, default 2000 |
num_trials |
the number of trials of each observation(=1, if it is Bernoulli), the type is forced to be 'integer', for the Binomial model only, default 0 |
contrast |
a list of contrasts for planned comparisons, default: effect coding (NULL value) |
y_lowerBound |
lower bound of the dependent variable, for the Truncated Normal model only, default -Inf. |
y_upperBound |
upper bound of the dependent variable, for the Truncated Normal model only, default Inf. |
object |
an object of class |
x |
an object of class |
newdata |
test data, either a matrix, vector or a data frame. It must have the same format as the original data (the same column number) |
Xsamples |
a list of sample data frames(each corresponds to the choice set of each observation) that includes all covariates and factors, for the Multinomial model only, default NULL |
Zsamples |
a data frame(long format) that includes all level 2 covariates and factors, for the Multinomial model only, default NULL |
... |
additional arguments, for |
BANOVA.run
returns an object of class "BANOVA"
. 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_l1_param |
posterior samples of level 1 parameters |
samples_l2_param |
posterior samples of level 2 parameters |
samples_l2_sigma_param |
posterior samples of level 2 standard deviations |
samples_cutp_param |
posterior samples of cutpoints |
data |
original data.frame |
mf1 |
model.frame of level 1 |
mf2 |
model.frame of level 2 |
model_code |
'Stan' code |
single_level |
if this is a single level model |
stan_fit |
fitted samples |
model_name |
the name of the model |
contrast |
contrasts for planned comparisons |
new_id |
id values coded in 1,2,3,... |
old_id |
original id values |
# Analysis of a single-level Normal dependent variable # Use the ipadstudy data set data(ipadstudy) library(rstan) # build the BANOVA model first so that it can be reused model <- BANOVA.model('Normal', single_level = TRUE) banova_model <- BANOVA.build(model) res_1 <- BANOVA.run(attitude~owner + age + gender + selfbrand*conspic, fit = banova_model, data = ipadstudy, id = 'id', iter = 2000, chains = 2) summary(res_1) # or call the function directly without specifying the fit argument # but it needs compilation res_1 <- BANOVA.run(attitude~owner + age + gender + selfbrand*conspic, model_name = 'Normal', data = ipadstudy, id = 'id', iter = 2000, chains = 2) # Hierarchical analysis of multiple dependent variables (Multivariate Normal distribution) # Use the colorad data set data(colorad) # Prepare dependent variables to be analyzed colorad$blur_squared <- (colorad$blur)^2 dv <- cbind(colorad$blur, colorad$blur_squared) colnames(dv) <- c("blur", "blur_squared") colorad$dv <- dv # Build and analyze the model for the dependent variables model <- BANOVA.model('multiNormal') banova_multi_norm_model <- BANOVA.build(model) res_2 <- BANOVA.run(dv ~ typic, ~ color, fit = banova_multi_norm_model, data = colorad, id = 'id', iter = 2000, thin = 1, chains = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.