Welcome Spring 2025 Students!

Lab#

Learning Objectives#

At the end of this learning activity you will be able to:

  • Practice using robust correlation tools that account for outliers.

  • Practice using pg.qqplot and pg.normality to asses the normality of residuals.

  • Practice using regression to create covariate-controlled scores.

import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

import pingouin as pg

%matplotlib inline
data = pd.read_csv('hiv_neuro_data.csv')
data['education'] = data['education'].astype(float)
data.head()

This lab is going to explore the inter-relationships between two cognitive domains.

  • Executive Function: The complex cognitive processes required for planning, organizing, problem-solving, abstract thinking, and executing strategies. This domain also encompasses decision-making and cognitive flexibility, which is the ability to switch between thinking about two different concepts or to think about multiple concepts simultaneously.

  • Speed of Information Processing: How quickly an individual can understand and react to the information being presented. This domain evaluates the speed at which cognitive tasks can be performed, often under time constraints.

We will explore whether these two domains are correllated after controlling for co-variates.

Q1: Are Processing domain and Executive domain scores correlated?#

# Generate a plot between processing_domain_z and exec_domain_z

q1_plot = ...
# Use pg.corr to calculate the correlation between the two variables using a `robust` correlation metric

q1_corr_res = ...
# Are the two domains significantly correlated? 'yes' or 'no'

q1_is_corr = ...
grader.check("q1_domain_corr")

Q2: Create a regression for the processing domain that accounts for demographic covariates.#

  • Age

  • Race

  • Sex

  • Education

  • Years Seropositive

  • ART

# Perform the regression using `pg.linear_regression`
# Use the result to answer the questions below
# Assess the normality of the residuals of the model


q2_model_resid_normal = ...
# Considering a p<0.01 threshold answer which of the following are significant

# Age
q2_processing_age = ...

# Race
q2_processing_race = ...

# Sex
q2_processing_sex = ...

# Education
q2_processing_edu = ...

# Infection length
q2_processing_ys = ...

# ART
q2_processing_art = ...
grader.check("q2_exec_adj")

Q3: Is covariate controlled EDZ still correlated with PDZ?#

# Generate a plot between covariate controlled processing_domain_z and exec_domain_z

q3_plot = ...
# Use pg.corr to calculate the correlation between the two variables using a `pearson` correlation metric

q3_corr_res = ...
q3_corr_res
# Are processing_domain_z and covariate controlled exec_domain_z still correlated?
q3_corr_sig = ...


# Correlation r-value
# Place the r-value here rounded to 4 decimal places
q3_corr_r = ...
# Partial correlation r-value
# Place the r-value here rounded to 4 decimal places
q3_partial_corr_r = ...
# Are the results the same between the two methods? 'yes' or 'no'

q3_same_res = ...
grader.check("q3_partial_corr")

We’ve seen from above that it is important to create processing_domain_z score corrected for covariates. We also saw in the walkthrough that it is important create an exec_domain_z score corrected for covariates. However, pg.partial_corr only allows you to correct for covariates in x or y but not both.

Use another regression to remove the covaraites from exec_domain_z and determine if it is correlated with processing_domain_z after removing covariates.

Q4: Are EDZ and PDZ correlated after controlling for covariates?#

# Find the residuals for exec_domain_z after controlling for covariates
# Plot the two corrected values against each other

q4_plot = ...
# Test the correlation between the two sets of corrected values

pg.corr(proc_res.residuals_, exec_res.residuals_)
# After correction for covariates, are PDZ and EDZ correlated? 'yes' or 'no'

q4_sig_cor = ...
grader.check("q4_full_corr")

grader.check_all()

Submission#

Check:

  • That all tables and graphs are rendered properly.

  • Code completes without errors by using Restart & Run All.

  • All checks pass.

Then save the notebook and the File -> Download -> Download .ipynb. Upload this file to BBLearn.