def subtr_cellmeans(workd,subjslots):
"""
Subtract all cell means when within-subjects factors are present ...
i.e., calculate full-model using a D-variable.
"""
# Get a list of all dims that are source and between-subj
sourcedims = makelist(Bbetweens,Nfactors+1)
# Now, fix this list by mapping the dims from the original source
# to dims for a between-subjects variable (namely, subjslots)
transidx = range(len(subjslots.shape))[1:] + [0] # put subj dim at end
tsubjslots = N.transpose(subjslots,transidx) # get all Ss for this idx
tworkd = N.transpose(workd) # swap subj. and variable dims
errors = 1.0 * tworkd
if len(sourcedims) == 0:
idx = [-1]
loopcap = [0]
if len(sourcedims) <> 0:
btwsourcedims = map(Bscols.index,sourcedims)
idx = [0] * len(btwsourcedims)
idx[0] = -1 # compensate for pre-increment of 1st slot in incr()
# Get a list of the maximum values each factor can handle
loopcap = N.take(N.array(Nlevels),sourcedims)-1
### WHILE STILL MORE GROUPS, CALCULATE GROUP MEAN FOR EACH D-VAR
while incr(idx,loopcap) <> -1: # loop through source btw level-combos
mask = tsubjslots[idx]
thisgroup = tworkd*mask[N.NewAxis,:]
groupmns = amean(N.compress(mask,thisgroup),1)
### THEN SUBTRACT THEM FROM APPROPRIATE SUBJECTS
errors = errors - N.multiply.outer(groupmns,mask)
return errors
评论列表
文章目录