# Finding average error of the data

Considering I have some data, and I want to fit the data to a linear fit and find the average error from the linear fit, how can I do that using Mathematica?

I have

temp = WeatherData[location, "MeanTemperature", {start, end, "Day"}];
Show[ListPlot@Partition[Reverse@temp["Values"], 2, 1], Plot[line, {x, 0, 40},
PlotStyle -> Red]]


Which generates

How can I find the average error of this linear fit?

-
What about error? – Mike Aug 15 '14 at 9:56
I don't believe we do need a room, not that I don't want to be in a room with you ;o) But just provide the data or the code to create them. – Öskå Aug 15 '14 at 10:11
If, for example, dat = Table[{x, Sin[x] + RandomReal[{-.2, .2}]}, {x, 0, 10, .1}]; (because the code you gave needs a location and other parameters and I don't know, nor want to learn, how to set that) then eg mdl = NonlinearModelFit[dat, a*Sin[b*x] + c, {a, b, c}, x] finds a model and you can find for example the variance like so Variance[dat[[All, 2]] - mdl /@ dat[[All, 1]]]. – acl Aug 15 '14 at 12:06
@Mike, fit["EstimatedVariance"] gives the variance. The documentation refers to many other properties and measures that are available, if you're after something else. – Michael E2 Aug 15 '14 at 12:27
I believe those displacements are called residuals and are given by fit["FitResiduals"] or by the formula acl used inside Variance in his first comment. – Michael E2 Aug 15 '14 at 14:19

The answer is 0, if the question is what is the value of Mean[fit["FitResiduals"]] and fit is a linear, least-squares fitted model.

data = WeatherData["London", "Temperature", {{2004, 1, 1}, {2013, 12, 31}, "Day"}];
normaldata = Partition[Reverse[data["Values"][[All, 1]]], 2, 1];
fit = LinearModelFit[SetPrecision[normaldata, Infinity], x, x, WorkingPrecision -> 20]
lfit["FitResiduals"] // Mean
(*
0.*10^-19
*)


Other possibilities:

Mean of the absolute residuals.

lfit["FitResiduals"] // Abs // Mean
(* 1.455345158021296804 *)


Standard error (root-mean-square of the residuals).

lfit["EstimatedVariance"] // Sqrt
(* 1.862702601613853043 *)

-