{"id":21587,"library":"momentchi2","title":"momentchi2","description":"A Python library for computing the cumulative distribution function (CDF) of a weighted sum of chi-squared random variables. Version 0.1.8 supports Imhof's method, Davies' method, and moment-based approximations. Developed by the PyPA, with monthly or less frequent releases.","status":"active","version":"0.1.8","language":"python","source_language":"en","source_url":"https://github.com/pypa/momentchi2","tags":["statistics","chi-squared","cdf","weighted-sum","imhof","davies"],"install":[{"cmd":"pip install momentchi2","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"The library is a single module; no submodules are exposed.","symbol":"momentchi2","correct":"import momentchi2"}],"quickstart":{"code":"import momentchi2\n\n# Example: CDF of a weighted sum of chi-squared variables\n# weights and degrees of freedom\ndf = [1, 2, 1]\nweights = [0.5, 0.3, 0.2]\nq = 1.5\n\n# Use Imhof's method\np = momentchi2.imhof(q, weights, df)\nprint(f\"CDF value: {p:.6f}\")","lang":"python","description":"Compute the CDF of a weighted sum of chi-squared random variables using Imhof's method. For other methods (e.g., Davies, moment-based), replace imhof with davies or moment_approximation."},"warnings":[{"fix":"Use import momentchi2 and call momentchi2.imhof(...) etc.","message":"The library function names differ from the original R package 'momentchi2'. Ensure you use Python function names: imhof, davies, moment_approximation, etc.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use momentchi2.imhof() instead of momentchi2.davies().","message":"The 'davies' method may be deprecated in future versions due to numerical stability issues. Prefer 'imhof' for reliable results.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure len(weights) == len(df). If df is a scalar, repeat it to match the number of weights.","message":"Weights and degrees of freedom vectors must be of equal length, otherwise an unhelpful ValueError is raised.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Check that len(weights) == len(df) and adjust accordingly.","cause":"Mismatched lengths of weights and df arrays.","error":"ValueError: The weights and degrees of freedom must have the same length"},{"fix":"Run pip install momentchi2 and ensure the correct Python environment is used.","cause":"The library is not installed or the package name is misspelled.","error":"ImportError: No module named 'momentchi2'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}