Linear and Logistic Regressions to control for a possible confouding variable
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
John D'Errico
el 25 de Ag. de 2023
Editada: John D'Errico
el 25 de Ag. de 2023
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?
Respuestas (1)
Ive J
el 26 de Ag. de 2023
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 comentarios
Ive J
el 28 de Ag. de 2023
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
Ver también
Categorías
Más información sobre Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!