# Power Trend Line

**URL:** <https://www.ruby-forum.com/t/power-trend-line/153292>\
**Category:** Ruby\
**Created:** [November 14, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/power-trend-line/153292 "2008-11-14T12:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 14, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/power-trend-line/153292/1 "2008-11-14T12:27:02Z")

</div>

Hi,

Im using some graphing software to produce charts which contain various  
lines. One line i need to produce is a power trend line from an array  
dataset. Has anyone had any experience of this in ruby?

JB

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 16, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/power-trend-line/153292/2 "2008-11-16T19:30:18Z")

</div>

> Im using some graphing software to produce charts which contain various  
> lines. One line i need to produce is a power trend line from an array  
> dataset. Has anyone had any experience of this in ruby?

One approach would be to use the fitting libraries provided by the GSL:  
[http://www.gnu.org/software/gsl/manual/html\_node/Least\_002dSquares-Fitting.html](http://www.gnu.org/software/gsl/manual/html_node/Least_002dSquares-Fitting.html)

To access this from Ruby you can use the Ruby GSL bindings :  
[http://rb-gsl.rubyforge.org/](http://rb-gsl.rubyforge.org/)

Another approach may be to use the Ruby/R interface RRRuby :  
[http://rubyforge.org/projects/rsruby/](http://rubyforge.org/projects/rsruby/)

although, unless you have a compelling reason to use Ruby (such as  
integrating with existing code) you may find it better to use R directly  
([http://www.r-project.org/](http://www.r-project.org/)).

If you have some sample data or code perhaps we can come up with some  
examples,

Hope this helps,

Chris

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 17, 2008, 12:15am UTC](https://www.ruby-forum.com/t/power-trend-line/153292/3 "2008-11-17T00:15:41Z")

</div>

-------- Original-Nachricht --------

> Datum: Fri, 14 Nov 2008 20:24:01 +0900  
> Von: John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Power Trend Line

> Hi,
> 
> Im using some graphing software to produce charts which contain various  
> lines. One line i need to produce is a power trend line from an array  
> dataset. Has anyone had any experience of this in ruby?
> 
> ## JB
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Dear John,

maybe gruff is for you ?

[http://nubyonrails.com/pages/gruff](http://nubyonrails.com/pages/gruff)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 17, 2008, 1:08am UTC](https://www.ruby-forum.com/t/power-trend-line/153292/4 "2008-11-17T01:08:22Z")

</div>

Dear Chris,

> > Im using some graphing software to produce charts which contain various  
> > lines. One line i need to produce is a power trend line from an array  
> > dataset.

> I interpreted the original message to mean code to fit a, for example,  
> polynomial of a given order to some data. It’s been a while since I  
> played with it but can Gruff do this ?

No, I don’t think so, it’s just for graphing (and for lines, rather than  
polynomials)  
rather than fitting, for which the software you proposed can be used.  
Maybe you’re right that the OP wanted some fitting algorithm.

A good place to look for is “Linear Regression” (can be used also to  
determine  
coefficients of polynomials). There is an example for Rb-gsl here:

[http://rb-gsl.rubyforge.org/fit.html#2](http://rb-gsl.rubyforge.org/fit.html#2) , chapter 5 .

Once you’ve calculated it, you can choose a nice graphing output  
software …

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 17, 2008, 12:25am UTC](https://www.ruby-forum.com/t/power-trend-line/153292/5 "2008-11-17T00:25:38Z")

</div>

> maybe gruff is for you ?
> 
> [http://nubyonrails.com/pages/gruff](http://nubyonrails.com/pages/gruff)

I interpreted the original message to mean code to fit a, for example,  
polynomial of a given order to some data. It’s been a while since I  
played with it but can Gruff do this ?

Chris
