我正在尝试创建注意力网络任务的Python版本。将此作为参考(第3页):http://www.researchgate.net/publication/7834908_The_Activation_of_Attentional_NetworksPython因素级别组合
我总共有216个试验。其中一半将是“一致的”,一半是“不一致的”。此外,216的三分之一将是“nocue”,另外三分之一将是“中心”,并且最后三分之一将是“空间的”。这216个试验中的每一个将是上述的一些组合(例如全等 - 空间的,不一致的,无)
这是我如何创造这些试验现在:
import pandas as pd
import numpy as np
import random
#set number of trials
numTrials = 216
numCongruent = numTrials/2
numCue = numTrials/3
#create shuffled congruency conditions
congruent = ["congruent"] * numCongruent
incongruent = ["incongruent"] * numCongruent
congruentConditions = congruent + incongruent
random.shuffle(congruentConditions)
#create shuffled cue conditions
noCue = ["none"] * numCue
centerCue = ["center"] * numCue
spatialCue = ["spatial"] * numCue
cueConditions = noCue + centerCue + spatialCue
random.shuffle(cueConditions)
#put everything into a dataframe
df = pd.DataFrame()
congruentArray = np.asarray(congruentConditions)
cueArray = np.asarray(cueConditions)
df["congruent"] = congruentArray
df["cue"] = cueArray
print df
2个问题...
- 现在,这个工作,但其中重要的一点是确保均匀分配水平的重刑。
例如,我需要确保所有的“一致”试验有相同数量的“nocue”,“中心”和“空间”试验。相反,例如,所有的“nocue”试验都需要半数的“一致”和“不一致”试验。
鉴于我随机洗牌的条件,目前无法保证。这甚至会超过无限的样本量,但这不是这种情况。
我该如何确保平等分配?
我已经采取了看笛卡尔乘积(https://docs.python.org/2/library/itertools.html#itertools.product),但我不完全,这将有助于我实现平等问题
- 一旦上述已然后我需要确保在最后的洗牌列表中,每个试验类型(例如全等空间)在列表顺序中遵循相同次数的相同次数
我一直在困惑你的问题的第二部分,这是一个更深入(和更有趣!)的问题。这取决于你,但是我认为如果你把它作为一个单独的问题发布,你会有更好的机会得到一个好的答案。理想情况下,你可以用更一般的方式来构成它(例如*“我怎样才能生成随机序列,其中每个独特的项目跟随彼此独特的项目相同的次数?”*)。 –
好点。我会把这个问题分解成一个单独的问题 – Simon