# Error evalution for linear fits

Operations Research Asked by Jane on August 19, 2021

I have some data that looks almost linear. I need to make a fit in order to evaluate the slope.
The thing is, the slope is changing if I change the fit range (not all the data is linear so I need to choose myself the range) I wondered how would you suggest to evaluate the added error from the arbitrary selection of the range. For example, maybe I should make a few fits for a few ranges, and take the "range of slopes"/stdv as the added uncertainty?
thanks

There exist methods for fitting a piece-wise linear function to data in an optimal way, for various interpretations of what it means for this fit to be optimal. These methods may still require you to specify the number of segments in advance, but playing around with the number of segments seems less arbitrary to me than selecting the ranges by yourself.

This question on StackOverflow discusses Python libraries to do piece-wise linear fitting, including pwlf. You may also have a look at the Wikipedia entry for Segmented regression.

Answered by Kevin Dalmeijer on August 19, 2021

## Related Questions

### What is a general procedure to prove that the LP relaxation of an IP delivers the optimal IP solution?

2  Asked on August 19, 2021 by k88074

### CPLEX MIP warm start seems slow down the program?

1  Asked on August 19, 2021 by mengfan-ma

### (Iterative?) Solutions to a certain quadratic program with non-convex constraints

2  Asked on August 19, 2021 by cfp

### Problem with implementing squared terms in the objective function

1  Asked on August 19, 2021 by poofybridge

### Scheduling with setup cost

0  Asked on August 19, 2021 by dirk-nachbar

### Is a convex or MILP (without big-M) formulation possible for this problem

1  Asked on August 19, 2021 by batwing

### MINLP Solution same as Global Optimum?

2  Asked on August 19, 2021 by clement

### Linear objective function with non-linear constraints

2  Asked on August 19, 2021 by fightmilk

### Meta papers on operations research

2  Asked on August 19, 2021 by luke599999

### Verifying the correctness of KKT conditions

0  Asked on August 19, 2021 by s_scouse

### How can I use warm start in C#

1  Asked on August 19, 2021 by fhm-ider

### Feasible sets represented as point clouds

1  Asked on August 19, 2021 by harry-cohen

### Is this the same as Agent Based DES or something different?

0  Asked on August 19, 2021 by brendan-hill

### Column generation when intractable variables appear in the objective function

1  Asked on August 19, 2021 by mostafa

### Is there any OR way to solve this problem?

3  Asked on August 19, 2021 by samiczy

### Find a particular optimal solution

1  Asked on August 19, 2021 by ljg

### How to find all vertices of a polyhedron

3  Asked on August 19, 2021

### Can every convex problem use Lagrangian dual method?

0  Asked on August 19, 2021

### Does strong duality hold when I dualize only a subset of the constraints?

1  Asked on August 19, 2021 by george-chang