[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_r
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result |
Date: |
Mon, 8 Aug 2022 13:06:33 -0400 (EDT) |
Follow-up Comment #3, bug #56118 (project octave):
I was hoping you might be familiar enough with the correct/standard definition
and could verify whether the problem is the output or the text.
>From a bit of reading up on the topic, my suspicion is that the function is
correct. The help text says logit(gamma(x) = theta-beta x. The same part of
the code mentioned in the other bug report that outputs gamma defines it as as
theta+x*beta:
line 181:
if (nargout == 6)
if (nx > 0)
e = ((x * beta) * ones (1, nz)) + ((y * 0 + 1) * theta');
else
e = (y * 0 + 1) * theta';
endif
gamma = diff ([(y * 0), (exp (e) ./ (1 + exp (e))), (y * 0 + 1)]')';
endif
using that, I tried just changing your exponential arguments in the numerator
and denominator, but the output was still nonsensical. (noticed that Pfun of
p2 was 1 then went to nan at higher values)
recentering around zero, and rerunning your code as:
x = (-10:10)' ; y = [zeros(11, 1) ; ones(10,1)] ;
Pfun = @(p, x) exp(p(2) * x + p(1)) ./ (1 + exp(p(2) * x + p(1))) ; Pin = [0
0]' ;
p1 = nonlin_curvefit (Pfun, Pin, x, y) ;
[p2(1) p2(2)] = logistic_regression(y, x) ;
subplot(2,1,1) ;
plot(x, y, "x", x, Pfun(p1, x), "-") ;
set(gca, "box", "off")
subplot(2,1,2) ;
plot(x, y, "x", x, Pfun(p2, x), "-") ;
set(gca, "box", "off")
it's not perfect but it seems to at least behave as expected.
So, I'll recommend that change to the help text. Given that do you see any
other issues that would prevent closing this report?
(cc package maintainer and attaching a simple doc patch to make that help text
change as well as add variable tags to the texinfo in the formulas)
(file #53544)
_______________________________________________________
Additional Item Attachment:
File name: doc-logistic_regression-formula-fix-pt2-bug-56118.patch Size:1 KB
<https://file.savannah.gnu.org/file/doc-logistic_regression-formula-fix-pt2-bug-56118.patch?file_id=53544>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?56118>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Nicholas Jankowski, 2022/08/06
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Muhali, 2022/08/08
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result,
Nicholas Jankowski <=
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Nicholas Jankowski, 2022/08/08
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Andreas Bertsatos, 2022/08/08
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Muhali, 2022/08/08
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Nicholas Jankowski, 2022/08/08
- [Octave-bug-tracker] [bug #56118] [octave forge] (statistics) logistic_regression gives incorrect result, Nicholas Jankowski, 2022/08/10