Skip to main content

Robust Linear Matching Algorithm (RLMA) for variable association detection

Project description

rlma

Robust Linear Matching Algorithm (RLMA)

A Python package to detect and quantify relationships between variables using a novel linear matching algorithm that:

  • Groups variables by categorical levels based on mean and standard deviation
  • Compares independent variables (IVs) and dependent variables (DVs) via category matching
  • Supports binary, continuous, and multivariate variables
  • Includes permutation testing for significance
  • Allows composite variable analysis via PCA, Ridge, or Random Forest predictions

Features

  • Simple and intuitive method to detect relationships beyond classic linear correlation
  • Handles different types of variables: continuous, categorical, and binary
  • Permutation test to estimate the significance of the relationship
  • Batch processing for multiple IVs with ranking by relationship strength
  • Composite analysis to handle many IVs in high-dimensional data

Installation

Install the package using pip:

pip install rlma

Usage Examples

import pandas as pd from rlma import compute_RMI, permutation_test, batch_pairwise_rlma, composite_rlma

Sample data for demonstration

data = { 'burnout': [4.87, 4.83, 3.83, 4.31, 4.73, 1.41, 2.80, 4.50], 'anxiety': [4.80, 4.55, 4.30, 4.30, 3.95, 1.25, 4.85, 4.00], 'metacognition': [2.60, 2.50, 4.20, 4.16, 2.93, 1.76, 3.56, 4.90], }

X = pd.DataFrame(data) y = X['anxiety'] # For example, treat anxiety as dependent variable

1. Compute RLMA between one IV and DV

rmi_value = compute_RMI(X['burnout'], y) print(f"RMI between burnout and anxiety: {rmi_value:.4f}")

2. Perform permutation test for significance

perm_results = permutation_test(X['burnout'], y, n_perm=2000) print(f"Permutation test p-value: {perm_results['emp_p']:.4f}")

3. Run batch RLMA on all IVs against anxiety

batch_results = batch_pairwise_rlma(X, y, n_perm=1000) print("Batch RLMA results:") print(batch_results)

4. Composite RLMA using ridge regression to combine IVs predicting anxiety

comp_result = composite_rlma(X, y, method='ridge', n_perm=1000) print(f"Composite RMI: {comp_result['rmi_result']:.4f}") print(f"Composite permutation p-value: {comp_result['perm_result']['emp_p']:.4f}") API Reference compute_RMI(X, y, num_categories=3, alpha=0.5) Calculate the Robust Linear Matching Index between variables X and y.

X, y: pandas Series or numpy arrays

num_categories: Number of categories to divide data into (default 3) alpha: Weight for near-matches (default 0.5) Returns a float between 0 and 1 indicating the strength of the relationship.

permutation_test(X, y, n_perm=1000) Perform a permutation test to assess the significance of the RLMA relationship. n_perm: Number of permutations (default 1000)

Returns a dictionary with empirical p-value under 'emp_p'.

batch_pairwise_rlma(X_df, y, n_perm=1000) Apply RLMA to all columns of X_df against y, including permutation testing.

Returns a pandas DataFrame ranking IVs by RLMA strength and significance.

composite_rlma(X_df, y, method='ridge', n_perm=1000) Generate a composite IV prediction using PCA, Ridge, or Random Forest, then compute RLMA.

method: One of 'pca', 'ridge', 'rf' (default 'ridge')

Returns a dict with RLMA value and permutation test result.

Contributing

Contributions, issues, and feature requests are welcome! Please open an issue or pull request.

License

This project is licensed under the MIT License.

Author

Francis Jemisiham Amofa Email: jemisihamamofa@gmail.com GitHub: https://github.com/francisamofa

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rlma-0.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rlma-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file rlma-0.2.0.tar.gz.

File metadata

  • Download URL: rlma-0.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for rlma-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c121245c3734d6dc4043e5b572dd2118a1482eaf6efd9c82c8c616e947bc09c6
MD5 726cca410ea6bbbacb0f3ac56d77c876
BLAKE2b-256 055478292e860e0dddf048e142a3b67b2cdd50644ecc3c8f4eb2d34f29b3ad39

See more details on using hashes here.

File details

Details for the file rlma-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rlma-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for rlma-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 448bfb74b539e964e346a1726d2ecc0e7b8db3ada2aba135e5393c0762ad6fe0
MD5 0e41ffba63fbce337e567b033c5ebbf8
BLAKE2b-256 8c5d8028fd47b47bbd139f9f449c2e441b89cf30dfbb50c4528991c797986903

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page