Skip to main content

A library providing frequently used functions in data analysis for YESlab members and other researchers

Project description

yescarpenter

This library provides some frequent used functions for YESlab members and other researchers, including data processing and analyses

Installation

From PyPI

Users can install it using pip:

pip install yescarpenter

Functions

perform_pca

This function leverages scikit-learn to perform a tailored PCA analysis (e.g., with rotation to maximize variance)

Usage:

import pandas as pd
from yescarpenter import perform_pca

# Create a sample DataFrame
data = pd.DataFrame({
    'feature1': [1, 2, 3, 4],
    'feature2': [2, 3, 4, 5],
    'feature3': [3, 4, 5, 6]
})

# Perform PCA with 2 components
loadings, explained_variance, components = perform_pca(data, n_components=2)

print("Loadings:\n", loadings)
print("Explained Variance:\n", explained_variance)
print("Components:\n", components)

create_scree_plot

This function creates a scree plot to visualize the explained variance of each principal component.

scree_plot(explained_variance, n_components)

pc_plot

Create a plot to visualize the PCA loadings.

pc_plot(loadings, df)

construct_RDM

For IS-RSA. Construct the Representational Dissimilarity Matrix(RDM) from the data.

Usage:

construct_RDM(data, n_target, method = "cityblock")
  • data: The input data for RDM construction.
  • method: cityblock, or spearman

do_rsa

Calculate the Spearman correlation between two RDMs(lower triangle) and do permutation

Usage:

do_RSA(rdm1, rdm2, n_perm=1000)

permutation_histogram

Plot the histogram of null distribution, with the observed value and p-value marked.

Usage:

permutation_histogram(r, perm_r)
  • r: The observed value.
  • perm_r: The null distribution, which consists of the iterated surrogated values

maximal_permutation_test

This fuction is used to address multiple comparison, which provides an alternative of Bonferroni correction.

Usage:

[perm_r, perm_p, observed_r] = maximal_permutation_test(data, iv_single, iv_multiplecomp, nperm)
  • data: For IS-RSA, each row is a subject, while each column is a variable.
    For example, if you have 20 subjects and 5 variables, the shape of data is (20, 5).
    • iv_single: the independent variable that will be shuffled and compare across iv_multiplecomp
    • iv_multiplecomp: the independent variable that are inter-related and elicit the multiple comparison problem
    • n_perm: number of permutation

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

yescarpenter-0.2.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

yescarpenter-0.2.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for yescarpenter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 181f3c989ee99ab430aa088bea7a55278538806fbd815e4cfd6cba58b61f90cd
MD5 1aa69f67f3d4de9bb8ab06493d0f64e6
BLAKE2b-256 ccd09dc06d388de57de4c8ae034232eedb1fd6dcce3a3394a752eeb46ab6a9d6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for yescarpenter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 085086d64e2fba77c83575debc6825e248b773318baff3b3e71f732d594cb849
MD5 61e0fd6a67eb8fb0c68c768711292653
BLAKE2b-256 0ce7362c208d2e6215b65c70f44d84d83ab134a50afcc68fecfabb1c244072f9

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