psycomm
Subject-level community detection on psychometric questionnaire data.
psycomm is the Python implementation of the pipeline described in the paper
Community detection in psychometric questionnaire data (Armanetti et al.,
forthcoming). Given a subject-by-item response matrix X, the package
builds a subject-subject similarity matrix in factor (or item) space, removes
a null model from it, runs a modularity-maximisation algorithm to detect
communities of respondents, and validates the resulting partition via
bootstrap consensus and significance metrics (cloud entropy at variable k,
histogram overlap, modularity).
Features
- Dataset generation — mixture-of-FA, mixture-of-binomials, structured FA, dominant-factor (bifactor); reproducible seeds.
- Loaders for the 15 questionnaire datasets used in the paper (
big5,hexaco,sd3,mach,acme,iri,ei,dass,cfcs,hsns,msscq,rwas,gcbs,pwe,empathy). - Similarity in item space or in factor space (FA / PCA) with eight
metrics (
sqeuclideandefault,euclidean,l1,cosine,covariance,mahalanobis,percentile_l1,percentile_l2). - Null models for the coupling matrix: Newman / configuration model and market-mode removal.
- Detection algorithms: Leiden (default), in-house multi-level Louvain, Potts with simulated annealing.
- Reshuffling null for the data matrix (column-wise permutation, Gaussian copula, FA-generative).
- Consensus clustering with permutation-benchmark residualisation.
- Metrics: loose / strict cloud entropy, variable-
kentropy curve, histogram overlap, modularity, eigenvector / community entropy. - Visualisation helpers for similarity matrices, spectra, consensus matrices, PCA embeddings and entropy curves.
Installation
pip install psycomm
leidenalg and igraph are required for the default Leiden detector and
are installed automatically.
Quick start
import psycomm as pc
# 1. Generate or load data
X, labels_true, info = pc.generate_mixture_fa(
N=800, M=60, q=6, K=4, F=4, sigma_within=1.0, seed=0,
)
# or
# X = pc.load_dataset("rwas", "/path/to/datasets")
# 2. Similarity in factor space (squared Euclidean, as in the paper)
S, scores, fa = pc.compute_similarity_fa(X, n_factors=4, metric="sqeuclidean")
# 3. Community detection: market-mode null + Leiden
labels, Q, S_clean = pc.detect_communities(
S, null_model="marketmode", algorithm="leiden",
)
print(f"detected K = {len(set(labels))}, Q = {Q:.3f}")
# 4. Significance metrics
eigvals, eigvecs = pc.compute_spectrum(S, neig=10)
K = len(set(labels))
H_loose = pc.cloud_entropy_loose(eigvecs, K)
H_strict = pc.cloud_entropy_strict(eigvecs, K, labels)
overlap = pc.histogram_overlap(S, labels)
mod = pc.modularity(S_clean, labels)
print(H_loose, H_strict, overlap, mod)
# 5. Reshuffling null for a permutation test
Xn = pc.reshuffle_subjects(X)
Sn, _, _ = pc.compute_similarity_fa(Xn, n_factors=4)
labels_n, Q_n, _ = pc.detect_communities(Sn, null_model="marketmode")
Public API
# datasets
generate_mixture_fa, generate_mixture_binomial,
generate_structured_ordinal_fa, generate_dominant_factor,
load_dataset, get_number_constructs, SUPPORTED_DATASETS
# similarity
compute_similarity, compute_similarity_fa, fit_factor_analysis,
AVAILABLE_METRICS
# community detection
detect_communities, leiden_communities, louvain_communities, louvain_best,
potts_communities, newman_null, marketmode_null, compute_spectrum
# consensus
consensus_clustering, compute_permuted_benchmark,
final_communities_from_consensus, consensus_diagnostics
# reshuffling nulls
reshuffle_subjects, gaussian_copula_null, fa_generative_null
# metrics
cloud_entropy, cloud_entropy_batch, cloud_entropy_loose, cloud_entropy_strict,
cloud_entropy_k, eigenvector_entropy, community_entropy, histogram_overlap,
modularity, average_community_size, default_k_loose, default_k_strict
# visualisation
viz.plot_similarity, viz.plot_spectrum, viz.plot_consensus_matrix,
viz.plot_community_pca, viz.plot_entropy_curve, viz.plot_similarity_histograms
Citation
If you use psycomm in a publication, please cite both the package and the
underlying paper:
@software{psycomm,
author = {Armanetti, Arianna},
title = {psycomm: community detection in psychometric data},
year = {2026},
url = {https://github.com/ariannaarmanetti/psycomm},
}
@article{armanetti2026community,
author = {Armanetti, Arianna and Cecchetti, Luca and Fried, Eiko and Garlaschelli, Diego and Ibáñez-Berganza, Miguel}
title = {Community detection in subject-subject networks from psychometrics data},
year = {2026},
note = {Manuscript in preparation},
}
Contacts
Feel free to contact arianna.armanetti@imtlucca.it for information.
License
See LICENSE. Free to use with attribution to both the package and the reference paper.
Tutorials
A walk-through notebook is available in tutorials/, covering:
generating synthetic data, loading a real dataset, computing similarities,
running the full detection pipeline, validating partitions with permutation
tests, and visualising results.
Metadata
Release files for psycomm 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| psycomm-1.1.1.tar.gz | 28.0 kB | Without provenance | Details for psycomm-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| psycomm-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for psycomm-1.1.1-py3-none-any.whl |
Total release size: 57.2 kB
Release files / psycomm-1.1.1.tar.gz
| Download URL | psycomm-1.1.1.tar.gz |
|---|---|
| Size | 28.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67e6339784f8732405e1840609844f82a8c3759431db8cf445b795648ac0d270
|
|
BLAKE2b-256 checksum How to use checksums |
04dc5de042b0b986b517e777a7069ffdb087319a3ab03adb8d99d9616a79abc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / psycomm-1.1.1-py3-none-any.whl
| Download URL | psycomm-1.1.1-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bae6849ffa412f1ca85dfb307c38ab3cade470a9d0d49e1a83d3bbddf7badb97
|
|
BLAKE2b-256 checksum How to use checksums |
03445ed7c98628b9b7b2075adc5bc871348b8caa8bccaea4d4bd8f1aff382066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for psycomm 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.