Here is my issue; I want to do the same processiterate a fit to this data for a setpolynomial of degree 2 up till degree 6. However, at each iteration I drop certain data points changing somethat have a poor residual value. So each time the degree is raised, a subset of the variables values slightly between runsprevious data set's fit is used. However I do not want to havewill also need to rename everything in this sectionchange the value of codethe max residual that I want to use over and over. How can I set up the program so that it can use the same definitions of variables throughoutinclude the program? I understand Module is a good way to do this, however I cannot get it to work. Here is07 in the procedure I want to do:code below).
data = Table[{x, RandomReal[{-.1, .1}] + x^2}, {x, 0, 15}]
lstplt = LinearModelFit[data, Table[x^i, {i, 2}], x]
Plot[lstplt[x], {x, 0, 15}]
reslist =
Inner[List, {data}[[1, All, 1]], lstplt["FitResiduals"], List];
Show[ListPlot[data], Plot[lstplt[x], {x, 0, 15}]]
ListPlot[reslist]
bres = Select[reslist, Abs[#[[2]]] > .07 &];
gres = DeleteCases[reslist, Alternatives @@ bres];
gpoints = gres[[All, 1]] \[Intersection] reslist[[All, 1]];
ListPlot[listtr3 = Select[data, gpoints~MemberQ~First[#] &]]
Again, the idea is that I could copy and paste this code below the output of the first run throughit would fit a quadratic, change some numbers slightly (say thethen take out residual values greater than .07 to. Take those data points that have a residual greater than .05)07 and execute againdelete them. Then take that set and fit a cubic polynomial, without havingand find points that have greater than a different residual value and delete them. Iterate this up to change the definition of 'bres' for exampledegree n polynomial.