Borrar filtros
Borrar filtros

Linear and Logistic Regressions to control for a possible confouding variable

6 visualizaciones (últimos 30 días)
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
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?
Ariel
Ariel el 26 de Ag. de 2023
Editada: Ariel el 26 de Ag. de 2023
I'm looking for help on how to run these tests on matlab! Sorry if that was unclear.. I shortened my answer in the hopes that would make the question not marked as spam so I took out the part about not being able to figure out how to do this despite reading articles/watching videos on doing regressions in matlab.
I tried to use fitlm but I'm not confident I'm using it correctly. I converted the number of procedures, operative time, and drug use into arrays (1 representing the patients receiving the drug and 0 if they did not) and then input my variables:
X = [druguse,procedurenumb]
model = fitlm(X,operativetime)
I'm unsure if this is the correct way to control for the number of procedures here.
As for the logistic regression, I can't seem to find an article on how to run a regression for three variables.
The only linear regression syntax I could find was this, but my output was confusing and I don't see how this would control for the number of procedures in assessing bruising in pts with the drug vs without.
MnrModel = fitmnr(procedurenumb, bruising)
I'm very new to Matlab so please excuse me if my vocab is off :)

Iniciar sesión para comentar.

Respuestas (1)

Ive J
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
model =
Linear regression model: opTime ~ 1 + drug + procedure Estimated Coefficients: Estimate SE tStat pValue ________ ______ ________ __________ (Intercept) 80.404 4.002 20.091 2.4226e-36 drug 2.7647 4.8607 0.56878 0.57082 procedure 0.060338 1.0032 0.060143 0.95217 Number of observations: 100, Error degrees of freedom: 97 Root Mean Squared Error: 21 R-squared: 0.00334, Adjusted R-Squared: -0.0172 F-statistic vs. constant model: 0.163, p-value = 0.85
% 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")
binModel =
Generalized linear regression model: logit(disease) ~ 1 + drug + procedure Distribution = Binomial Estimated Coefficients: Estimate SE tStat pValue ________ _______ _______ ________ (Intercept) 0.22879 0.39098 0.58517 0.55843 drug -0.91499 0.51435 -1.7789 0.075255 procedure -0.14258 0.10063 -1.4168 0.15654 100 observations, 97 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 4.65, p-value = 0.098
  3 comentarios
Ive J
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

Iniciar sesión para comentar.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by