Metadata-Version: 2.5
Name: pysemforge
Version: 0.1.0
Summary: Structural Equation Modeling for Python - closing the R-Python gap (lavaan-compatible, native multigroup & measurement invariance, graphviz-free path diagrams)
Project-URL: Homepage, https://github.com/RachelChow/pysemforge
Project-URL: Repository, https://github.com/RachelChow/pysemforge.git
Project-URL: Issues, https://github.com/RachelChow/pysemforge/issues
Author: pysemforge contributors
License: MIT
License-File: LICENSE
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Requires-Dist: matplotlib>=3.7
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: scipy>=1.11
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: jupyter; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# pysemforge

**Structural Equation Modeling for Python — closing the R-Python gap for behavioral and econometric modeling.**

> A Python-native SEM/CFA package inspired by **lavaan** (syntax) and **semTools** (multigroup + measurement invariance), with a **graphviz-free path diagram** backend.

---

## Why pysemforge?

Python has mature estimation backends (e.g. semopy), but still lacks a single package that combines:

| Capability | R (lavaan + semTools) | Python (semopy / pySEM) | **pysemforge** |
|---|---|---|---|
| lavaan-style syntax | ✅ | partial | ✅ |
| CFA / path / mediation | ✅ | partial | ✅ |
| Multigroup analysis | ✅ native | ❌ not native | ✅ **native** |
| Measurement invariance (configural → metric → scalar) | ✅ `semTools` | ❌ missing | ✅ **one-liner** |
| Partial invariance | ✅ `semTools` | ❌ | ✅ |
| Ordinal / WLSMV | ✅ | limited | ✅ |
| Robust ML (MLR) + fit-index CIs | ✅ | partial | ✅ |
| Path diagrams (no graphviz, publication-ready) | `lavaanPlot` | ⚠️ needs graphviz | ✅ **matplotlib backend** |

The two highlighted rows are the real gaps this package targets — so you **stay in Python end-to-end**.

---

## Quick Start

```python
import pandas as pd
from pysemforge import Model

# 1) lavaan-compatible syntax
syntax = """
    visual =~ x1 + x2 + x3
    textual =~ x4 + x5 + x6
    speed =~ x7 + x8 + x9
"""

model = Model(syntax)
result = model.fit(data)          # a pandas DataFrame of your indicators
print(result.summary())

# 2) Path diagram (no graphviz needed)
model.plot("sem_path.png", standardized=True)

# 3) Multigroup + measurement invariance (the headline feature)
inv = model.measurement_invariance(data, group_col="gender")
print(inv.summary())
inv.plot("invariance.png")
```

---

## Install

```bash
pip install pysemforge
```

For the latest development version:

```bash
git clone https://github.com/your-username/pysemforge.git
cd pysemforge
pip install -e .
```

---

## Features

- **lavaan-compatible syntax** — `=~`, `~`, `~~`, `~1`, `==`, comments, group blocks
- **CFA / structural regression / mediation** as first-class models
- **Estimators** — ML, MLR (robust SE), WLSMV (polychoric for ordinal data)
- **Native multigroup** analysis with equality constraints
- **Measurement invariance** — fully automated `configural → metric → scalar` ladder with Δχ² / ΔCFI / ΔRMSEA decisions (R `semTools` parity)
- **Partial invariance** — build-up / tear-down of non-invariant parameters
- **Fit indices** — χ², CFI, TLI, RMSEA (+90% CI), SRMR
- **graphviz-free diagrams** — publication-quality path plots via matplotlib (no system dependencies)
- **pandas / NumPy / SciPy** first-class interoperability

---

## Measurement Invariance Example

```python
inv = model.measurement_invariance(data, group_col="group")

# Access each level's fit
inv.levels["configural"]
inv.levels["metric"]
inv.levels["scalar"]

# Pairwise comparisons (Δχ², ΔCFI, decision)
inv.comparisons
```

The returned object mirrors **`semTools::measurementInvariance()`** output, so R users feel at home.

---

## Documentation & Publishing

- Source: https://github.com/your-username/pysemforge
- Docs: https://pysemforge.readthedocs.io
- Issues: https://github.com/your-username/pysemforge/issues

**Publish to PyPI** (main release target):

```bash
pip install build twine
python -m build
twine check dist/*
twine upload --repository testpypi dist/*   # test first
twine upload dist/*                         # then production
```

---

## Roadmap (post-MVP)

Latent growth curve models · Bayesian estimation · complex survey designs · full `lavaanPlot`-parity plotting.

---

## License

MIT — see [LICENSE](LICENSE).
