Skip to content

align term matrix sorting in Wilkinson Formula parser.#437

Merged
pr0m1th3as merged 1 commit into
gnu-octave:mainfrom
AvanishSalunke:parseWilkinsonFormula-fixes
May 31, 2026
Merged

align term matrix sorting in Wilkinson Formula parser.#437
pr0m1th3as merged 1 commit into
gnu-octave:mainfrom
AvanishSalunke:parseWilkinsonFormula-fixes

Conversation

@AvanishSalunke
Copy link
Copy Markdown
Contributor

This issues was mentioned before as well in #395

Standard sortrows on the binary terms matrix was sorting 0 before 1 because of this later variables (x3 - 0 0 1) were evaluated before (x1- 1 0 0).

Added negation so that instead of just comparing 0 and 1 it will compare 0 and -1.

MATLAB :

>> formula = 'Y ~ x1 * x2 * x3';
>> mdl = fitlm(t, formula);
>> mdl.Formula.VariableNames

ans =

  1×4 cell array

    {'Y'}    {'x1'}    {'x2'}    {'x3'}

>> mdl.Formula.Terms

ans =

     0     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
     0     1     1     0
     0     1     0     1
     0     0     1     1
     0     1     1     1

OCTAVE (before) :

octave:5>  eq = parseWilkinsonFormula ('Y ~ x1 * x2 * x3', 'matrix');
octave:6> eq.VariableNames
ans =
  1x4 cell array

    {'Y'}    {'x1'}    {'x2'}    {'x3'}    

octave:7> eq.Terms
ans =

   0   0   0   0
   0   0   0   1
   0   0   1   0
   0   1   0   0
   0   0   1   1
   0   1   0   1
   0   1   1   0
   0   1   1   1

OCTAVE (after) :

octave:5> eq = parseWilkinsonFormula ('Y ~ x1 * x2 * x3', 'matrix');
octave:6> eq.VariableNames
ans =
  1x4 cell array

    {'Y'}    {'x1'}    {'x2'}    {'x3'}    

octave:7> eq.Terms
ans =

   0   0   0   0
   0   1   0   0
   0   0   1   0
   0   0   0   1
   0   1   1   0
   0   1   0   1
   0   0   1   1
   0   1   1   1

@pr0m1th3as pr0m1th3as merged commit 2b27a93 into gnu-octave:main May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants