python和心理学

Python is gaining popularity in many fields of science. This means that there also are many applications and libraries specifically for use in Psychological research. For instance, there are packages for collecting data & analysing brain imaging data. In this post, I have collected some useful Python packages for researchers within the field of Psychology and Neuroscience. I have used and tested some of them but others I have yet to try.

Python在科学的许多领域都越来越流行。 这意味着,还有许多专门用于心理学研究的应用程序和库。 例如,有用于收集数据和分析脑成像数据的软件包。 在这篇文章中,我收集了一些有用的Python软件包,供心理学和神经科学领域的研究人员使用。 我已经使用和测试了其中一些,但其他我还没有尝试过。

实验构建应用程序/库 (Experiment building applications/libraries)

Importing expyriment
进口实验

Expyriment is a Python library in which makes the programming of Psychology experiments a lot easier than using Python. It contains classes and methods for creating fixation cross’, visual stimuli, collecting responses, etc.

Expyriment是一个Python库,在该库中,心理学实验的编程比使用Python容易得多。 它包含用于创建交叉注视,视觉刺激,收集响应等的类和方法。

Modular Psychophysics  is a collection of tools that aims to implement a modular approach to Psychophysics. It enables us to write experiments in different languages. As far as I understand, you can use both MATLAB and R to control your experiments. That is, the timeline of the experiment can be carried out in another language (e.g., MATLAB).

模块化心理物理学是旨在实现模块化心理物理学方法的工具的集合。 它使我们能够用不同的语言编写实验。 据我了解,您可以同时使用MATLAB和R来控制实验。 也就是说,实验的时间表可以用另一种语言(例如MATLAB)执行。

However, it seems like the experiments are created using Python. Your experiments can be run both locally and over networks. Have yet to test this out.

但是,似乎实验是使用Python创建的。 您的实验既可以在本地运行,也可以通过网络运行。 尚未对此进行测试。

OpenSesame  is a Python application. Using OpenSesame one can create Psychology experiments. It has a graphical user interface (GUI) that allows the user to drag and drop objects on a timeline. More advanced experimental designs can be implemented using inline Python scripts.

OpenSesame是一个Python应用程序。 使用OpenSesame可以创建心理学实验。 它具有图形用户界面(GUI),允许用户在时间线上拖放对象。 可以使用内联Python脚本实现更高级的实验设计。

PsychoPy is also a Python application for creating Psychology experiments. It comes packed with a GUI but the API can also be used for writing Python scripts. I have written a bit more thoroughly about PsychoPy: PsychoPy.

PsychoPy还是用于创建心理学实验的Python应用程序。 它带有GUI,但API也可用于编写Python脚本。 我已经对PsychoPy: PsychoPy进行了更详尽的介绍。

PsychoPy GUI for a drag-and-drop creation of experiments.
PsychoPy GUI,用于拖放式创建实验。

I have written more extensively on Expyriment, PsychoPy, Opensesame, and some other libraries for creating experiment in my post Python apps and libraries for creating experiments.

我在Post Python应用程序和用于创建实验的库中编写了关于Expyriment,PsychoPy,Opensesame和其他一些用于创建实验的库的文章,内容更加广泛。

数据分析 (Data analysis)

心理学与神经科学 (Psychology and Neuroscience)

PsyUtils “The psyutils package is a collection of utility functions useful for generating visual stimuli and analysing the results of psychophysical experiments. It is a work in progress, and changes as I work. It includes various helper functions for dealing with images, including creating and applying various filters in the frequency domain.”

PsyUtils “ psyutils软件包是一组实用程序功能,可用于生成视觉刺激并分析心理物理实验的结果。 这是一项正在进行的工作,并且随着我的工作而变化。 它包括用于处理图像的各种辅助功能,包括在频域中创建和应用各种滤波器。”

Psisignifit is a toolbox that allows you to fit psychometric functions. Further, hypotheses about psychometric data can be tested. Psisignfit allows for full Bayesian analysis of psychometric functions that includes Bayesian model selection and goodness of fit evaluation among other great things.

Psisignifit是一个工具箱,可让您安装心理功能。 此外,可以检验有关心理测验数据的假设。 Psisignfit允许对心理测量功能进行完整的贝叶斯分析,包括贝叶斯模型选择和拟合优度评估等其他重要方面。

Pygaze is a Python library for eye-tracking data & experiments. It works as a wrapper around many other Python packages (e.g., PsychoPy, Tobii SDK). Pygaze can also, through plugins, be used from within OpenSesame.

Pygaze是一个用于跟踪数据和实验的Python库。 它可以作为许多其他Python软件包(例如PsychoPy,Tobii SDK)的包装。 Pygaze也可以通过插件在OpenSesame中使用。

General Recognition Theory (GRT) is a fork of a MATLAB toolbox. GRT is ” a multi-dimensional version of signal detection theory.” (see link for more information).

通用识别理论(GRT)是MATLAB工具箱的分支。 GRT是“信号检测理论的多维版本”。 (请参阅链接以获取更多信息)。

MNE is a library designed for processing electroencephalography (EEG) and magnetoencephalography (MEG) data. Collected data can be preprocessed and denoised. Time-frequency analysis and statistical testing can be carried out. MNE can also be used to apply some machine learning algorithms. Although, mainly focused on EEG and MEG data some of the statistical tests in this library can probably be used to analyse behavioural data (e.g., ANOVA).

MNE是一个设计用于处理脑电图(EEG)和磁脑电图(MEG)数据的库。 收集的数据可以进行预处理和去噪。 可以进行时频分析和统计测试。 MNE也可以用于应用某些机器学习算法。 尽管主要集中于EEG和MEG数据,但是该库中的某些统计测试可能可以用来分析行为数据(例如ANOVA)。

Kabuki is a Python library for effortless creation of hierarchical Bayesian models. It uses the library PyMC. Using Kabuki you will get formatted summary statistics, posterior plots, and many more. There is, further, a function to generate data from a formulated model. It seems that there is an intention to add more commonly used statistical tests (i.e., Bayesian ANOVA) in the future!

Kabuki是一个Python库,用于轻松创建分层贝叶斯模型。 它使用库PyMC 。 使用Kabuki,您将获得格式化的摘要统计信息,后验图等等。 此外,还有一个从公式化模型生成数据的功能。 似乎打算在将来添加更多常用的统计检验(即,贝叶斯ANOVA)!

NIPY: “Welcome to NIPY. We are a community of practice devoted to the use of the Python programming language in the analysis of neuroimaging data”. Here different packages for brain imaging data can be found.

NIPY :“欢迎来到NIPY。 我们是一个致力于在神经影像数据分析中使用Python编程语言的实践社区”。 在这里可以找到不同的大脑成像数据包。

一般 (General)

Although, many of the above libraries probably can be used within other research fields there are also more libraries for pure statistics & visualisation.

尽管上述许多库可能可以在其他研究领域中使用,但也有更多的库用于纯统计和可视化。

描述性和参数统计 (Descriptive and parametric statistics)

PyMVPA is a Python library for MultiVariate Pattern Analysis. It enables statistical learning analyses of big data.

PyMVPA是用于多模式分析的Python库。 它可以对大数据进行统计学习分析。

Pandas is a Python library for fast, flexible and expressive data structures. Researchers and analysists with an R background will find Pandas data frame objects very similar to Rs. Data can be manipulated, summarised, and some descriptive analysis can be carried out (e.g., see Descriptive Statistics Using Python for some examples using Pandas).

Pandas是一个Python库,用于快速,灵活和富有表现力的数据结构。 具有R背景的研究人员和分析人员将发现Pandas数据框对象与Rs非常相似。 可以对数据进行操作,汇总和执行一些描述性分析(例如,有关使用Pandas的示例,请参见使用 Python进行描述性统计 )。

Statsmodels is a Python library for data exploration, estimation of statistical models, and statistical tests. An extensive list of descriptive statistics, statistical tests, plotting functions, and result statistics are available for different types of data and each estimator. Among many methods regression, generalized linear, and non-parametric tests can be carried out using statsmodels.

Statsmodels是一个Python库,用于数据探索,统计模型估计和统计测试。 描述性统计信息,统计检验,绘图功能和结果统计信息的大量列表适用于不同类型的数据和每个估计量。 在许多方法中,可以使用statsmodels进行回归,广义线性和非参数检验。

 

Pyvttbl is a library for creating Pivot tables. One can further process data and carry out statistical computations using Pyvttbl. Sadly, it seems like it is not updated anymore and is not compatible with other packages (e.g., Pandas). If you are interested in how to carry out repeated measures ANOVAs in Python this is a package that enables these kind of analysis (e.g., see Repeated Measures ANOVA using Python and Two-way ANOVA for Repeated Measures using Python).

Pyvttbl是用于创建数据透视表的库。 可以使用Pyvttbl进一步处理数据并进行统计计算。 可悲的是,它似乎不再更新了,并且与其他软件包(例如Pandas)也不兼容。 如果您对如何在Python中执行重复测量ANOVA感兴趣,则可以使用该软件包进行此类分析(例如,请参阅使用Python的重复测量ANOVA和使用Python 的重复测量进行双向ANOVA )。

可视化 (Visualisation)

There are many Python libraries for visualisation of data. Below are the ones I have worked with. Note, pandas and statsmodels also provides methods for plotting data. All three libraries are compatible with Pandas which makes data manipulation and visualisation very easy.

有很多Python库可用于数据可视化。 以下是我曾合作过的人。 注意,pandas和statsmodels还提供了绘制数据的方法。 这三个库都与Pandas兼容,这使得数据操作和可视化变得非常容易。

Boxplot made using Seaborn.
使用Seaborn制作的箱线图。

Matplotlib is a package for creating two-dimensional plots.

Matplotlib是用于创建二维图的软件包。

Seaborn is a library based on Matplotlib. Using seaborn you can create ready-to-publish graphis (e.g., see the Figure below for a boxplot on some response time data).

Seaborn是基于Matplotlib的库。 使用seaborn,您可以创建准备发布的图形(例如,有关某些响应时间数据的箱形图,请参见下图)。

Ggplot is a visualisation library based on the R package Ggplot2. That is, if you are familiar with R and Ggplot2 transitioning to Python and the package Ggplot will be easy.

Ggplot是基于R包Ggplot2的可视化库。 也就是说,如果您熟悉R和Ggplot2的过渡到Python,并且Ggplot包将很容易。

Many of the libraries for analysis and visualisation can be installed separately and, more or less, individually . I do however recommend that you install a scientific Python distribution. This way you will get all you need (and much more) by one click (e.g., Pandas, Matplotlib, NumPy, Statsmodels, Seaborn). I suggest you have a look at the distributions Anaconda or Python(x, y). Note, that installing Python(x, y) will give you the Python IDE Spyder.

许多用于分析和可视化的库可以分别安装,或多或少单独安装。 但是,我建议您安装科学的Python发行版。 这样,您只需单击一下即可获得所需的一切(以及更多)(例如,Pandas,Matplotlib,NumPy,Statsmodels,Seaborn)。 我建议您看看Anaconda或Python(x,y)的分布。 请注意,安装Python(x,y)将为您提供Python IDE Spyder。

The last Python package for Psychology I am going to list is PsychoPy_ext. Although, PsychoPy_ext may be considered a library for building experiments it seems like the general aim behind the package is to make reproducible research easier. That is, analysis and plotting of the experiments can be carried out. I also think it is interesting that there seems to be a way to autorun experiments (a neat function I know that e-prime have, for instance).

我要列出的最后一个用于Psychology的Python软件包是PsychoPy_ext 。 尽管PsychoPy_ext可以被认为是用于构建实验的库,但似乎该软件包背后的总体目标是使可重复的研究更加容易。 即,可以进行实验的分析和绘制。 我也认为有趣的是,似乎有一种方法可以自动运行实验(例如,我知道e-prime具有一个简洁的功能)。

翻译自: https://www.pybloggers/2016/06/best-python-libraries-for-psychology-researchers/

python和心理学

更多推荐

python和心理学_心理学研究人员的最佳Python库