Azzera filtri
Azzera filtri

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

7 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Sai Pavan
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)');
Please refer to the below documentation to learn more about the "fitlme" function:
Hope it helps!

Community Treasure Hunt

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

Start Hunting!

Translated by