Linear and Logistic Regressions to control for a possible confouding variable
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi all!
I am looking at a dataset that is studying whether or not patients received a certain drug during facial gender affirming surgery and whether that drug impacted their operating time, estimated blood loss, and rate of bruising.
However, the patients had variable number of "procedures" during each surgery (i.e. nose job, brow lift, lip lift, etc.). If one patient had 6 procedures, it seems likely their operative time, blood loss, and bruising may be greater than someone who only had 1 procedure.
How can I run a linear regressions to see if the number of procedures confounds the operative time and estimated blood loss for drug use vs. no drug use? and how can I run a logistic regression to see if the level of bruising is impacted as well?
댓글 수: 2
John D'Errico
2023년 8월 25일
편집: John D'Errico
2023년 8월 25일
Apparently not spam as the algorithms seem to think in might be (god knows why), but as important, how is this a question about MATLAB?
답변 (1개)
Ive J
2023년 8월 26일
whether or not should you adjust for some covariates in your model heavily depends on your understaind of the matter you study. A covariate may or may not be a confounder, and that depends on the underlying causal relationship between your variables in (any) problem. However, as for running a linear or logistic regression you can use fitlm and fitglm respectively.
See:
n = 100; % number of patients
druguse = binornd(1, 0.3, n, 1); % 30% of patients received the drug
procedurenumb = randi([0, 6], n, 1); % number of procedures for each patient
operativetime = randi([50, 120], n, 1); % time in minute
tab = table(druguse, procedurenumb, operativetime, VariableNames=["drug", "procedure", "opTime"]);
model = fitlm(tab) % make sure to check diagnostics and assumptions of your model
% now run a logistic regression for a binary response
tab2 = tab(:, 1:2);
tab2.disease(:) = binornd(1, 0.4, n, 1);
binModel = fitglm(tab2, Link="logit", Dist="binomial")
댓글 수: 3
Ive J
2023년 8월 28일
You don't need to convert them to arrays (you can do! but not as convenient as tables). Just use as table.
patients_data = readtable('Matlab Data draft 1.xlsx');
% column names in patients_data table, make sure reponse is the last column
% e.g. optime here.
cols = ["drug", "ebl", "optime"];
mytab = patients_data(:, cols); % create a new table for fitting the linear model
summary(mytab) % to see what data types you have, if necessary convert numerical variables to categorical or vice versa
model = fitlm(mytab);
In the line you mentioned, I just created another table, tab2 by subsetting the first 2 columns (1:2) of tab to use it in the logistic regression model. If you're not familiar with MATLAB syntax and commands, please familiarize yourself by reading the doc for table
doc table
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!