Upload
trinhque
View
216
Download
1
Embed Size (px)
Citation preview
Package ‘BANOVA’January 22, 2018
Type Package
Title Hierarchical Bayesian ANOVA Models
Version 1.1.1
Date 2018-01-21
Author Chen Dong, Michel Wedel
SystemRequirements C++11, JAGS >= 4.1.0(http://mcmc-jags.sourceforge.net)
Maintainer Chen Dong <[email protected]>
Depends R (>= 3.2.3)
Imports rjags(>= 3-13), runjags (>= 1.2.1-0), coda (>= 0.16-1),rstan(>= 2.15.1), methods
Suggests knitr, rmarkdown
VignetteBuilder knitr
Description It covers several Bayesian Analysis of Variance (BANOVA) models used in analy-sis of experimental designs in which both within- and between- subjects factors are manipu-lated. They can be applied to data that are common in the behavioral and social sci-ences. The package includes: Hierarchical Bayes ANOVA models with normal response, t re-sponse, Binomial (Bernoulli) response, Poisson response, ordered multinomial re-sponse and multinomial response variables. All models accommodate unobserved heterogene-ity by including a normal distribution of the parameters across individuals. Outputs of the pack-age include tables of sums of squares, effect sizes and p-values, and tables of predic-tions, which are easily interpretable for behavioral and social researchers. The floodlight analy-sis and mediation analysis based on these models are also pro-vided. BANOVA uses 'Stan' and 'JAGS' as the computational platform.
License GPL (>= 2)
NeedsCompilation yes
Repository CRAN
Date/Publication 2018-01-22 11:57:32 UTC
1
2 BANOVA-package
R topics documented:BANOVA-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2BAnova . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4BANOVA.Bernoulli . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5BANOVA.Binomial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7BANOVA.build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9BANOVA.floodlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10BANOVA.mediation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12BANOVA.model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13BANOVA.Multinomial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14BANOVA.Normal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16BANOVA.ordMultinomial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18BANOVA.Poisson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20BANOVA.run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22BANOVA.T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24bernlogtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26bpndata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27choicedata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29colorad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30colorad2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31condstudy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33conv.diag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34goalstudy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36ipadstudy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37pairs.BANOVA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39table.predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39table.pvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40trace.plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Index 42
BANOVA-package BANOVA: Hierarchical Bayesian ANOVA Models
Description
This package includes several hierarchical Bayes Analysis of Variance models. These models aresuited for the analysis of experimental designs in which both within- and between- subjects factorsare manipulated, and account for a wide variety of distributions of the dependent variable. Flood-light analysis and mediation analysis basaed on these models are also provided. The package uses’Stan’ and ’JAGS’ as the computational platform.
BANOVA-package 3
Details
Package: BANOVAType: PackageVersion: 1.1.1Date: 2018-01-21License: GPL (>= 2)
Model:E(yi) = g−1(ηi)
where ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of data response i. Missing values (NAs) ofyi are allowed. The within-subjects factors and their interactions are indexed by p(p = 1, 2, ., P ).Each index p represents a batch of Jp coefficients: βpj,s, j = 1, ., Jp;s = 1, ., S indexes subjects.Note that if the subject-level covariate is continuous, Jp = 1, so that ANCOVA models are alsoaccommodated (relaxing their "constant slope" assumption).
The population-level model allows for heterogeneity among subjects, because the subject-level co-efficients βpj,s are assumed to follow a multivariate normal distribution.The between-subjects fac-tors and their interactions are indexed by q, (q = 1, 2, ., Q), q = 0 denotes the constant term. Thepopulation-level ANOVA can be written as:βpj,s =
∑Qq=0 θ
pqj,kqs
+ δpj,s
The population-level ANCOVA model can be expressed as a linear model with a design matrix Zthat contains all between-subjects factors and their interactions and a constant term:βpj,s =
∑Qk=1 Zs,kθ
pj,k + δpj,s
where Zs,kis an element of Z, a S × Q matrix of covariates. θpj,k is a hyperparameter which cap-tures the effects of between-subjects factor q on the parameter βpj,s of within-subjects factor p. Theerror δpj,s is assumed to be normal: δpj,s ~ N(0, σ−2
p ). Proper, but diffuse priors are assumed: θpj,k~ N(0, γ), and σ−2
p ~ Gamma(a, b), where γ, a, b are hyper-parameters. The default setting isγ = 10−4, a = 1, b = 1.
Note that missing values of independent variables are currently not allowed in the package.
Author(s)
Chen Dong; Michel Wedel
Maintainer: Chen Dong <[email protected]>
References
Dong, C. and Wedel, M. (2017) BANOVA: An R Package for Hierarchical Bayesian ANOVA, Journalof Statistical Software, Vol. 81, No.9, pp. 1-46.
McCullagh, P., Nelder, JA. (1989) Generalized linear models, New York, NY: Chapman and Hall.
Gelman, A. (2005) Analysis of variance-why it is more important than ever, Ann. Statist., Vol. 33,No. 1, pp. 1-53.
4 BAnova
Rossi, P., Allenby,G., McCulloch, R. (2005) Bayesian Statistics and Marketing, John Wiley andSons.
Gill, J. (2007) Bayesian Methods for the Social and Behavioral Sciences, Chapman and Hall, Sec-ond Edition.
Gelman, A., Carlin, J., Stern, H. and Dunson, D. (2013) Bayesian Data Analysis, London: Chapmanand Hall.
Wedel, M. and Dong, C. (2016) BANOVA: Bayesian Analysis of Variance for Consumer Research.Submitted.
BAnova Function to print the table of effect sizes
Description
The analysis of variance is performed at level 1 (for the single level model) and level 2 equation ofthe Bayesian ANOVA see BANOVA-package. This makes it possible to capture the effects of level-1or level-2 variables on the heterogeneity distribution of subjects, and compute sums of squares andeffect sizes.
Usage
BAnova(x)
Arguments
x the object from BANOVA.*
Details
Measures of effect size in regression are measures of the degree of association between an effect(e.g., a main effect, an interaction, a linear contrast) and the dependent variable. They can be con-sidered as the correlation between a categorical factor(effect) and the dependent variable. They areusually interpreted as the proportion of variance in the dependent variable that is attributable to eacheffect. In the package, partial Eta squared is calculated and displayed. It is defined as follows,
η2 =(SSeffect)
(SSeffect+SSerror)
Where: SS_effect= the sums of squares for the effect of interestSS_error= the sums of squares for the error in the regression.
This equation is evaluated at each draw of the parameters, which allows for the calculation of notonly the posterior mean, but also the credible interval of the effect size.
BANOVA.Bernoulli 5
References
Fox, J. (2008) Applied Regression Analysis and Generalized Linear Models, Second Edition. Sage.
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.
Lakens, D. (2013) Calculating and Reporting Effect Sizes to Facilitate Cumulative Science: APractical Primer for T-tests and ANOVAs, Frontiers in Psychology, Vol. 4, pp.863.
Gelman, A. and Pardoe, I. (2006) Bayesian Measures of Explained Variance and Pooling in Multi-level (Hierarchical) Models, TECHNOMETRICS, Vol. 48, NO. 2.
Examples
data(goalstudy)res1 <- BANOVA.Normal(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 1000, sample = 1000, thin = 2)BAnova(res1)
# or use BANOVA.run based on 'Stan'res2 <- BANOVA.run(bid~1, ~progress*prodvar, model_name = 'Normal',data = goalstudy, id = goalstudy$id, iter = 1000, chains = 2)BAnova(res2)
BANOVA.Bernoulli Estimation of BANOVA with a Bernoulli dependent variable
Description
BANOVA.Bernoulli implements a Bayesian ANOVA for binary dependent variable, using a logitlink and a normal heterogeneity distribution.
Usage
BANOVA.Bernoulli(l1_formula = "NA", l2_formula = "NA", data,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.Bernoulli'summary(object, ...)## S3 method for class 'BANOVA.Bernoulli'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.Bernoulli'print(x, ...)
6 BANOVA.Bernoulli
Arguments
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
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses
id subject ID of each response unit
l2_hyper level 2 hyperparameters, c(a, b, γ), default c(1,1,0.0001)
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.Bern (returned by BANOVA.Bern)
newdata test data, either a matrix, vector or a data.frame. It must have the same formatwith the original data (the same number of features and the same data classes)
x object of class BANOVA.Bern (returned by BANOVA.Bern)
... additional arguments,currently ignored
Details
Level 1 model:yi ~ Binomial(1, pi), pi = logit−1(ηi)
where ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of data record i. see BANOVA-package
Value
BANOVA.Bernoulli returns an object of class "BANOVA.Bernoulli". The returned object is a listcontaining:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameters
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
BANOVA.Binomial 7
Examples
data(bernlogtime)
# model with the dependent variable : responseres <- BANOVA.Bernoulli(response~typical, ~blur + color, bernlogtime,bernlogtime$subject, burnin = 5000, sample = 2000, thin = 10)summary(res)# or use BANOVA.runres0 <- BANOVA.run(response~typical, ~blur + color, data = bernlogtime,model_name = 'Bernoulli',id = bernlogtime$subject, iter = 100, thin = 1, chains = 2)summary(res0)
BANOVA.Binomial Estimation of BANOVA with a Binomial dependent variable
Description
BANOVA.Binomial implements a Hierarchical Bayesian ANOVA for a binomial response variableusing a logit link and a normal heterogeneity distribution.
Usage
BANOVA.Binomial(l1_formula = "NA", l2_formula = "NA", data,id, num_trials, 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.Binomial'summary(object, ...)## S3 method for class 'BANOVA.Binomial'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.Binomial'print(x, ...)
Arguments
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
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses
id subject ID of each response unit
num_trials the number of trials of each observation(=1, if it is bernoulli), the type is forcedto be ’integer’
l2_hyper level 2 hyperparameters, c(a, b, γ), default c(1,1,0.0001)
burnin the number of burn in draws in the MCMC algorithm, default 5000
8 BANOVA.Binomial
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.Bin (returned by BANOVA.Bin)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
x object of class BANOVA.Bin (returned by BANOVA.Bin)
... additional arguments,currently ignored
Details
Level 1 model:yi ~ Binomial(ntrials, pi), pi = logit−1(ηi)
where ntrials is the binomial total for each record i, ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject idof response i. see BANOVA-package
Value
BANOVA.Binomial returns an object of class "BANOVA.Bin". The returned object is a list containing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameters
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
Examples
data(colorad)
# mean center Blur for effect codingcolorad$blur <- colorad$blur - mean(colorad$blur)res <- BANOVA.Binomial(y~typic, ~color*blur, colorad, colorad$id, as.integer(16),burnin = 5000, sample = 2000, thin = 10)summary(res)# or use BANOVA.run
BANOVA.build 9
res0 <- BANOVA.run(y~typic, ~color*blur, data = colorad, model_name = 'Binomial',id = colorad$id, num_trials = as.integer(16), iter = 100, thin = 1, chains = 2)summary(res0)table.predictions(res)# only in-model variables(except numeric variables) will be usedpredict(res0, c(1, 0, 8, 2, 1, 0.03400759))
BANOVA.build Build BANOVA models
Description
BANOVA.build builds(compiles) BANOVA models.
Usage
BANOVA.build(BANOVA_model)
Arguments
BANOVA_model an object of class "BANOVA.model"
Value
BANOVA.build returns an object of class "BANOVA.build". The returned object is a list containing:
stanmodel the compiled ’Stan’ model
model_name the model name
single_level if the model is a single level model
Examples
model <- BANOVA.model('Poisson', single_level = FALSE)Poisson_model <- BANOVA.build(model)# visualize the modelcat(model$model_code)# modify the model code and rebuild# be careful to change any parametersmodel$model_code <-"data {
int<lower=0> N;int<lower=0> J;int<lower=0> M;int<lower=0> K;matrix[N, J] X;matrix[M, K] Z;
10 BANOVA.floodlight
int<lower=0> id[N];int y[N];
}
parameters {matrix[J, M] beta1;matrix[K, J] beta2;vector<lower=0>[J] tau_beta1Sq;
}
model {vector[N] y_hat;matrix[M, J] mu_beta1;vector[J] tau_beta1;tau_beta1 = sqrt(tau_beta1Sq);for (i in 1:N){
y_hat[i] = X[i,]*beta1[,id[i]];}y ~ poisson_log(y_hat);mu_beta1 = Z*beta2;for (i in 1:J){
beta1[i,] ~ normal(mu_beta1[,i], tau_beta1[i]);}tau_beta1Sq ~ inv_gamma(1, 1);for (i in 1:J){
beta2[,i] ~ normal(0, 10);}
}"Poisson_model_new <- BANOVA.build(model)
BANOVA.floodlight Floodlight analysis based on BANOVA models
Description
BANOVA.floodlight conducts floodlight analysis based on various BANOVA models.
Usage
BANOVA.floodlight(sol, var_numeric, var_factor, flood_values = list())## S3 method for class 'BANOVA.floodlight'print(x, ...)
Arguments
sol a BANOVA.* object
BANOVA.floodlight 11
var_numeric the numeric variable
var_factor the factor variable
flood_values a list of values of the other numeric variables which interact with var_factor andvar_numeric, the floodlight analysis will be based on these values, default 0
x a BANOVA.floodlight object
... additional arguments, currently ignored
Details
A floodlight analysis (Spiller et al. 2013; Johnson and Neyman 1936) based on BANOVA modelsis conducted, which identifies regions of the numeric variable for which differences between thelevels of the factor are significant. The endpoints of the 95% credible interval of the numericvariable provide the Johnson-Neyman points; for values outside of that interval there is ’strong’evidence that there is a difference between the levels of the factor.
Value
BANOVA.floodlight returns an object of class "BANOVA.floodlight". The returned object is alist containing:
sol table of the floodlight analysis including the 95% credible interval
num_range range of the numeric variable
References
Spiller, S., Fitzsimons, G., Lynch Jr., J. and McClelland, G. (2013) Spotlights, Floodlights, and theMagic Number Zero: Simple Effects Tests in Moderated Regression. Journal of Marketing Research,Vol. L, pp. 277-288.
Wedel, M. and Dong, C. (2016) BANOVA: Bayesian Analysis of Variance for Consumer Research.Submitted.
Examples
data(condstudy)
# use BANOVA.runmodel <- BANOVA.model('Normal')stanmodel <- BANOVA.build(model)res <- BANOVA.run(att~cond+pict, ~type, fit = stanmodel, data = condstudy,
id = condstudy$id, iter = 500, thin = 1, chains = 2)BANOVA.floodlight(res, var_factor = 'type', var_numeric = 'pict')
data(colorad)colorad$num <- rnorm(nrow(colorad))res1 <- BANOVA.run(y ~ typic*num, ~ color*blur, fit = stanmodel_bin,
data = colorad, id = colorad$id,num_trials = as.integer(16))
# floodlight analysis at the +sd(standard deviation) levelBANOVA.floodlight(res1, var_factor = 'typic',
12 BANOVA.mediation
var_numeric = 'blur', list(num = sd(colorad$num)))
BANOVA.mediation Mediation analysis based on BANOVA models
Description
BANOVA.mediation conducts mediation/moderated mediation analysis based on various BANOVAmodels.
Usage
BANOVA.mediation(sol_1, sol_2, xvar, mediator)## S3 method for class 'BANOVA.mediation'print(x, ...)
Arguments
sol_1 a BANOVA.* model based on an outcome variable, a causal variable, a mediatorand possible moderators
sol_2 a BANOVA.Normal model for the mediator which inlcudes the causal variableand moderators
xvar the causal variablemediator the mediator variablex a BANOVA.mediation object... additional arguments, currently ignored
Details
A mediation or moderated mediation analysis (Baron and Kenny 1986; Zao, Lynch and Chen 2010;Zhang, Wedel and Pieters 2008) based on BANOVA models is conducted, in which posterior distri-butions of the direct effect and indirect effect are calculated based on posterior samples. Means and95% credible intervals are reported.
Value
BANOVA.mediation returns an object of class "BANOVA.mediation". The returned object is a listcontaining:
dir_effects tables of the direct effectm1_effects tables of the effct of the mediator on the outcomem2_effects tables of the effct of the causal variable on the mediatorindir_effects tables of the indirect effectxvar the name of the causal variablemediator the name of the mediator
BANOVA.model 13
References
Baron, R. M. and Kenny, D. A. (1986) Moderator Mediator Variables Distinction in Social Psycho-logical Research: Conceptual, Strategic, and Statistical Considerations, Journal of Personality andSocial Psychology, Vol. 51, No. 6, pp. 1173-82.
Zhang, J., Wedel,M. and Pieters, R. G.M. (2009) Sales Effects of Attention to Feature Advertise-ments: A Bayesian Mediation Analysis, Journal of Marketing Research, Vol.46, No.5, pp. 669-681.
Ying, Y. and MacKinnon,D. P. (2009) Bayesian Mediation Analysis, Psychological Methods, Vol.14, No.4, pp. 301-322.
Zhao, X., John G. L. and Chen, Q. (2010) Reconsidering Baron and Kenny: Myths and TruthsAbout Mediation Analysis, Journal of Consumer Research, Vol.37, No.2, pp. 197-206.
Wedel, M. and Dong, C. (2016) BANOVA: Bayesian Analysis of Variance for Consumer Research.Submitted.
Examples
data(condstudy)
# use BANOVA.run based on 'Stan'model <- BANOVA.model('Normal')stanmodel <- BANOVA.build(model)out2 <- BANOVA.run(att~cond+pict, ~type, fit = stanmodel, data = condstudy,
id = condstudy$id, iter = 500, thin = 1, chains = 2)out3 <- BANOVA.run(pict~cond, ~type, fit = stanmodel, data = condstudy,
id = condstudy$id, iter = 500, thin = 1, chains = 2)# (moderated) mediationsol <- BANOVA.mediation(out2, out3, xvar='cond', mediator='pict')print(sol)print(sol$dir_effects)
BANOVA.model Extract BANOVA models
Description
BANOVA.model extracts BANOVA models from the package.
Usage
BANOVA.model(model_name, single_level = F)
Arguments
model_name a character string in c(’Normal’, ’T’, ’Bernoulli’, ’Binomial’, ’Poisson’, ’ord-Multinomial’, ’Multinomial’)
single_level if the model is a single level model, default False
14 BANOVA.Multinomial
Value
BANOVA.model returns an object of class "BANOVA.model". The returned object is a list containing:
model_code the model code of the extracted model
model_name the model name
single_level if the model is a single level model
Examples
model <- BANOVA.model('Poisson', single_level = FALSE)cat(model$model_code)
BANOVA.Multinomial Estimation of BANOVA with a Multinomial dependent variable
Description
BANOVA.Multinomial implements a Hierarchical Bayesian ANOVA for multinomial response vari-able 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) thatincludes 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, γ), default c(1,1,0.0001)
burnin the number of burn in draws in the MCMC algorithm, default 5000
BANOVA.Multinomial 15
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.Multinomial(returned by BANOVA.Multinomial)
Xsamples new data samples in level one, must be a list( the same format with the traningdata), numeric variables must be mean centered.
Zsamples new data samples in level two( the same format with the traning data), numericvariables must be mean centered.
x object of class BANOVA.Multinomial (returned by BANOVA.Multinomial)
... additional arguments,currently ignored
Details
Level 1 model:P (yi = `) = exp(ηi`)∑L
`=1exp(ηi`)
where ηi` =∑Pp=0
∑Jpj=1X
k,pi,j β
pj,si
, si is the subject id of response i, see BANOVA-package. Xk,pi,j
is the design matrix corresponding to each class `(` = 1, ., L) of yi. The first level of the responseis 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 alist containing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_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
16 BANOVA.Normal
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 centereddataX[[i]] <- as.data.frame(logP) - mean(logP)
}dataZ <- choicedata[,9:13]
res <- BANOVA.Multinomial(~ logP, ~ college, dataX, dataZ,choicedata$choice, choicedata$hhid, burnin = 5000, sample = 2000, thin = 10)
# or use BANOVA.run based on 'Stan'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)
BANOVA.Normal Estimation of BANOVA with a normally distributed dependent variable
Description
BANOVA.Normal implements a Hierarchical Bayesian ANOVA for linear models with normal re-sponse and a normal heterogeneity distribution.
Usage
BANOVA.Normal(l1_formula = "NA", l2_formula = "NA", data,id, l1_hyper = c(1, 1), 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.Normal'summary(object, ...)## S3 method for class 'BANOVA.Normal'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.Normal'print(x, ...)
Arguments
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, ifmissing, the single level model will be generated
BANOVA.Normal 17
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses
id subject ID of each response unit
l1_hyper level 1 hyperparameters, c(α, β)) for two-level models and c(α, β, σp) for singlelevel models, default c(1,1)
l2_hyper level 2 hyperparameters, c(a, b, γ), default c(1,1,0.0001)
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.Normal (returned by BANOVA.Normal)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
x object of class BANOVA.Normal (returned by BANOVA.Normal)
... additional arguments,currently ignored
Details
Level 1 model:yi ~ Normal(ηi, σ−2)
where ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of response i, σ−2 ~ Gamma(α, β). seeBANOVA-package
Value
BANOVA.Normal returns an object of class "BANOVA.Normal". The returned object is a list contain-ing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameters
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
18 BANOVA.ordMultinomial
Examples
# Use the ipadstudy data setdata(ipadstudy)# mean center covariatesipadstudy$age <- ipadstudy$age - mean(ipadstudy$age)ipadstudy$owner <- ipadstudy$owner - mean(ipadstudy$owner)ipadstudy$gender <- ipadstudy$gender - mean(ipadstudy$gender)res <- BANOVA.Normal(attitude~1, ~owner + age + gender + selfbrand*conspic, ipadstudy,ipadstudy$id, burnin = 1000, sample = 1000, thin = 1 )summary(res)
# or use BANOVA.run based on 'Stan'res <- BANOVA.run(attitude~1, ~owner + age + gender + selfbrand*conspic,data = ipadstudy, model_name = 'Normal', id = ipadstudy$id,iter = 100, thin = 1, chains = 2)
BANOVA.ordMultinomial Estimation of BANOVA with a ordered Multinomial response variable
Description
BANOVA.ordMultinomial implements a Hierarchical Bayesian ANOVA for ordered multinomialresponses, with a normal heterogeneity distribution.
Usage
BANOVA.ordMultinomial(l1_formula = "NA",l2_formula = "NA", data, id, l1_hyper = c(0.0001, 100),l2_hyper = c(1, 1, 0.0001, 100), burnin = 5000,sample = 2000, thin = 10, adapt = 0, conv_speedup = F,jags = runjags.getOption('jagspath'))
## S3 method for class 'BANOVA.ordMultinomial'summary(object, ...)## S3 method for class 'BANOVA.ordMultinomial'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.ordMultinomial'print(x, ...)
Arguments
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, ifmissing, the single level model will be generated
data a data frame
id subject ID of each response unit
l1_hyper level 1 hyperparameters for single level models, default c(0.0001,100)
BANOVA.ordMultinomial 19
l2_hyper level 2 hyperparameters, c(a, b, γ, d), default c(1,1,0.0001,100)
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.ordMultinomial (returned by BANOVA.ordMultinomial)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
x object of class BANOVA.ordMultinomial (returned by BANOVA.ordMultinomial)
... additional arguments,currently ignored
Details
Level 1 model:yi = 1, if li < 0yi = 2, if 0 < li < c2...yi = `, if c`−1 < li <∞li = ηi + εi where εi ~ logistic (0, 1), c`, (` = 2, ...L − 1) are cut points, c` ~ N(0, σ̄2
` ), and σ̄2` ~
Uniform(0, d), with d a hyper-parameter.ηi =
∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of response i. see BANOVA-package
Value
BANOVA.ordMultinomial returns an object of class "BANOVA.ordMultinomial". The returnedobject is a list containing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameterssamples_cutp_param
posterior samples of cutpoints
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
20 BANOVA.Poisson
Examples
data(goalstudy)
res <- BANOVA.ordMultinomial (perceivedsim~1, ~progress*prodvar, goalstudy,goalstudy$id, burnin = 5000, sample = 2000, thin = 10)summary(res)# or use BANOVA.run based on 'Stan'res <- BANOVA.run(perceivedsim~1, ~progress*prodvar, data = goalstudy,model_name = 'ordMultinomial', id = goalstudy$id, iter = 100, thin = 1, chains = 2)
BANOVA.Poisson Estimation of BANOVA with Poisson dependent variables
Description
BANOVA.Poisson implements a Hierarchical Bayesian ANOVA for models with a count-data re-sponse variable and normal heterogeneity distribution.
Usage
BANOVA.Poisson(l1_formula = "NA", l2_formula = "NA",data, 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.Poisson'summary(object, ...)## S3 method for class 'BANOVA.Poisson'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.Poisson'print(x, ...)
Arguments
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, ifmissing, the single level model will be generated
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses
id subject ID of each response unit
l2_hyper level 2 hyperparameters, c(a, b, γ), default c(1,1,0.0001)
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, default10
BANOVA.Poisson 21
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.Poisson (returned by BANOVA.Poisson)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
x object of class BANOVA.Poisson (returned by BANOVA.Poisson)
... additional arguments,currently ignored
Details
Level 1 model:yi ~ Poisson(λi), λi = exp(ηi + εi)
where ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of response i, see BANOVA-package. εi is adispersion term.
Value
BANOVA.Poisson returns an object of class "BANOVA.Poisson". The returned object is a list con-taining:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameterssamples_l2_sigma_param
posterior samples of level 2 standard deviations
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
Examples
# use the bpndata datasetdata(bpndata)# within-subjects model using the dependent variable : PIC_FIXres1 <- BANOVA.Poisson(PIC_FIX ~ AD_ID + PIC_SIZE+ PAGE_NUM+ PAGE_POS, ~1, bpndata, bpndata$RESPONDENT_ID, burnin = 500,sample = 200, thin = 5)summary(res1)
22 BANOVA.run
# use the goalstudy datasetdata(goalstudy)goalstudy$bid <- as.integer(goalstudy$bid + 0.5)res2<-BANOVA.Poisson(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 5000, sample = 2000, thin = 10)summary(res2)
# or use the BANOVA.run based on 'Stan'res3 <- BANOVA.run(bid~1, ~progress*prodvar, data = goalstudy,model_name = 'Poisson', id = goalstudy$id, iter = 100, thin = 1, chains = 2)
BANOVA.run Estimation of BANOVA models
Description
BANOVA.run implements Hierarchical Bayesian ANOVA models using ’Stan’
Usage
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, ...)## 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, ...)
Arguments
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. IfNULL, the single level model is used
fit a fitted BANOVA models, an object of class "BANOVA.build", default NULLwhich needs compilation
model_name a character string in c(’Normal’, ’T’, ’Bernoulli’, ’Binomial’, ’Poisson’, ’ord-Multinomial’, ’Multinomial’)
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, defaultNULL
dataZ a data frame(long format) that includes all level 2 covariates and factors, for theMultinomial model only, default NULL
BANOVA.run 23
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses, default NULL
id subject ID 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 forcedto be ’integer’, for the Binomial model only, default 0
object an object of class BANOVA (returned by BANOVA.run)
x an object of class BANOVA (returned by BANOVA.run)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
Xsamples a list of sample data frames(each corresponds to the choice set of each obser-vation) 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 theMultinomial model only, default NULL
... additional arguments, for BANOVA.run, it can include standard ’Stan’ arguments,e.g. warmup, thin, chains, etc., see sampling for more details, for other func-tions, ignored currently
Value
BANOVA.run returns an object of class "BANOVA". The returned object is a list containing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l1_param
posterior samples of level 1 parameterssamples_l2_param
posterior samples of level 2 parameterssamples_l2_sigma_param
posterior samples of level 2 standard deviationssamples_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
24 BANOVA.T
Examples
# Use the ipadstudy data setdata(ipadstudy)
# build the BANOVA model first so that it can be reusedmodel <- BANOVA.model('Normal', single_level = FALSE)banova_model <- BANOVA.build(model)res_1 <- BANOVA.run(attitude~1, ~owner + age + gender + selfbrand*conspic,fit = banova_model, data = ipadstudy, id = ipadstudy$id, iter = 2000,thin = 5, chains = 2)summary(res_1)res_2 <- BANOVA.run(attitude~1, ~selfbrand*conspic,fit = banova_model, data = ipadstudy, id = ipadstudy$id, iter = 2000,thin = 5, chains = 2)
# or call the function directly without specifying the fit argument# but it needs compilationres_1 <- BANOVA.run(attitude~1, ~owner + age + gender + selfbrand*conspic,model_name = 'Normal', data = ipadstudy, id = ipadstudy$id, iter = 2000,thin = 5, chains = 2)
BANOVA.T Estimation of BANOVA with T-distributin of the dependent variable
Description
BANOVA.T implements a Hierarchical Bayesian ANOVA for linear models with T-distributed re-sponse.
Usage
BANOVA.T(l1_formula = "NA", l2_formula = "NA", data, id, l1_hyper = c(1, 1, 1),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.T'summary(object, ...)## S3 method for class 'BANOVA.T'predict(object, newdata = NULL,...)## S3 method for class 'BANOVA.T'print(x, ...)
Arguments
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, ifmissing, the single level model will be generated
BANOVA.T 25
data a data.frame in long format including all features in level 1 and level 2(covariatesand categorical factors) and responses
id subject ID of each response unit
l1_hyper level 1 hyperparameters, c(α, β, λ) for two-level models and c(α, β, λ, σp) forsingle level models, default c(1,1,1)
l2_hyper level 2 hyperparameters, c(a, b, γ), default c(1,1,0.0001)
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, default10
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 attemptto locate ’JAGS’ on your system
object object of class BANOVA.T (returned by BANOVA.T)
newdata test data, either a matrix, vector or a data frame. It must have the same formatwith the original data (the same column number)
x object of class BANOVA.T (returned by BANOVA.T)
... additional arguments,currently ignored
Details
Level 1 model:yi ~ t(ν, ηi, σ−2)
where ηi =∑Pp=0
∑Jpj=1X
pi,jβ
pj,si
, si is the subject id of response i, see BANOVA-package. Thehyper parameters: ν is the degree of freedom, ν ~ Piosson(λ) and σ is the scale parameter, σ−2 ~Gamma(α, β).
Value
BANOVA.T returns an object of class "BANOVA.T". The returned object is a list containing:
anova.table table of effect sizes BAnova
coef.tables table of estimated coefficients
pvalue.table table of p-values table.pvalues
dMatrice design matrices at level 1 and level 2samples_l2_param
posterior samples of level 2 parameters
data original data.frame
mf1 model.frame of level 1
mf2 model.frame of level 2
JAGSmodel ’JAGS’ model
26 bernlogtime
Examples
# Use the ipadstudy data setdata(ipadstudy)res <- BANOVA.T(attitude~1, ~owner + age + gender + selfbrand*conspic, ipadstudy,ipadstudy$id, burnin = 5000, sample = 2000, thin = 10)summary(res)
# or use BANOVA.run based on 'Stan'res19 <- BANOVA.run(attitude~1, ~owner + age + gender + selfbrand*conspic,data = ipadstudy, model_name = 'T', id = ipadstudy$id, iter = 100,thin = 1, chains = 2)
bernlogtime Data for analysis of effects of typicality, blur and color on gist percep-tion of ads
Description
Data from a mixed design experiment, where respondents were exposed to 32 ads, for 100 millisec.The ads were either typical or atypical (typical: 1 or 2). Respondents were exposed to ads that wereeither in full color or black-and-white (color: 1 or 2), and at different levels of blur (1=normal,5 =very high blur). These are between-subjects factors. The dependent variables are the response 0/1,and the response time. Typicality is a within-subjects variable.
Usage
data(bernlogtime)
Format
This R object contains within-subject variable: \$typical is a factor with 2 levels "0" (typical ads)and "1"(atypical ads); between-subjects variables: \$blur is a factor with two levels (1=normal,5 =very high blur). \$color denotes a factor with 2 levels "1"(full color) and "2"(grayscale). \$subjectis the ID of subjects. \$response denotes if the ad is correctly identified. \$logtime is the responsetime.
\$bernlogtime: ’data.frame’: 3072 obs. of 6 variables:. . . \$ subject : int 5 5 5 5 5 5 5 5 5 5 .... . . \$ typical : Factor w/ 2 levels "1","2": 1 2 1 1 1 2 2 2 2 1 .... . . \$ blur : Factor w/ 2 levels "1","5": 1 1 1 1 1 1 1 1 1 1 .... . . \$ color : Factor w/ 2 levels "1","2": 2 2 2 2 2 2 2 2 2 2 .... . . \$ response: int 1 1 1 1 1 1 1 1 1 1 .... . . \$ logtime : num 0.977 1.73 1.784 1 1.149 ...
bpndata 27
References
Wedel, M and R. Pieters (2015). The Buffer Effect: The Role of Color when Advertising Exposuresare Brief and Blurred, Marketing Science, Vol. 34, No. 1, pp. 134-143.
Examples
data(bernlogtime)
# model using the dependent variable : log of the response time(logtime)res1 <- BANOVA.Normal(logtime~typical, ~blur + color, bernlogtime,bernlogtime$subject, burnin = 1000, sample = 1000, thin = 1)summary(res1)table.predictions(res1)
# model using the dependent variable : responseres2 <- BANOVA.Bernoulli(response~typical, ~blur + color, bernlogtime,bernlogtime$subject, burnin = 1000, sample = 1000, thin = 1)summary(res2)table.predictions(res2)
bpndata Eye-movement data for analysis of print ad designs
Description
Data were collected in an experimental study in which 88 participants freely paged through a mag-azine at home or in a waiting room. While flipping through pages at their own pace, participants’eye-movements were recorded with infra-red corneal reflection eye-tracking methodology. In asubsequent memory task, participants were asked to identify the target brand in the ad as soon aspossible by touching the correct brand name on the screen. Accuracy (accurate=1, inaccurate =0)of brand memory and response time were recorded for each ad and participant.
Usage
data(bpndata)
Format
This R object contains 3080 observations in the data (35 ads x 88 participants). The goal is to ex-amine the effects of several ad design variables on both eye movements and memory. The variablesinclude:
1. RESPONDENT_ID: ID number of a respondent;2. AD_ID: ID number of an ad;3. PAGE_NUM: page number in the magazine where an ad appears (1,2,3,...);4. PAGE_POS: the right-side vs. left-side position on a page, 1 = right, 0 = left;5. PIC_FIX: fixation count of the pictorial element (0, 1, 2, 3, ...);6. PIC_SIZE: surface size of the pictorial element, in inches2;
28 bpndata
7. RECALL_ACCU: whether a respondent accurately recalls the brand name, 1= yes, 0 = no;8. RECALL_TIME: the time it takes a respondent to answer the brand recall question, in seconds.
\$ bpndata: ’data.frame’: 3080 obs. of 8 variables:. . . \$ RESPONDENT_ID: int 1 1 1 1 1 1 1 1 1 1 .... . . \$ AD_ID : int 1 2 3 4 5 6 7 8 9 10 .... . . \$ PAGE_NUM : int 2 5 6 11 13 14 17 18 21 22 .... . . \$ PAGE_POS : int 0 1 0 1 1 0 1 0 1 0 .... . . \$ PIC_FIX : int 0 2 1 1 1 2 0 3 3 8 .... . . \$ PIC_SIZE : num 74.2 52.6 77.6 71.4 52.4 .... . . \$ RECALL_ACCU : int 0 0 0 0 0 0 1 1 0 0 .... . . \$ RECALL_TIME : num 2.56 1.04 2.76 2.8 2.28 2.32 2.04 2.04 2.48 0.6 ...
References
Wedel, M. and Pieters, R. (Autumn, 2000). Eye Fixations on Advertisements and Memory forBrands: A Model and Findings, Marketing Science, Vol. 19, No. 4, pp. 297-312
Examples
data(bpndata)# within-subjects model using the dependent variable : PIC_FIX
model <- BANOVA.model('Poisson')stanmodel <- BANOVA.build(model)res0 <- BANOVA.run(PIC_FIX ~ PIC_SIZE + PAGE_NUM + PAGE_POS, ~1,fit = stanmodel, data = bpndata, id = bpndata$RESPONDENT_ID,iter = 200, thin = 1, chains = 2)res0# orres1 <- BANOVA.Poisson(PIC_FIX ~ PIC_SIZE + PAGE_NUM+ PAGE_POS, ~1, bpndata, bpndata$RESPONDENT_ID, burnin = 1000, sample = 1000, thin = 1)res1
# within-subjects model using the dependent variable : RECALL_ACCUmodel_bern <- BANOVA.model('Bernoulli')stanmodel_bern <- BANOVA.build(model_bern)res2 <- BANOVA.run(RECALL_ACCU ~ RECALL_TIME + PAGE_NUM + PAGE_POS, ~1,fit = stanmodel_bern, data = bpndata, id = bpndata$RESPONDENT_ID,iter = 200, thin = 1, chains = 2)res2# orres3 <- BANOVA.Bernoulli(RECALL_ACCU ~ RECALL_TIME + PAGE_NUM+ PAGE_POS, ~1, bpndata, bpndata$RESPONDENT_ID, burnin = 1000, sample = 1000, thin = 1)res3
choicedata 29
choicedata Household Panel Data on Margarine Purchases
Description
Panel data on purchases of margarine by 204 households. Demographic variables are included.
Usage
data(choicedata)
Format
This is an R object that contains within-subjects variables and between-subjects variables:
\$ choicePrice:‘data.frame’: 1500 obs. of 13 variables:. . . \$ hhid : int 2100016 2100016 2100016 2100016. . . \$ choice : int 1 1 1 1 1 4 1 1 4 1
Within-subject variables:
. . . \$ PPk\_Stk : num 0.66 0.63 0.29 0.62 0.5 0.58 0.29 ...
. . . \$ PBB\_Stk : num 0.67 0.67 0.5 0.61 0.58 0.45 0.51 ...
. . . \$ PFl\_Stk : num 1.09 0.99 0.99 0.99 0.99 0.99 0.99 ...
. . . \$ PHse\_Stk: num 0.57 0.57 0.57 0.57 0.45 0.45 0.29 ...
. . . \$ PGen\_Stk: num 0.36 0.36 0.36 0.36 0.33 0.33 0.33 ...
. . . \$ PSS\_Tub : num 0.85 0.85 0.79 0.85 0.85 0.85 0.85 ...
Pk is Parkay; BB is BlueBonnett, Fl is Fleischmanns, Hse is house, Gen is generic, SS is ShedSpread. \_Stk indicates stick, \_Tub indicates Tub form.
Between-subject variables:
. . . \$ Income : num 32.5 17.5 37.5 17.5 87.5 12.5 ...
. . . \$ Fam\_Size : int 2 3 2 1 1 2 2 2 5 2 ...
. . . \$ college : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
. . . \$ whtcollar: Factor w/ 2 levels "0","1": 0 0 0 0 0 0 0 1 1 1 ...
. . . \$ retired : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
Details
choice is a multinomial indicator of one of the 6 brands (in order listed under format). All pricesare in $.
30 colorad
Source
Allenby, G. and Rossi, P. (1991), Quality Perceptions and Asymmetric Switching Between Brands,Marketing Science, Vol. 10, No.3, pp. 185-205.
References
Chapter 5, Bayesian Statistics and Marketing by Rossi et al.http://www.perossi.org/home/bsm-1
Examples
data(choicedata)# generate dataX(convert the within-subjects variables to a list)dataX <- list()for (i in 1:nrow(choicedata)){
logP <- as.numeric(log(choicedata[i,3:8]))# Note: Before the model initialization, all numeric variables(covariates)# must be mean centereddataX[[i]] <- as.data.frame(logP) - mean(logP)
}dataZ <- choicedata[,9:13]
res <- BANOVA.Multinomial(~ logP, ~ college, dataX, dataZ, choicedata$choice,choicedata$hhid, burnin = 1000, sample = 1000, thin = 1)summary(res)predict(res,dataX[1:4], dataZ[1:4,])
colorad Data for gist perception of advertising, study 1
Description
Data from an experiment in which one hundred and sixteen subjects (53 men; mean age 23, rangingfrom 21 to 28) were randomly assigned to one condition of a 5 (blur: normal, low, medium, high,very high) x 2 (color: full color, grayscale) between-participants, x 2 (image: typical ads, atypicalads) within-participants, mixed design. Participants were exposed to 40 images, 32 full-page adsand 8 editorial pages. There were 8 ads per product category, with 4 typical and 4 atypical ones,the categories being car, financial services, food, and skincare. Subjects were asked to identifyeach image being flashed for 100msec. as being an ad or not. The total number of correct adidentifications, for typical and atypical ads, are used as a dependent variable.
Usage
data(colorad)
colorad2 31
Format
This R object contains within-subject variable \$typic which is a factor with 2 levels "0" (typical ads)and "1"(atypical ads); between-subjects variables: \$blur which is a numerical vairable denotes 5different levels of blur (which must be mean centered), \$blurfac is a categorical data correspondingto the levels of \$blur, \$color which is a factor with 2 levels "0"(full color) and "1"(grayscale). \$idis the ID of subjects. \$y is the number of correct identifications of the 16 ads of each subject foreach level of \$typic.
\$ colorad:‘data.frame’: 474 obs. of 8 variables:. . . \$ id : int 1 1 2 2 3 3 4 4 5 5 .... . . \$ typic : Factor w/ 2 levels "0","1": 0 1 0 1 0 1 0 1 0 1 .... . . \$ y : int 8 6 12 6 11 9 9 11 14 14 .... . . \$ blurfac : Factor w/ 5 levels "1","2","3","4",..: 2 2 4 4 2 2 3 3 1 1 .... . . \$ color : Factor w/ 2 levels "0","1": 1 1 0 0 0 0 0 0 1 1 .... . . \$ blur: num 3.69 3.69 4.79 4.79 3.69 ...
References
Wedel, M and R. Pieters (2015). The Buffer Effect: The Role of Color when Advertising Exposuresare Brief and Blurred, Marketing Science, Vol. 34, No. 1, pp. 134-143.
Examples
data(colorad)# mean center blurcolorad$blur <- colorad$blur - mean(colorad$blur)res <- BANOVA.Binomial(y ~ typic, ~ color + blur + color*blur, colorad, colorad$id,as.integer(16), burnin = 1000, sample = 1000, thin = 1)ressummary(res)table.predictions(res)# use the the first row of data to predict,# only in-model variables(except numeric variables) will be usedpredict(res, c(1, 0, 8, 2, 1, 0.03400759))
colorad2 Data for gist perception of advertising, study 2
Description
Data from an experiment in which One hundred and forty eight subjects (71 men; age ranging from21 to 28) were randomly assigned to one condition of a 2 (blur: normal, very high) x 2 (color: fullcolor, grayscale, inverted) between-participants design. Participants were exposed to 25 ads for five
32 colorad2
brands in each of five categories. Ads were selected to be typical for the category, using the sameprocedure as in colorad. The product categories used were cars, financial services, food, skincareand fragrance. Images were flashed for 100 msec. and subjects were asked to identify whether theimage was an ad or not, and if they identified it correctly as an ad, they were asked to indicate whichcategory (out of five) was advertised. The total number of correct ad identifications and categoryidentifications are used as dependent variables.
Usage
data(colorad2)
Format
This R object contains between-subjects variables: \$B is a factor corresponding to the levels of blur(normal = 0, very high = 1), \$C1 and \$C2 are dummy variables denote ’grayscale’ and ’inverted’levels of color. \$C is the original factor denote the color with 3 levels. \$ID is the ID of subjects.\$Y1 is the number of correct identifications of the 25 ads of each subject. \$Y2 is the number ofcorrect identifications of the category, given the number of correct ad identifications.
\$ colorad2:‘data.frame’: 148 obs. of 7 variables:. . . \$ ID : int 1 2 3 4 5 6 7 8 9 10 .... . . \$ C1 : int 0 1 1 0 0 0 0 0 1 1 .... . . \$ C2 : int 0 0 0 1 1 0 0 0 0 0 .... . . \$ B : Factor w/ 2 levels "0","1": 1 1 0 0 1 0 0 1 0 1 .... . . \$ Y1 : int 14 6 23 21 8 23 24 5 23 6 .... . . \$ Y2 : int 2 3 8 8 2 15 10 1 13 0 .... . . \$ C : Factor w/ 3 levels "1","2","3": 1 2 2 3 3 1 1 1 2 2 ...
References
Wedel, M and R. Pieters (2015). The Buffer Effect: The Role of Color when Advertising Exposuresare Brief and Blurred, Marketing Science, Vol. 34, No. 1, pp. 134-143.
Examples
data(colorad2)# factor C is effect coded
model_bin <- BANOVA.model('Binomial')stanmodel_bin <- BANOVA.build(model_bin)res0 <- BANOVA.run(Y1 ~ 1, ~ C + B + C*B, fit = stanmodel_bin,data = colorad2, id = colorad2$id, num_trials = as.integer(25),iter = 1000, thin = 1, chains = 4)res0# or use BANOVA.Binomialres1 <- BANOVA.Binomial(Y1 ~ 1, ~ C + B + C*B, colorad2, colorad2$id, as.integer(25),burnin = 1000, sample = 1000, thin = 1)# or use dummy variables
condstudy 33
res1 <- BANOVA.Binomial(Y1 ~ 1, ~ C1 + B + C2 + C1*B + C2*B,colorad2, colorad2$ID, as.integer(25))res1summary(res1)table.predictions(res1)
# second modelres2 <- BANOVA.Binomial(Y2 ~ 1, ~ C + B + C*B,colorad2, colorad2$id, colorad2$Y1)summary(res2)table.means(res2)
condstudy Data for the study of how brand attitudes were influenced by showingbrands together with pleasant pictures
Description
The study investigated how brand attitudes were influenced by showing brands together with pleas-ant pictures. Attitude change via conditioning can result from either a direct transfer of affect fromthe picture to the brand, or from an indirect association of the brand and the picture in memory.In Sweldens’ et al. (2010) experiment 1, indirect conditioning was implemented by presenting abrand repeatedly with the same picture, direct conditioning by presenting it simultaneously withdifferent pictures. The pictures used were either neutral or positive. This study involved a mixeddesign, with a within-subject factor (cond = neutral, positive), and a between-subject factor (type =indirect, direct), as well as a within-subject mediator. Although the original mediation hypothesesare more intricate, here the mediation of the conditioning effect is investigated by measurements ofattitudes towards the pictures that were shown with the brands (pict).
Usage
data(condstudy)
Format
This R object contains a between-subjects variable: type, which denotes a between-subject modera-tor. It has two levels, "indirect" and "direct". In the "indirect" condition the brands were shown withthe same images, in the indirect condition the brands were shown with different images; Within-subject variables: cond, a within-subject factor with 2 levels: "pos", and "xneu", which indicateswhether each brand was shown with a neutral (xneu) or positive (pos) emotional image. pict, awithin-subject mediator variable measuring the valence (positive/negative) of the emotional imagethe respondent remembers the brand to have been shown with. att, a dependent variable whichdenotes the ratings of attitudes toward brands.
\$ condstudy: ’data.frame’: 888 obs. of 5 variables:. . . \$ id : int 2 2 2 2 2 2 3 3 3 3 .... . . \$ att : num 2.94 2.44 3.44 1.67 1.67 .... . . \$ cond: Factor w/ 2 levels "pos","xneu": 1 1 1 2 2 2 1 1 1 2 ...
34 conv.diag
. . . \$ type: Factor w/ 2 levels "direct","indirect": 2 2 2 2 2 2 2 2 2 2 ...
. . . \$ pict: int 6 7 6 2 4 5 9 3 2 5 ...
References
Sweldens, S., Osselaer, S. and Janiszewski, C. (2010) Evaluative Conditioning Procedures and theResilience of Conditioned Brand Attitudes. Journal of Consumer Research, Vol. 37.
Wedel, M. and Dong, C. (2016) BANOVA: Bayesian Analysis of Variance for Consumer Research.Submitted.
Examples
data(condstudy)
model <- BANOVA.model('Normal')stanmodel <- BANOVA.build(model)out2 <- BANOVA.run(att~cond+pict, ~type, fit = stanmodel, data = condstudy,
id = condstudy$id, iter = 500, thin = 1, chains = 2)conv.diag(out2)summary(out2)table.predictions(out2)BANOVA.floodlight(out2, var_factor = 'type', var_numeric = 'pict')cat(out2$model_code)
out3 <- BANOVA.run(pict~cond, ~type, fit = stanmodel, data = condstudy,id = condstudy$id, iter = 500, thin = 1, chains = 2)
conv.diag(out3)summary(out3)BANOVA.mediation(out2, out3, xvar='cond', mediator='pict')
conv.diag Function to display the convergence diagnostics
Description
The Geweke diagnostic and the Heidelberg and Welch diagnostic are reported. These two con-vergence diagnostics are calculated based on only a single MCMC chain. Both diagnostics re-quire a single chain and may be applied with any MCMC method. The functions geweke.diag,heidel.diag in coda package is used to compute this diagnostic.
Geweke’s convergence diagnostic is calculated by taking the difference between the means from thefirst nA iterations and the last nB iterations. If the ratios nA/n and nB/n are fixed and nA+nB <n, then by the central limit theorem, the distribution of this diagnostic approaches a standard normalas n tends to infinity. In our package, nA = .2 ∗ n and nB = .5 ∗ n.
The Heidelberg and Welch diagnostic is based on a test statistic to accept or reject the null hypothe-sis that the Markov chain is from a stationary distribution. The present package reports the station-ary test.The convergence test uses the Cramer-von Mises statistic to test for stationary. The test is
conv.diag 35
successively applied on the chain. If the null hypothesis is rejected, the first 10% of the iterationsare discarded and the stationarity test repeated. If the stationary test fails again, an additional 10%of the iterations are discarded and the test repeated again. The process continues until 50% of theiterations have been discarded and the test still rejects. In our package, eps = 0.1, pvalue = 0.05are used as parameters of the function heidel.diag.
Usage
conv.diag(x)
Arguments
x the object from BANOVA.*
Value
conv.diag returns a list of two diagnostics:
sol_geweke The Geweke diagnostic
sol_heidel The Heidelberg and Welch diagnostic
References
Plummer, M., Best, N., Cowles, K. and Vines K. (2006) CODA: Convergence Diagnosis and OutputAnalysis for MCMC, R News, Vol 6, pp. 7-11.
Geweke, J. Evaluating the accuracy of sampling-based approaches to calculating posterior mo-ments, In Bayesian Statistics 4 (ed JM Bernado, JO Berger, AP Dawid and AFM Smith). ClarendonPress, Oxford, UK.
Heidelberger, P. and Welch, PD. (1981) A spectral method for confidence interval generation andrun length control in simulations, Comm. ACM. Vol. 24, No.4, pp. 233-245.
Heidelberger, P. and Welch, PD. (1983) Simulation run length control in the presence of an initialtransient, Opns Res., Vol.31, No.6, pp. 1109-44.
Schruben, LW. (1982) Detecting initialization bias in simulation experiments, Opns. Res., Vol. 30,No.3, pp. 569-590.
Examples
data(goalstudy)
res1 <- BANOVA.run(bid~1, ~progress*prodvar, model_name = "Normal", data = goalstudy,id = goalstudy$id, iter = 100, thin = 1)conv.diag(res1)# might need pairs() to confirm the convergence
36 goalstudy
goalstudy Data for the study of the impact of the variety among means on moti-vation to pursue a goal
Description
The study investigated how the perceived variety (high vs. low) among products, as means to asubjects’ goal, affects their motivation to pursue that goal. The hypothesis was that only whenprogress toward a goal is low, product variety increases motivation to pursue the goal. In the study,one hundred and five subjects were randomly assigned to conditions in a 2 (goal progress: low vs.high) by 2 (variety among means: low vs. high) between-subjects design. The final goal was a"fitness goal", and the products used were protein bars; variety was manipulated by asking subjectsto think about how the products were similar (low) or different (high); goal progress was primedby asking subjects questions regarding the frequency of their recent workouts on low (0,1,...,5 ormore) versus high (5 or less, 6,7,..., 10) frequency scales. Subjects were asked questions regardingthe similarity of protein bars, and the bid they were willing to make for the bars, used as dependentvariables in the study.
Usage
data(goalstudy)
Format
This R object contains between-subjects variables: progress, which denotes the progress toward agoal (1:low , 2: high ); prodvar, which denotes the amount of variety within the means to goal at-tainment (1:low , 2:high); perceivedsim, which is a seven-point scale dependent variable measuringthe perceived similarity of the set of products (1 = not at all similar, 7 = very similar); and bid whichdenotes the amount that subjects would be willing to pay for the products .
\$ goalstudy: ’data.frame’: 105 obs. of 5 variables:. . . \$ id : int 1 2 3 4 5 6 7 8 9 10 .... . . \$ perceivedsim : int 5 7 2 2 5 5 5 4 5 7 .... . . \$ progress : Factor w/ 2 levels "1","2": 1 1 2 2 2 1 2 1 2 1 .... . . \$ prodvar : Factor w/ 2 levels "1","2": 2 1 2 1 1 1 1 2 1 1 .... . . \$ bid : num 5 0 1 15 3 10 5 4.5 3 0.75 ...
References
Etkin, J. and Ratner, R. (2012) The Dynamic Impact of Variety among Means on Motivation. Journalof Consumer Research, Vol. 38, No. 6, pp. 1076 - 1092.
Examples
data(goalstudy)
res1 <- BANOVA.Normal(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,
ipadstudy 37
burnin = 1000, sample = 1000, thin = 1)
# use BANOVA.run based on 'Stan'res1 <- BANOVA.run(bid~1, ~progress*prodvar, model_name = "Normal",data = goalstudy, id = goalstudy$id, iter = 1000, thin = 1, chains = 2)conv.diag(res1)# using pairs, it shows that the chains are not converged# the level 1 and level 2 variances are not identified since the data# has only one obervation per subject, it is better to use single level modelspairs(res1, pars = c("beta1[1,1]", "beta2[1,1]", "tau_ySq", "tau_beta1Sq"))# single level modelres1 <- BANOVA.run(bid~progress*prodvar, model_name = "Normal",data = goalstudy, id = goalstudy$id, iter = 1000, thin = 1, chains = 2)BAnova(res1)table.pvalues(res1)trace.plot(res1)table.predictions(res1)
res1_t <- BANOVA.T(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 1000, sample = 1000, thin = 1)
res2 <- BANOVA.ordMultinomial (perceivedsim~1, ~progress*prodvar, goalstudy,goalstudy$id, burnin = 1000, sample = 1000, thin = 1)
summary(res2)table.predictions(res2)# print 'JAGS' codecat(res2$JAGSmodel)
ipadstudy Data for the study of relation between Conspicuous, Brand Usage,Self-Brand Connection and attitudes toward the brand
Description
The study is a between-subjects experiment which has factor (conspicuousness: low vs. high)and one measured variable (self-brand connection). The goal is to show that conspicuous branduse negatively affects attitudes toward the user and the brand only for observers low in self-brandconnection. One hundred fifty-four participants were exposed to a video manipulating conspicuousbrand usage. Participants completed the study by answering several questions which are used tomeasure the dependent (attitude) and independent (self-brand connection) variables in the model.
Usage
data(ipadstudy)
38 ipadstudy
Format
This R object contains between-subjects variables: \$owner is an indicator variable. If the subjectowns iPad or iPhone, then owner = 1. It is equal to 0 otherwise. \$age denotes the age of subjects.\$gender denotes the gender of subjects. gender = 1 if the subject is a female, 0 otherwise. \$conspicis an indicator variable related to conspicuousness. conspic = 1 if conspicuousness is high. \$self-brand denotes the self-brand connection for Apple. \$id is the id of subjects. \$attitude denotes theattitudes towards the brand which is the continuous dependent variable. \$apple_dl is a seven-pointscale variable which denotes the attitudes (dislike = 1,..., like = 7)
\$ ipadstudy: ’data.frame’: 154 obs. of 9 variables:. . . \$ id : int 1 2 3 4 5 6 7 8 9 10 .... . . \$ attitude : num 3 5.33 5.67 5.33 6 .... . . \$ owner : num 0 0 0 1 1 0 1 0 1 0 .... . . \$ age : int 19 33 25 41 38 33 37 46 41 55 .... . . \$ gender : num 0 0 1 0 1 1 1 0 1 1 .... . . \$ conspic : num 0 1 0 1 1 0 0 1 0 1 .... . . \$ selfbrand : num -2.304 1.696 -0.161 -0.447 0.267 .... . . \$ apple_dl : int 3 6 6 5 6 4 7 7 5 5 ...
References
Ferraro,R., Kirmani, A. and Matherly, T., (2013) Look at Me! Look at Me! Conspicuous BrandUsage, Self-Brand Connection, and Dilution. Journal of Marketing Research, Vol. 50, No. 4, pp.477-488.
Examples
data(ipadstudy)
# mean center covariatesipadstudy$age <- ipadstudy$age - mean(ipadstudy$age)ipadstudy$owner <- ipadstudy$owner - mean(ipadstudy$owner )ipadstudy$gender <- ipadstudy$gender - mean(ipadstudy$gender)
res <- BANOVA.Normal(attitude~1, ~owner + age + gender + selfbrand*conspic,ipadstudy, ipadstudy$id, burnin = 100, sample = 100, thin = 1 )summary(res)
# use apple_dl as the dependent variableres <- BANOVA.ordMultinomial(apple_dl~1, ~owner + age + gender + selfbrand*conspic,ipadstudy, ipadstudy$id, burnin = 100, sample = 100, thin = 2 )summary(res)table.predictions(res)
pairs.BANOVA 39
pairs.BANOVA Create a matrix of output plots from a BANOVA object
Description
A pairs method that is customized for MCMC output.
Usage
## S3 method for class 'BANOVA'pairs(x, ...)
Arguments
x an object of class "BANOVA"
... Further arguments to be passed to pairs.stanfit
Details
For a detailed description see pairs.stanfit
Examples
data(ipadstudy)res_1 <- BANOVA.run(attitude~1, ~owner + age + gender + selfbrand*conspic,model_name = 'Normal', data = ipadstudy, id = ipadstudy$id, iter = 1000,thin = 1, chains = 2)pairs(res_1, pars = c("beta2[1,1]","beta2[2,1]"))
table.predictions Function to print the table of means
Description
Output of this function is a table of means for the categorical predictors (and their interactions) ateither within- or between- subjects level. Statistics of interest such as credible intervals and standarddeviations of the means are also computed. Means of numeric variables and their interactions willnot be computed.
Usage
table.predictions(x)
40 table.pvalues
Arguments
x the object from BANOVA.*
Examples
data(goalstudy)res <- BANOVA.Normal(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 1000, sample = 1000, thin = 1)
# or use BANOVA.run based on 'Stan'res <- BANOVA.run(bid~progress*prodvar, model_name = "Normal",data = goalstudy, id = goalstudy$id, iter = 1000, thin = 1, chains = 2)
table.predictions(res)
table.pvalues Function to print the table of p-values
Description
Computes the Baysian p-values for the test concerning all coefficients/parameters:
For p = 1, ..., PH0 : θp,qj,k = 0
H1 : θp,qj,k 6= 0
The two-sided P-value for the sample outcome is obtained by first finding the one sided P-value,min(P (θp,qj,k < 0), P (θp,qj,k > 0)) which can be estimated from posterior samples. For example,P (θp,qj,k > 0) = n+
n , where n+ is the number of posterior samples that are greater than 0, n is thetarget sample size. The two sided P-value is Pθ(θ
p,qj,k ) = 2 ∗min(P (θp,qj,k < 0), P (θp,qj,k > 0)).
If there are θp,qj,k1 , θp,qj,k2
, ..., θp,qj,kJ representing J levels of a multi-level variable, we use a single P-value to represent the significance of all levels. The two alternatives are:
H0 : θp,qj,k1 = θp,qj,k2 = · · · = θp,qj,kJ = 0
H1 : some θp,qj,kj 6= 0
Let θp,qj,kminand θp,qj,kmax
denote the coefficients with the smallest and largest posterior mean. Thenthe overall P-value is defined as
min(Pθ(θp,qj,kmin
), Pθ(θp,qj,kmax
)).
Usage
table.pvalues(x)
trace.plot 41
Arguments
x the object from BANOVA.*
Source
It borrows the idea of Sheffe F-test for multiple testing: the F-stat for testing the contrast withmaximal difference from zero. Thank Dr. P. Lenk of the University of Michigan for this suggestion.
Examples
data(goalstudy)res1 <- BANOVA.Normal(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 1000, sample = 1000, thin = 2)
# or use BANOVA.runres1 <- BANOVA.run(bid~1, ~progress*prodvar, model_name = "Normal",data = goalstudy, id = goalstudy$id, iter = 1000, thin = 1, chains = 2)
table.pvalues(res1)
trace.plot Function to plot the trace of parameters
Description
Function to plot the trace of all coefficients/parameters. The plots can be saved as a pdf file.
Usage
trace.plot(x, save = FALSE)
Arguments
x the object from BANOVA.*save whether to save the trace plot as a pdf file, the default is FALSE
Examples
data(goalstudy)res1 <- BANOVA.Normal(bid~1, ~progress*prodvar, goalstudy, goalstudy$id,burnin = 1000, sample = 1000, thin = 2)
# or use BANOVA.runres1 <- BANOVA.run(bid~1, ~progress*prodvar, model_name = "Normal",data = goalstudy, id = goalstudy$id, iter = 1000, thin = 1, chains = 2)
trace.plot(res1)
Index
∗Topic Hierarchical Bayes, ANOVABANOVA-package, 2
BANOVA (BANOVA-package), 2BAnova, 4, 6, 8, 15, 17, 19, 21, 23, 25BANOVA-package, 2BANOVA.Bernoulli, 5BANOVA.Binomial, 7BANOVA.build, 9BANOVA.floodlight, 10BANOVA.mediation, 12BANOVA.model, 13BANOVA.Multinomial, 14BANOVA.Normal, 16BANOVA.ordMultinomial, 18BANOVA.Poisson, 20BANOVA.run, 22BANOVA.T, 24bernlogtime, 26bpndata, 27
choicedata, 29colorad, 30, 32colorad2, 31condstudy, 33conv.diag, 34
geweke.diag, 34goalstudy, 36
heidel.diag, 34, 35
ipadstudy, 37
pairs, 39pairs.BANOVA, 39pairs.stanfit, 39predict.BANOVA (BANOVA.run), 22predict.BANOVA.Bernoulli
(BANOVA.Bernoulli), 5
predict.BANOVA.Binomial(BANOVA.Binomial), 7
predict.BANOVA.Multinomial(BANOVA.Multinomial), 14
predict.BANOVA.Normal (BANOVA.Normal),16
predict.BANOVA.ordMultinomial(BANOVA.ordMultinomial), 18
predict.BANOVA.Poisson(BANOVA.Poisson), 20
predict.BANOVA.T (BANOVA.T), 24print.BANOVA (BANOVA.run), 22print.BANOVA.Bernoulli
(BANOVA.Bernoulli), 5print.BANOVA.Binomial
(BANOVA.Binomial), 7print.BANOVA.floodlight
(BANOVA.floodlight), 10print.BANOVA.mediation
(BANOVA.mediation), 12print.BANOVA.Multinomial
(BANOVA.Multinomial), 14print.BANOVA.Normal (BANOVA.Normal), 16print.BANOVA.ordMultinomial
(BANOVA.ordMultinomial), 18print.BANOVA.Poisson (BANOVA.Poisson),
20print.BANOVA.T (BANOVA.T), 24
run.jags, 6, 8, 15, 17, 19, 21, 25
sampling, 23summary.BANOVA (BANOVA.run), 22summary.BANOVA.Bernoulli
(BANOVA.Bernoulli), 5summary.BANOVA.Binomial
(BANOVA.Binomial), 7summary.BANOVA.Multinomial
(BANOVA.Multinomial), 14
42
INDEX 43
summary.BANOVA.Normal (BANOVA.Normal),16
summary.BANOVA.ordMultinomial(BANOVA.ordMultinomial), 18
summary.BANOVA.Poisson(BANOVA.Poisson), 20
summary.BANOVA.T (BANOVA.T), 24
table.predictions, 39table.pvalues, 6, 8, 15, 17, 19, 21, 23, 25, 40trace.plot, 41