필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Edwin Robertson
Edwin Robertson 2021년 3월 12일
답변: Sai Pavan 2024년 4월 10일
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.

답변 (1개)

Sai Pavan
Sai Pavan 2024년 4월 10일
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: https://www.mathworks.com/help/stats/fitlme.html
Hope it helps!

Community Treasure Hunt

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

Start Hunting!

Translated by