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.1.0.tar.gz (5.3 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.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rlma-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5906da6a3a1b41522bf5deaa259e1367b2c9c2bad4343c49f3b0d0899019f279
MD5 8125d194391ed872f5706305397b7680
BLAKE2b-256 d5ae8b53669a31a7fd9c03aa8071a3fcb8a6dbbba1ab6073af918e9a20c09900

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rlma-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb5ec2378826657cd06c84fb27cc3dbb2fce4ac7f0ce9490bdf56f56ab2276fb
MD5 073c493f9149b23d307692b12b57a86a
BLAKE2b-256 a9b505fbdd68f3b13e3c90206a1ee94e64ae7ef2b23048d9f833716f1ec50cba

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