Different regression coefficients using parfor and for loop

I've recently started analysing a dataset using the logistic regression function mnrfit, running it usually inside a for loop with some other operations.
But in the last couple days, while trying to speed up the proccess, I tried it running inside a parfor loop, and found out that the returned coefficients were different than the ones I had obtained when running it inside a for loop.
The actual code I am actually running is longer, but I found this problem even with a code as simple as this:
parfor k = 1:1
[Bpar,devpar,statspar] = mnrfit(predictor,response); % Logistic regression
parsave('someVariable.mat',Bpar); % Function to save the variable inside a .mat file
end
for k = 1:1
[B,dev,stats] = mnrfit(predictor,response); % Logistic regression
end
The Bpar variable is pretty different from the B variable, and I don't know why. Thinking it could be some random initialization problem, I tried running this same code a couple of times, but Bpar and B were still the same as before, and still different from each other.
In this example I used k = 1:1, but in my actual code it is more complicated, running for about 60 times with some nested for loops, and my predictor matrix gets as big as 2715x406 (which takes a considerable amount of time to be processed), so it would be really useful if I could run it faster using parfor, but I need to be sure that the results would still be trustworthy.
Has anyone crossed something similar before or has any insights?

Respuestas (0)

Categorías

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 22 de Sept. de 2020

Editada:

el 22 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by