# [Nipy-devel] rm 2-way ANOVA

Christian Brodbeck christianmbrodbeck@gmail....
Sun Nov 15 17:43:45 CST 2009

```>> Thanks for all the responses! I managed to implement
>> with scikits.statsmodels.OLS and dummy-coding the equivalent of R's
>> aov(V~f+Error(subject)). Does anyone happen to know how I would implement
>> subject as random factor?
>
> I'd be interested to see how you went about doing this, if you think
> it is general enough to contribute to the project.  Did you primarily
> use Josef's code?

I wrote my own code, it depends very much on what your source data looks like and how your factors are coded (as Josef said). It is fairly simple in principle though and could be adapted. If in your data array subjects are alternating inside blocks, the fixed effect of subject can be added to the design matrix as :

_subjects_   _conditions...
s1  1  0  0  0    1 ... \
s2  0  1  0  0    1      \ condition 1
s3  0  0  1  0    1      /
s4 -1 -1 -1 -1    1     /
s1  1  0  0  0    0     \
s2  0  1  0  0    0      \ condition 2
...

(after Rutherford (2000) Introducing Anova and Ancova Amazon preview; I ordered the book so I hope will know more soon)

I did this with:
n = number_of_subjects
p = number_of_conditions
one_block = np.vstack((np.eye(n-1), np.r_[[-1]*(n-1)]))
subjects_matrix = np.vstack([one_block]*p)
design_matrix = np.hstack((subjects_matrix, rest_of_design_matrix))

>
>> Also, Scikits.statsmodels still requires me to repeat the procedure and call
>> the fit function for each individual test seperately, right? There is no
>> direct call for fitting a model for multiple tests independently (i.e. for
>> electrode by time plots)?
>>
>
> I'm not quite sure what you're after here, but if you want to fit
> multiple models, then you have to instantiate each model and call fit
> as the code is at the moment, because the way that I see it (I have an
> econometrics background) a model is both a response and a set of
> covariates (not sure I want to open this can of worms again...but the
> code is probably not as general as it could be given the way I am used
> to approaching problems in economics).  This should be pretty
> straightforward using list comprehension, but if you want to post (or
> send me off list, if you think it's too off-topic) a few more details
> about your code, we can have a look at extending the functionality
> (probably won't happen until Christmas break for me unless someone
> else wants to have a go).

Yes you would have to fit each model, what I meant was merely whether there might be a function to avoid the for loop in Python (129 electrodes * 150 sample points) .. not very urgent, really.

-Christian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/nipy-devel/attachments/20091116/47b0af18/attachment.html
```