SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: Multi-way ANOVA [ Reply ]
By: Mathew McLean on 2013-06-22 13:08
[forum:39731]
Great. Please let me know when get around to making the changes to the code. Regarding how to specify the groupings, I think one nice way would be to use bars "|" to separate groups. E.g. three groups of two variables each would be specified with the formula: y~x1+x2 | x3+x4 | x5+x6 . Random effects are specified in a similar manner in lme4.

RE: Multi-way ANOVA [ Reply ]
By: Jeff Rouder on 2013-06-22 07:33
[forum:39695]
The issues of multiple g parameters has come up in our discussions from time to time. I think it may be plausible that researchers would want to group slopes into categories, such as those related to effects of individuals and those related to effects of institutions. Yet, I havent seen an example, and so I am curious about a real-world application of such clustering.

RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-22 07:24
[forum:39694]
We had been considering such models since we used them for ANOVA, but we weren't sure whether anyone would find a use for them. We therefore put it on the back burner. It's helpful to know there are people with a need for them,

One of the major conceptual issues is how to specify the groupings from formula interface, or alternatively using an argument. For now, though, I'll stick with loosening up the restrictions on nWayAOV() so that you can specify your own design matrix without it complaining.

RE: Multi-way ANOVA [ Reply ]
By: Mathew McLean on 2013-06-21 22:24
[forum:39693]
Thanks for checking. Yes, it would be quite useful for some current work I am doing. The model I have is quite similar to the one you have in Section 8 of your 2012 paper in Journal of Mathematical Psychology, but I have to be able to specify the design matrices because they don't contain only zeros and ones in my case. It would be great to be able to use and cite your package instead of having to code up something else on my own that clearly won't be as good.

RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-21 21:39
[forum:39692]
Ok, I just checked again, and I do indeed restrict all continuous covariates to a single g, as in the setup of Liang et al. (2008). So the nWayAOV() approach will not work (the function will complain that not all slopes have the same g). I could loosen this restriction, but it would require some new code and testing; is there a particular reason why you want to have different g parameters for different groups of slopes?

RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-21 21:20
[forum:39691]
Actually, I think I spoke too soon. I need to check the code to make sure that it will accept different g priors on different groups of continuous covariates. I'll let you know soon.

RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-21 21:16
[forum:39690]
Ah, I see the model more clearly now. The default functions do not allow separate g parameters on different groups of slopes; all slopes have the same g. If you want to have different g priors on different groups of slope parameters, you'll need to use the nWayAOV() function. This function is unfortunately named, for historical reasons, but it allows specifying a design matrix. See the help and examples for that function.

Note that this function was meant to be called by BayesFactor internally, but is exported for advanced users; I'm not sure how "safe" it is, in the sense that there aren't many checks to make sure that the input you're giving it makes sense. Also, it passes the input to C code, which if it is malformed has the potential to crash R. If you're in doubt, or you can't get it working, you can send me some code and example data - along with a specification of the model to fit - and I can help you with it.

Of particular interest for you are the gMap and continuous arguments.


RE: Multi-way ANOVA [ Reply ]
By: Mathew McLean on 2013-06-21 19:50
[forum:39689]
Thank you for the quick reply. I think I've got it figured out, but I just want to make sure and I may also have a bug report.

Let's say I wish to fit the model y= X_1\theta_1+X_2\theta_2+X_3\theta_3+e
and lets say y is an N-vector, X_1 is an Nx10 matrix, X_2 is Nx8, X_3 is Nx5.
I want \theta_1~N(0,g_1 I_10), \theta_2~N(0, g_2 I_8), \theta_3~N(0, g_2 I_5). Notice the prior covariances are a constant times the identity not a general diagonal matrix of g's and that the constant is different for each vector \theta.

I formed the data frame

dat <- data.frame(y,I(X_1),I(X_2),I(X_3))

then I use lmBF

fullBF <- lmBF(y~X1+X2+X3,data=dat)

Does this give the full model I want with the three g-priors above?

The potential bug relates to the output of the posterior function when the model contains a matrix variable with more than one column like I specified above using I( ). There is an error when the function tries to assign column labels to the output list. For example try

y <- rnorm(50)
X <- matrix(rnorm(250),50,5)
dat <- data.frame(y,I(X))
bf <- lmBF(y~X,data=dat)
posterior(bf,iter=1000) #produces an error

|============================================================================================| 100%
Error in `colnames<-`(`*tmp*`, value = c("X", "sig2", "g")) :
length of 'dimnames' [2] not equal to array extent




RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-21 09:18
[forum:39686]
...and also, perhaps most importantly (since generalTestBF() is the general workhorse function for the package now) see http://bayesfactorpcl.r-forge.r-project.org/#generalTestBF.

RE: Multi-way ANOVA [ Reply ]
By: Richard Morey on 2013-06-21 09:15
[forum:39685]
Hi Mathew,

Yes, this is possible; if you specify the corresponding columns of the data.frame as numeric nonfactors, the package will automatically build the design matrix you want. See http://bayesfactorpcl.r-forge.r-project.org/#regression and http://bayesfactorpcl.r-forge.r-project.org/#glm for examples.

Best,
Richard

Multi-way ANOVA [ Reply ]
By: Mathew McLean on 2013-06-21 08:46
[forum:39684]
Hi, first of all, the package looks very impressive, congratulations. It's so great to see such a detailed help manual. As for my inquiry, referring to the model specified in the Details section of the anovaBF help file, I would like to specify a model with general matrices X_1, X_2, X_3 and get a Bayes factor for comparing a null model with vector \theta_2=\theta_3=0 to the full model. I'm not sure how to specify the design matrices using the formula interface. It would be similar to the setup in Section 8 of the Rounder et. al (2012) Journal of Mathematical Psychology paper except the entries of the design matrices could be any real numbers not just 0s and 1s. More simply, is it possible to specify a model with two scalar/numerical covariates, say X_1 and X_2, subject to the same g-prior ( i.e. (X_1,X_2)'~N(0,g I_2) )?

Thanks to:
Vienna University of Economics and Business Powered By FusionForge