in reply to Re^2: using Statistics::Regression
in thread using Statistics::Regression
my $reg = Statistics::Regression->new("Pain", ["C", "X", "X**2", "X**3 +"]); $reg->include($y, [1.0, $x, $x**2, $x**3]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: using Statistics::Regression
by Random_Walk (Prior) on Apr 19, 2017 at 19:52 UTC | |
Thank you so much Anonymonk, now I am getting somewhere. The fragment of code I am now using, culled from a larger script goes like this ...
Here is some output, now mostly it is working, but then on one set of data it chokes...
I am guessing I may not have enough variation in that data for it to find an optimum, but if anyone can see I am barking up the wrong tree, please do shout Cheers,
Pereant, qui ante nos nostra dixerunt!
UpdateI have now tried it with a cubic term, and it failed on an earlier data set. Then I tried it with just the Constant and an X terms, no square or higher, and it ran the complete set. So now I can get a best fit line. Next step is to see if I can feed it some guess values for the theta vector. | [reply] [d/l] [select] |
by Anonymous Monk on Apr 19, 2017 at 20:21 UTC | |
| [reply] |
by Random_Walk (Prior) on Apr 19, 2017 at 20:42 UTC | |
Yeh, I remembered that when I bombed out on a case with two samples so I have added a guard clause that I do not try to use LR if I have less than 10 samples. It appears to still have some very degenerate cases that kill this module with plenty of samples. I have now updated my code to divide Max(Y) by Min(Y) and use this 'change' value to alter the number of terms I use. Strangely it looks like cases where there is a sudden step change in the data that trigger this failure, I have one case where there is a 56% change and that kills the module.
That appear to guard the cases where I had very little movement in Y over the series, but this one still kills it. The value 'Change' in this debug is Max/Min, so here there is a 30% change
Cheers,
Pereant, qui ante nos nostra dixerunt!
| [reply] [d/l] [select] |
by Anonymous Monk on Apr 19, 2017 at 21:00 UTC | |
by Random_Walk (Prior) on Apr 20, 2017 at 14:52 UTC | |