# Repeated measures of paired variables -- testing whether they regress.

7 visualizzazioni (ultimi 30 giorni)
Edwin Robertson il 12 Mar 2021
Risposto: Sai Pavan il 10 Apr 2024
I have N participants.
Each has two variables measured X and Y on five occasions.
How do I calculate/create the regression/correlation of X vs Y using all five repeated measures for the N participants?
Mostly repeated measures deal with time as a factor and how a variable does or does not change.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Sai Pavan il 10 Apr 2024
Hello Edwin,
I understand that you want to create a regression model of X vs Y using all five repeated measures for the N participants.
This task can be carried out with the use of a mixed-effects model as it allows us to model both the fixed effects and random effects like how individual participants deviate from the overall effect using "fitlme" function.
Please refer to the below workflow to create a regression model:
• First, we need to prepare the data in a table format that includes all measurements of X and Y, along with an identifier for each participant and an identifier for each measurement occasion.
• We can then fit a linear mixed-effects model to this data. The model will include fixed effects for X and random intercepts for each participant to account for the repeated measures.
Please refer to the below code snippet that illustrates the workflow described above:
N = 100; % Number of participants
occasions = 5;
X = rand(N, occasions); % Place the actual data here
Y = rand(N, occasions); % Place the actual data here
participants = repmat((1:N)', occasions, 1);
occasion = repmat(1:occasions, N, 1);
occasion = occasion(:);
X_flat = reshape(X', [], 1);
Y_flat = reshape(Y', [], 1);
data = table(participants, occasion, X_flat, Y_flat, 'VariableNames', {'Participant', 'Occasion', 'X', 'Y'});
% Fit a Linear Mixed-Effects Model (Random Intercepts)
lme = fitlme(data, 'Y ~ 1 + X + (1|Participant)');
Hope it helps!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Linear Regression in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by