# Linear Regression

**URL:** <https://forum.inductiveautomation.com/t/linear-regression/3098>\
**Category:** Ignition\
**Created:** [July 14, 2011, 4:27pm UTC](https://forum.inductiveautomation.com/t/linear-regression/3098 "2011-07-14T16:27:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon.Trusik](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jon.Trusik](https://forum.inductiveautomation.com/u/Jon.Trusik)\
**Post date:** [July 14, 2011, 4:27pm UTC](https://forum.inductiveautomation.com/t/linear-regression/3098/1 "2011-07-14T16:27:48Z")

</div>

Has anyone ever done any linear regression for a series of points in a dataset that are being trended? Would like to create an overlay for a series of points being displayed.

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [July 15, 2011, 7:13pm UTC](https://forum.inductiveautomation.com/t/linear-regression/3098/2 "2011-07-15T19:13:57Z")

</div>

It’s been a while since I’ve done any real math, but the most difficult part of linear regression should be setting up the equations. To take a dataset, do some calculations and then put the results back, you need something like the followig on a nearby button (or propertyChange script):[code]oldData = system.dataset.toPyDataSet(event.source.parent.getComponent(‘Table’).data)  
newData = []  
header = [“raw1”, “calc”]  
for row in oldData:  
#do your calculations  
calc = (row[0]+row[1])/2  
#append the data  
newData.append([row[0], calc])

#store the new data  
event.source.parent.getComponent(‘Table’).data = system.dataset.toDataSet(header, newData)[/code]

---

<div class="post-metadata">

**Author:** ![Jon.Trusik](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jon.Trusik](https://forum.inductiveautomation.com/u/Jon.Trusik)\
**Post date:** [July 18, 2011, 4:26pm UTC](https://forum.inductiveautomation.com/t/linear-regression/3098/3 "2011-07-18T16:26:44Z")

</div>

Thanks, I’ve got an equation for it, was hoping someone might have done this already and had a ‘canned ap’. Also just realized I posted this in the wrong place! Sorry 'bout that.
