Why do I get disjoint data when I try extrapolate after using polynomial regression

SDG

I wanted to extrapolate some of the data I had, as shown in the plot below. The blue line is the original data and the red line is the extrapolation that I wanted.

enter image description here

To use regression analysis, I used the function polyfit:

sizespecial = size(i_C); 
endgoal = sizespecial(2); 
plothelp = 1:endgoal;

reg1 = polyfit(plothelp,i_C,2);
reg2 = polyfit(plothelp,i_D,2);

Where i_C and i_D are the vectors that represent the original data. I extended the data by using this code:

plothelp=1:endgoal+11; 

for in = endgoal+1:endgoal+11
    i_C(in) = (reg1(1)*(in^2))+(reg1(2)*in)+reg1(3);
    i_D(in) = (reg2(1)*(in^2))+(reg2(2)*in)+reg2(3);
end

However, the graph I output now is:

enter image description here

I do not understand why the extra notch is introduced (circled in red). Do not hesitate to ask me to clarify any of the details on this questions and thank you for all your answers.

Dan

enter image description here

What I imagine is happening is that you are trying fit a second order polynomial over all your data. My guess is that this polynomial will look a lot like the curve I have drawn in in orange. If you follow Matt's advise from his comment and plot your regressed polynomial over the your original data as well (not just the extrapolated part) you should confirm this.

You might get better results by fitting a higher order polynomial. Your data have two points of inflection so a 3rd order polynomial will probably work quite well. One danger of extrapolating on higher order polynomial however is that they could have fairly dramatic inflections outside of the domain of your data and produce unexpected and wild results.

One way to mitigate against this is by rather performing a linear regression over the final x data points of your series. These are the points highlighted in yellow in the figure. You can tune x as a parameter such that it covers as much of the approximately linear final portion of your curve as makes sense. The red line I have drawn in will be the result of a linear regression performed on only those data (as opposed to the entire data set)

Another option might be to rather fit a spline curve and extrapolate on that. You can use the interp1 function specifying 'spline' or 'pchip' for that.

However which is the best choice will depend largely on the nature of the problem you are trying to solve.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why do I get wrong prediction when using this polynomial forecasting formula

Why do I get an Error when I try to rename a table after FROM?

Why do I get this error in my logcat when I try to post JSON data?

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why do I get an error when I try to see my Text using useState?

Why do i get this error when I try installing autopep8 using pip?

Why do i always get NULL in php response when i try to send some variable using ajax

Am I using polynomial regression right in pytorch?

Why do I get error when try to convert Carbon to DateTime?

How do I get the function which transforms an input to be the argument of a Legendre polynomial when using numpy.polynomial.legendre?

Why do i get the following error, when i try to click a asp.net button using vb.net?

Why do I get a message saying "Object is not a function" when I try to do an apply?

Why Do I get an error when I try to get tkinter slider value?

Why do I get the "extra data after last expected column' when importing .csv into my database?

Why do i get different PC values when using the same data set when implementing nsprcomp

Why do I get a NoClassDefFound error when I try to save my test plan?

Why do I get an invalid path when I try and construct a JPQL join query?

Why do I get error when I try to alert the length of the passed array to the function?

Why do I get 'undefined' error when I try to read session atrribute from Controller

Why do I get an error when I try to add a dependent task to one created by the C plugin?

Why do I get an "invalid values" error when I try to access the network settings on Eclipse Mars?

Gitlab CI: why do I get an error when I try to define the pages stage?

Why do I see `503 Backend Error` when I try to get a Cloud Storage service account?

Why do I get a warning and negative numbers when I try to project the world population in Python?

Why do I get Argument exception when I try to use "Include("PropertyName")" in query EF?

Why do I get a compilation error when I try to have two methods with the same name and parameter type?

Why do I get invalid syntax when I try to use pandas to run this code?

Why do I get a blank output when I try to print ASCII table by array approach in Java?

Why do I get permission denied when I try use "make" to install something?