Welcome to pypsy’s documentation!¶
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
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
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), 特质向量初值
-
score
¶
-
solve
¶
-
-
class
psy.cat.tirt.
BaseProbitModel
(slop, threshold, init_theta=None, score=None, iter_method=u'newton', sigma=None)[source]¶ Bases:
psy.cat.tirt.BaseModel
-
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
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.
EmDina
(guess_init=None, no_slip_init=None, max_iter=100, tol=1e-05, *args, **kwargs)[source]¶ Bases:
psy.cdm.irm.BaseEmDina
-
class
psy.cdm.irm.
McmcDina
(thin=1, burn=3000, max_iter=10000, *args, **kwargs)[source]¶ Bases:
psy.cdm.irm.BaseMcmcDina
-
class
psy.cdm.irm.
McmcHoDina
(thin=1, burn=3000, max_iter=10000, *args, **kwargs)[source]¶ Bases:
psy.cdm.irm.BaseMcmcDina
-
class
psy.cdm.irm.
MlDina
(guess, no_slip, *args, **kwargs)[source]¶ Bases:
psy.cdm.irm.BaseEmDina
Module contents¶
psy.ctt package¶
Submodules¶
Module contents¶
psy.exceptions package¶
Submodules¶
psy.irt package¶
Submodules¶
psy.irt.base module¶
-
class
psy.irt.base.
GuessLogitMixin
[source]¶ Bases:
psy.irt.base.LogitMixin
-
class
psy.irt.base.
GuessProbitMixin
[source]¶ Bases:
psy.irt.base.ProbitMixin
psy.irt.grm module¶
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
-
LINK_DT
= {'logit': <class 'psy.irt.irm._LogitIrt'>, 'probit': <class 'psy.irt.irm._ProbitIrt'>}¶
-
PARAMS_TYPE_TP
= ('1PL', '2PL', '3PL')¶
-
Module contents¶
psy.sem package¶
Submodules¶
psy.sem.ccfa module¶
psy.sem.cfa module¶
psy.sem.sem module¶
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.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¶
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.
Fork the pypsy repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/pypsy.git
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
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
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.
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
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- 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.
- 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.
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.