




TCL(Tool Command Language) Scripting









xy chart with trend line.
I am attempting to transliterate a spread sheet based financial application to TclTk. Most of the ap can be duped easily with improved user interface and error protection. But the last sheet of the spread sheet consists of an xy chart with a trend line. The idea is that the user can plug in different values and get different results, including a different chart. Any suggestions on how to hook a dynamically changing xy chart into a Tcl/Tk operation? Oh yes, the app has to be portable to programmerunfriendly environments like Windoze. John Culleton
j @wexfordpress.com wrote: > I am attempting to transliterate a spread sheet based financial > application to TclTk. Most of the ap can be duped easily with improved > user interface and error protection. But the last sheet > of the spread sheet consists of an xy chart with a trend line. The > idea is that the user can plug in different values and get different > results, including a different chart. > Any suggestions on how to hook a dynamically changing xy chart into a > Tcl/Tk operation? > Oh yes, the app has to be portable to programmerunfriendly > environments like Windoze. > John Culleton
have look at blt and its vector command( esp. the spline and expr stuff ) and the graph widget which uses either blt::vector items for display or plain lists of numbers. http://wiki.tcl.tk/199 http://wiki.tcl.tk/15000 example 3 is an interactive viewer for functions implemented currently ax^3 + bx^2 + cx + d with sliders for changing a b c d in realtime. http://wiki.tcl.tk/_ref/10119 http://sourceforge.net/projects/blt http://sourceforge.net/project/showfiles.php?group_id=18616 uwe
On 10 mei, 22:58, Uwe Klein <uwe_klein_habertw@tonline.de> wrote:
> j @wexfordpress.com wrote: > > I am attempting to transliterate a spread sheet based financial > > application to TclTk. Most of the ap can be duped easily with improved > > user interface and error protection. But the last sheet > > of the spread sheet consists of an xy chart with a trend line. The > > idea is that the user can plug in different values and get different > > results, including a different chart. > > Any suggestions on how to hook a dynamically changing xy chart into a > > Tcl/Tk operation? > > Oh yes, the app has to be portable to programmerunfriendly > > environments like Windoze. > > John Culleton > have look at blt and its vector command( esp. the spline and expr stuff ) > and the graph widget which uses either blt::vector items for display > or plain lists of numbers. > http://wiki.tcl.tk/199http://wiki.tcl.tk/15000 > example 3 is an interactive viewer for functions > implemented currently ax^3 + bx^2 + cx + d > with sliders for changing a b c d in realtime. > http://wiki.tcl.tk/_ref/10119 > http://sourceforge.net/projects/blthttp://sourceforge.net/project/sho... > uwe Tekst uit oorspronkelijk bericht niet weergeven  >  Tekst uit oorspronkelijk bericht weergeven 
Alternatively Tklib's Plotchart has stripcharts and is pure Tcl/Tk. (http://tcllib.sf.net) How do you compute (or define) these trend lines? Regards, Arjen
On May 11, 4:39 am, Arjen Markus <arjen.mar@wldelft.nl> wrote:
> On 10 mei, 22:58, Uwe Klein <uwe_klein_habertw @tonline.de> wrote: > > j@wexfordpress.com wrote: > > > I am attempting to transliterate a spread sheet based financial > > > application to TclTk. Most of the ap can be duped easily with improved > > > user interface and error protection. But the last sheet > > > of the spread sheet consists of an xy chart with a trend line. The > > > idea is that the user can plug in different values and get different > > > results, including a different chart. > > > Any suggestions on how to hook a dynamically changing xy chart into a > > > Tcl/Tk operation? > > > Oh yes, the app has to be portable to programmerunfriendly > > > environments like Windoze. > > >JohnCulleton > > have look at blt and its vector command( esp. the spline and expr stuff ) > > and the graph widget which uses either blt::vector items for display > > or plain lists of numbers. > >http://wiki.tcl.tk/199http://wiki.tcl.tk/15000 > > example 3 is an interactive viewer for functions > > implemented currently ax^3 + bx^2 + cx + d > > with sliders for changing a b c d in realtime. > >http://wiki.tcl.tk/_ref/10119 > >http://sourceforge.net/projects/blthttp://sourceforge.net/project/sho... > > uwe Tekst uit oorspronkelijk bericht niet weergeven  > >  Tekst uit oorspronkelijk bericht weergeven  > Alternatively Tklib's Plotchart has stripcharts and is pure Tcl/Tk. > (http://tcllib.sf.net) > How do you compute (or define) these trend lines? > Regards, > Arjen
I don't. The author of the original spread sheet package did some Excel magic that I don't understand, not being a user of that product. Basically some data pairs are plotted on an xy chart and an averaging line of some kind is drawn through them. I have done it with pencil and paper but I never understood the math of it. I would probably attack the problem with some sort of moving average overlaying the scattered data points, but that would be a curved rather than a straight line. I'll ask the originator what the line is supposed to represent.
j @wexfordpress.com wrote: > I don't. The author of the original spread sheet package did some > Excel magic > that I don't understand, not being a user of that product. Basically > some data pairs are plotted on an xy chart and an averaging line of > some kind is drawn through them. I have done it with pencil and paper > but I never understood the math of it. I would probably attack the > problem with some sort of moving average overlaying the scattered data > points, but that would be a curved rather than a straight line. I'll > ask the originator what the line is supposed to represent. This smells like "linear regression", a well known method in applied maths. You basically just calculate the sum of x, y, x^2, y^2 and x*y and can derive the parameters of the line. Let N be the number of datapoints and x_i, y_i the coordinates. Then you calculate xm := sum (x_i) /N ym := sum (y_i) /N b := sum ( (x_i xm) * (y_iym)) / sum ( (x_i xm)^2 ) a := ym  b*xm then the regression line is given by y(x)=a+b*x CHristian
On May 11, 9:19 am, Christian Gollwitzer <Christian.Gollwit...@uni
bayreuth.de> wrote: > j @wexfordpress.com wrote: > > I don't. The author of the original spread sheet package did some > > Excel magic > > that I don't understand, not being a user of that product. Basically > > some data pairs are plotted on an xy chart and an averaging line of > > some kind is drawn through them. I have done it with pencil and paper > > but I never understood the math of it. I would probably attack the > > problem with some sort of moving average overlaying the scattered data > > points, but that would be a curved rather than a straight line. I'll > > ask the originator what the line is supposed to represent. > This smells like "linear regression", a well known method in applied > maths. You basically just calculate the sum of x, y, x^2, y^2 and x*y > and can derive the parameters of the line. > Let N be the number of datapoints and x_i, y_i the coordinates. Then you > calculate > xm := sum (x_i) /N > ym := sum (y_i) /N > b := sum ( (x_i xm) * (y_iym)) / sum ( (x_i xm)^2 ) > a := ym  b*xm > then the regression line is given by y(x)=a+b*x > CHristian
The author of the spreadsheet has since stated that the line represents a least squares fit. It has been 40 yers since I fiddled with regressions and the like. Is your formulation a least squares fit? (got to find that old stat textbook :) John c.
Thanks for the clear algorithm description  it prompted me to make a "linear regression toy" http://wiki.tcl.tk/18055 as breakfast fun project :^)
On May 11, 3:35 pm, "j@wexfordpress.com" <j@wexfordpress.com> wrote:
> On May 11, 9:19 am, Christian Gollwitzer <Christian.Gollwit...@uni > bayreuth.de> wrote: > > j@wexfordpress.com wrote: > > > I don't. The author of the original spread sheet package did some > > > Excel magic > > > that I don't understand, not being a user of that product. Basically > > > some data pairs are plotted on an xy chart and an averaging line of > > > some kind is drawn through them. I have done it with pencil and paper > > > but I never understood the math of it. I would probably attack the > > > problem with some sort of moving average overlaying the scattered data > > > points, but that would be a curved rather than a straight line. I'll > > > ask the originator what the line is supposed to represent. > > This smells like "linear regression", a well known method in applied > > maths. You basically just calculate the sum of x, y, x^2, y^2 and x*y > > and can derive the parameters of the line. > > Let N be the number of datapoints and x_i, y_i the coordinates. Then you > > calculate > > xm := sum (x_i) /N > > ym := sum (y_i) /N > > b := sum ( (x_i xm) * (y_iym)) / sum ( (x_i xm)^2 ) > > a := ym  b*xm > > then the regression line is given by y(x)=a+b*x > > CHristian > The author of the spreadsheet has since stated that the line > represents > a least squares fit. It has been 40 yers since I fiddled with > regressions and > the like. Is your formulation a least squares fit? (got to find that > old stat textbook :) > John c.
Yes, that's a leastsquares fit. You can get it using calculus, by constructing: F(a,b) = sum (y_i  (a + b * x_i))^2 and minimizing F(a,b) with respect to a and b (by taking derivatives). The result should by (I didn't go check) the formulas above.
On 11 mei, 21:35, "j@wexfordpress.com" <j@wexfordpress.com> wrote:
> On May 11, 9:19 am, Christian Gollwitzer <Christian.Gollwit...@uni > bayreuth.de> wrote: > > j@wexfordpress.com wrote: > > > I don't. The author of the original spread sheet package did some > > > Excel magic > > > that I don't understand, not being a user of that product. Basically > > > some data pairs are plotted on an xy chart and an averaging line of > > > some kind is drawn through them. I have done it with pencil and paper > > > but I never understood the math of it. I would probably attack the > > > problem with some sort of moving average overlaying the scattered data > > > points, but that would be a curved rather than a straight line. I'll > > > ask the originator what the line is supposed to represent. > > This smells like "linear regression", a well known method in applied > > maths. You basically just calculate the sum of x, y, x^2, y^2 and x*y > > and can derive the parameters of the line. > > Let N be the number of datapoints and x_i, y_i the coordinates. Then you > > calculate > > xm := sum (x_i) /N > > ym := sum (y_i) /N > > b := sum ( (x_i xm) * (y_iym)) / sum ( (x_i xm)^2 ) > > a := ym  b*xm > > then the regression line is given by y(x)=a+b*x > > CHristian > The author of the spreadsheet has since stated that the line > represents > a least squares fit. It has been 40 yers since I fiddled with > regressions and > the like. Is your formulation a least squares fit? (got to find that > old stat textbook :) > John c. Tekst uit oorspronkelijk bericht niet weergeven  >  Tekst uit oorspronkelijk bericht weergeven 
That is a fairly simple task  adding lines representing the confidence levels is a bit more difficult (I would have to go and hunt the formulae to do that). Regards, Arjen
On 10 mei, 22:41, "j@wexfordpress.com" <j@wexfordpress.com> wrote: > I am attempting to transliterate a spread sheet based financial > application to TclTk. Most of the ap can be duped easily with improved > user interface and error protection. But the last sheet > of the spread sheet consists of an xy chart with a trend line. The > idea is that the user can plug in different values and get different > results, including a different chart. > Any suggestions on how to hook a dynamically changing xy chart into a > Tcl/Tk operation? > Oh yes, the app has to be portable to programmerunfriendly > environments like Windoze. > John Culleton
Just to show off a bit: here is how you can add a trend line in the latest version of Plotchart (use the CVS repository): canvas .c background white width 400 height 400 pack .c fill both side top set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}] set xd 5.0 set yd 20.0 set xold 0.0 set yold 50.0 $s dataconfig series1 colour "red" $s dataconfig series2 colour "blue" $s dataconfig series3 colour "magenta" for { set i 0 } { $i < 20 } { incr i } { set xnew [expr {$xold+$xd}] set ynew [expr {$yold+(rand()0.5)*$yd}] set ynew2 [expr {$yold+(rand()0.5)*2.0*$yd}] $s plot series1 $xnew $ynew $s plot series2 $xnew $ynew2 $s trend series3 $xnew $ynew2 ;# <=== Add data for the trend line, updated automatically set xold $xnew set yold $ynew }
Regards, Arjen





