Welcome to pypsy’s documentation!

https://img.shields.io/travis/inuyasha2012/pypsy.svg https://coveralls.io/repos/github/inuyasha2012/pypsy/badge.svg?branch=master https://img.shields.io/pypi/v/psy.svg https://readthedocs.org/projects/python-psychometrics/badge/?version=latest

pypsy

中文

psychometrics package, including structural equation model, confirmatory factor analysis, unidimensional item response theory, multidimensional item response theory, cognitive diagnosis model, factor analysis and adaptive testing. The package is still a doll. will be finished in future.

unidimensional item response theory

models

  • binary response data IRT (two parameters, three parameters).
  • grade respone data IRT (GRM model)

Parameter estimation algorithm

  • EM algorithm (2PL, GRM)
  • MCMC algorithm (3PL)

Multidimensional item response theory (full information item factor analysis)

Parameter estimation algorithm

The initial value

The approximate polychoric correlation is calculated, and the slope initial value is obtained by factor analysis of the polychoric correlation matrix.

EM algorithm
  • E step uses GH integral.
  • M step uses Newton algorithm (sparse matrix is divided into non sparse matrix).
Factor rotation

Gradient projection algorithm

The shortcomings

GH integrals can only estimate low dimensional parameters.


Cognitive diagnosis model

models

  • Dina
  • ho-dina

parameter estimation algorithms

  • EM algorithm
  • MCMC algorithm
  • maximum likelihood estimation (only for estimating skill parameters of subjects)

Structural equation model

  • contains three parameter estimation methods(ULS, ML and GLS).
  • based on gradient descent

Confirmatory factor analysis

  • can be used for continuous data, binary data and ordered data.
  • based on gradient descent
  • binary and ordered data based on Polychoric correlation matrix.

Factor analysis

For the time being, only for the calculation of full information item factor analysis, it is very simple.

The algorithm

principal component analysis

The rotation algorithm

gradient projection


Adaptive test

model

Thurston IRT model (multidimensional item response theory model for personality test)

Algorithm

Maximum information method for multidimensional item response theory


Require

  • numpy
  • progressbar2

How to use it

install

pip install psy

See demo

TODO LIST

  • theta parameterization of CCFA
  • parameter estimation of structural equation models for multivariate data
  • Bayesin knowledge tracing (Bayesian knowledge tracking)
  • multidimensional item response theory (full information item factor analysis)
  • high dimensional computing algorithm (adaptive integral, etc.)
  • various item response models
  • cognitive diagnosis model
  • G-DINA model
  • Q matrix correlation algorithm
  • Factor analysis
  • maximum likelihood estimation
  • various factor rotation algorithms
  • adaptive
  • adaptive cognitive diagnosis
  • other adaption model
  • standard error and P value
  • code annotation, testing and documentation.

Installation

Stable release

To install pypsy, run this command in your terminal:

$ pip install pypsy

This is the preferred method to install pypsy, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for pypsy can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/inuyasha2012/pypsy

Or download the tarball:

$ curl  -OL https://github.com/inuyasha2012/pypsy/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use pypsy in a project:

import pypsy

API

psy package

Subpackages

psy.cat package
Submodules
psy.cat.tirt module
class psy.cat.tirt.BaseModel(slop, threshold, init_theta=None, score=None, iter_method=u'newton', sigma=None)[source]

Bases: object

gradient_ascent
newton

基于牛顿迭代的参数估计 :return: ndarray(int|float), 特质向量初值

prob(theta)[source]
score
solve
z(theta)[source]
class psy.cat.tirt.BaseProbitModel(slop, threshold, init_theta=None, score=None, iter_method=u'newton', sigma=None)[source]

Bases: psy.cat.tirt.BaseModel

info(theta)[source]
class psy.cat.tirt.BaseSimTirt(subject_nums, trait_size, model=u'bayes_probit', sigma=None, iter_method=u'newton', block_size=3, lower=1, upper=4, avg=0, std=1)[source]

Bases: object

MODEL = {u'bayes_probit': <class 'psy.cat.tirt.BayesProbitModel'>}
random_thetas

生成特质向量 :return: ndarray

class psy.cat.tirt.BayesProbitModel(slop, threshold, init_theta=None, score=None, iter_method=u'newton', sigma=None)[source]

Bases: psy.cat.tirt.BaseProbitModel

info(theta)[source]
class psy.cat.tirt.SimAdaptiveTirt(item_size, max_sec_item_size=10, *args, **kwargs)[source]

Bases: psy.cat.tirt.BaseSimTirt

item_bank
scores
sim()[source]
thetas
Module contents
psy.cdm package
Submodules
psy.cdm.irm module
class psy.cdm.irm.BaseEmDina(attrs, score=None)[source]

Bases: psy.cdm.irm.Dina

class psy.cdm.irm.BaseMcmcDina(thin=1, burn=3000, max_iter=10000, *args, **kwargs)[source]

Bases: psy.cdm.irm.Dina

class psy.cdm.irm.Dina(attrs, score=None)[source]

Bases: object

get_p(yita, no_slip, guess)[source]
get_yita(skills)[source]
item_size
class psy.cdm.irm.EmDina(guess_init=None, no_slip_init=None, max_iter=100, tol=1e-05, *args, **kwargs)[source]

Bases: psy.cdm.irm.BaseEmDina

em()[source]
class psy.cdm.irm.McmcDina(thin=1, burn=3000, max_iter=10000, *args, **kwargs)[source]

Bases: psy.cdm.irm.BaseMcmcDina

mcmc()[source]
class psy.cdm.irm.McmcHoDina(thin=1, burn=3000, max_iter=10000, *args, **kwargs)[source]

Bases: psy.cdm.irm.BaseMcmcDina

static get_skills_p(lam0, lam1, theta)[source]
mcmc()[source]
class psy.cdm.irm.MlDina(guess, no_slip, *args, **kwargs)[source]

Bases: psy.cdm.irm.BaseEmDina

solve()[source]
Module contents
psy.ctt package
Submodules
psy.ctt.ctt module
class psy.ctt.ctt.BaseCtt(scores)[source]

Bases: object

get_alpha_reliability()[source]
get_composite_reliability()[source]
class psy.ctt.ctt.BivariateCtt(scores)[source]

Bases: psy.ctt.ctt.BaseCtt

get_difficulty()[source]
get_discrimination()[source]
Module contents
psy.data package
Submodules
psy.data.data module
Module contents
psy.exceptions package
Submodules
psy.exceptions.cat module
exception psy.exceptions.cat.ItemParamError[source]

Bases: exceptions.Exception

Item Param Type Error

exception psy.exceptions.cat.IterMethodError[source]

Bases: exceptions.Exception

iter method error

exception psy.exceptions.cat.ScoreError[source]

Bases: exceptions.Exception

score error

exception psy.exceptions.cat.ThetaError[source]

Bases: exceptions.Exception

theta error

exception psy.exceptions.cat.UnknownModelError[source]

Bases: exceptions.Exception

unknown model

Module contents
exception psy.exceptions.ConvergenceError[source]

Bases: exceptions.Exception

no convergence

psy.fa package
Submodules
psy.fa.factors module
class psy.fa.factors.Factor(scores, factors_num)[source]

Bases: object

cor
loadings
mirt_loading
polycor
psy.fa.rotations module
class psy.fa.rotations.GPForth(init_loadings, method='varimax')[source]

Bases: object

solve()[source]
static varimax(l)[source]
Module contents
psy.irt package
Submodules
psy.irt.base module
class psy.irt.base.GuessLogitMixin[source]

Bases: psy.irt.base.LogitMixin

p(guess, *args, **kwargs)[source]
class psy.irt.base.GuessProbitMixin[source]

Bases: psy.irt.base.ProbitMixin

p(guess, *args, **kwargs)[source]
class psy.irt.base.LogitMixin[source]

Bases: object

p(z)[source]
class psy.irt.base.ProbitMixin[source]

Bases: object

p(z)[source]
class psy.irt.base.RaschZMixin[source]

Bases: object

z(threshold, theta)[source]
class psy.irt.base.ZMixin[source]

Bases: object

z(slop, threshold, theta)[source]
Parameters:
  • slop
  • threshold
  • theta
Returns:

psy.irt.grm module
class psy.irt.grm.Grm(scores=None, init_slop=None, init_threshold=None, max_iter=1000, tol=1e-05, gp_size=11)[source]

Bases: object

em()[source]
static get_gh_point(gp_size)[source]
static p(z)[source]
static z(slop, thresholds, theta)[source]
psy.irt.irm module
class psy.irt.irm.Irt(scores, link='logit', params_type='2PL', init_slop=None, init_threshold=None, max_iter=1000, tol=1e-05, *args, **kwargs)[source]

Bases: object

PARAMS_TYPE_TP = ('1PL', '2PL', '3PL')
fit()[source]
class psy.irt.irm.Mirt(dim_size, init_slop=None, init_threshold=None, max_iter=1000, tol=0.0001, *args, **kwargs)[source]

Bases: psy.irt.irm._BaseEmIrt, psy.irt.base.LogitMixin

em()[source]
static z(slop, threshold, theta)[source]
Module contents
psy.sem package
Submodules
psy.sem.ccfa module
psy.sem.ccfa.delta_i_ccfa(data, lam, step=0.01, max_iter=1000000, rdd=3, tol=1e-06)[source]
psy.sem.ccfa.get_irt_parameter(lam, thresholds, theta)[source]
psy.sem.ccfa.get_thresholds(data)[source]
psy.sem.cfa module
psy.sem.cfa.cfa(data, lam, step=0.01, max_iter=10000, rdd=3, tol=1e-07)[source]
psy.sem.sem module
psy.sem.sem.sem(data, y, x, lam_x, lam_y, beta, gamma, method=u'ml', step=0.1, max_iter=50000, tol=1e-07)[source]
Module contents
psy.settings package
Submodules
psy.settings.cat module
psy.settings.mirt module
Module contents
psy.utils package
Submodules
psy.utils.probs module
psy.utils.probs.get_log_beta_pd(no_slip, guess)[source]
psy.utils.probs.get_log_lognormal_pd(x)[source]
psy.utils.probs.get_log_normal_pd(x)[source]
psy.utils.probs.get_nodes_weights(dim_size)[source]
psy.utils.probs.inverse_logistic(y)[source]
psy.utils.probs.r4beta(shape1, shape2, a, b, size)[source]
psy.utils.randoms module
psy.utils.randoms.gen_item_bank(trait_size, item_size, block_size=3, lower=1, upper=4, avg=0, std=1)[source]

生成用于自适应测验的题库 :param trait_size: int :param item_size: int :param block_size: int :param lower: int|float :param upper: int|float :param avg: int|float :param std: int|float :return:

psy.utils.randoms.random_params(item_dt, trait_size, block_size=3, lower=1, upper=4, avg=0, std=1)[source]

生成随机参数 :param item_dt: dict,试题字典,例如题块为3的0:1,1:0,2:2}代表第1题的第一个陈述测的是特质1, 第二个陈述测的是特质0,第三个陈述测的是特质2 :param trait_size: int :param block_size: int :param lower: int|float :param upper: int|float :param avg: int|float :param std: int|float :return:

psy.utils.tools module
class psy.utils.tools.cached_property(func, name=None)[source]

Bases: object

# 从django抄的详见同名函数

Module contents

Module contents

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/inuyasha2012/pypsy/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

pypsy could always use more documentation, whether as part of the official pypsy docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/inuyasha2012/pypsy/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up pypsy for local development.

  1. Fork the pypsy repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/pypsy.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv pypsy
    $ cd pypsy/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 pypsy tests
    $ python setup.py test or py.test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
  3. The pull request should work for Python 2.7, 3.4, 3.5 and 3.6, and for PyPy. Check https://travis-ci.org/inuyasha2012/pypsy/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ py.test tests.test_pypsy

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags

Travis will then deploy to PyPI if tests pass.

History

0.0.1 (2018-09-18)

  • First release on PyPI.

Indices and tables