# Trend Lines

Trend lines can be added to all 2D chart types except for Pie and Stock charts.

Choose Insert - Trend Lines (Charts)

- To insert a trend line for a data series, select the data series in the chart. Choose
**Insert - Trend Lines**, or right-click to open the context menu, and choose**Insert - Trend Line**.

Mean Value Lines are special trend lines that show the mean value. Use**Insert - Mean Value Lines**to insert mean value lines for data series.

If an element of a data series is selected, this command works on that data series only. If no element is selected, this command works on all data series.

- To delete a trend line or mean value line, click the line, then press the Del key.

A trend line is shown in the legend automatically. Its name can be defined in options of the trend line. |

The trend line has the same color as the corresponding data series. To change the line properties, select the trend line and choose **Format - Format Selection - Line**.

## Contents

## Trend Line Equation and Coefficient of Determination

When the chart is in edit mode, LibreOffice gives you the equation of the trend line and the coefficient of determination R^{2}, even if they are not shown: click on the trend line to see the information in the status bar.

To show the trend line equation, select the trend line in the chart, right-click to open the context menu, and choose **Insert Trend Line Equation**.

To change format of values (use less significant digits or scientific notation), select the equation in the chart, right-click to open the context menu, and choose **Format Trend Line Equation - Numbers**.

Default equation uses `x`

for abscissa variable, and `f(x)`

for ordinate variable. To change these names, select the trend line, choose **Format - Format Selection – Type** and enter names in `X Variable Name`

and `Y Variable Name`

edit boxes.

To show the coefficient of determination R^{2}, select the equation in the chart, right-click to open the context menu, and choose **Insert R2**.

If intercept is forced, coefficient of determination R^{2} is not calculated in the same way as with free intercept. R^{2} values can not be compared with forced or free intercept. |

## Trend Lines Curve Types

Following regression types are available:

**Linear**trend line: regression through equation`y=a∙x+b`

. Intercept`b`

can be forced.**Polynomial**trend line: regression through equation`y=Σ(ai∙xi)`

. Intercept`a0`

can be forced. Degree of polynomial must be given (at least 2).**Logarithmic**trend line: regression through equation`y=a∙ln(x)+b`

.**Exponential**trend line: regression through equation`y=b∙exp(a∙x)`

.This equation is equivalent to`y=b∙mx`

with`m=exp(a)`

. Intercept`b`

can be forced.**Power**trend line: regression through equation`y=b∙xa`

.**Moving average**trend line: simple moving average is calculated with the**n**previous y-values,**n**being the period. No equation is available for this trend line.

## Constraints

The calculation of the trend line considers only data pairs with the following values:

- Logarithmic trend line: only positive x-values are considered.
- Exponential trend line: only positive y-values are considered, except if all y-values are negative: regression will then follow equation
`y=-b∙exp(a∙x)`

. - Power trend line: only positive x-values are considered; only positive y-values are considered, except if all y-values are negative: regression will then follow equation
`y=-b∙xa`

.

You should transform your data accordingly; it is best to work on a copy of the original data and transform the copied data.

## Calculate Parameters in Calc

You can also calculate the parameters using Calc functions as follows.

### The linear regression equation

The **linear regression** follows the equation `y=m*x+b`

.

`m = SLOPE(Data_Y;Data_X)`

`b = INTERCEPT(Data_Y ;Data_X)`

Calculate the coefficient of determination by

`r`

^{2} = RSQ(Data_Y;Data_X)

Besides m, b and r^{2} the array function **LINEST** provides additional statistics for a regression analysis.

### The logarithmic regression equation

The **logarithmic regression** follows the equation `y=a*ln(x)+b`

.

`a = SLOPE(Data_Y;LN(Data_X))`

`b = INTERCEPT(Data_Y ;LN(Data_X))`

`r`

^{2} = RSQ(Data_Y;LN(Data_X))

### The exponential regression equation

For exponential trend lines a transformation to a linear model takes place. The optimal curve fitting is related to the linear model and the results are interpreted accordingly.

The exponential regression follows the equation `y=b*exp(a*x)`

or `y=b*m^x`

, which is transformed to `ln(y)=ln(b)+a*x`

or `ln(y)=ln(b)+ln(m)*x`

respectively.

`a = SLOPE(LN(Data_Y);Data_X)`

The variables for the second variation are calculated as follows:

`m = EXP(SLOPE(LN(Data_Y);Data_X))`

`b = EXP(INTERCEPT(LN(Data_Y);Data_X))`

Calculate the coefficient of determination by

`r`

^{2} = RSQ(LN(Data_Y);Data_X)

Besides m, b and r^{2} the array function LOGEST provides additional statistics for a regression analysis.

### The power regression equation

For **power regression** curves a transformation to a linear model takes place. The power regression follows the equation `y=b*x^a`

, which is transformed to `ln(y)=ln(b)+a*ln(x)`

.

`a = SLOPE(LN(Data_Y);LN(Data_X))`

`b = EXP(INTERCEPT(LN(Data_Y);LN(Data_X))`

`r`

^{2} = RSQ(LN(Data_Y);LN(Data_X))

### The polynomial regression equation

For **polynomial regression** curves a transformation to a linear model takes place.

Create a table with the columns x, x^{2}, x^{3}, … , x^{n}, y up to the desired degree n.

Use the formula `=LINEST(Data_Y,Data_X)`

with the complete range x to x^{n} (without headings) as Data_X.

The first row of the LINEST output contains the coefficients of the regression polynomial, with the coefficient of xⁿ at the leftmost position.

The first element of the third row of the LINEST output is the value of r^{2}. See the LINEST function for details on proper use and an explanation of the other output parameters.

## Related Topics

LINEST function

LOGEST function

SLOPE function

INTERCEPT function

RSQ function