Finding a function for data points with disturbances I have a question regarding how to find an equation for data points that have disturbances. For example, I have the following data:


*

*P = 366 measured values 

*T = 366 measured values

*t = [ 1 : 366 ], representing the days of the year (index)


So at each t (day), we have value of P and corresponding value of T. When drawing P and T vs. t, it shows a continued curve for P with disturbances. These disturbances are caused by the change of T and it is clear that P is mainly affected by T, meaning that: P = f(T)
This figure is shown here:

This figure shows P vs. T:

My aim is to find this relation between P and T or in another words: P = f(T). What I have tried and think so far is first to smooth the curve P and from the smoothed points and smoothed curve, some function may be established. Then, including the effect of disturbances (up and down) by some function, may be exponential.
Could you please guide me how can I manipulate this problem to get a final model  P = f(T). 
 A: $P$ (power) depends on $T$ (temperature) as well as $t$ (time) in these natural, obvious ways:


*

*Power is the sum of a base consumption (for operating electrical and gas equipment such as stoves and refrigerators in a consumer setting), consumption for lighting, and for heating and cooling.

*Base consumption may vary but the variation is likely to be relatively small and can be handled with additional factors (such as a vacation/weekend schedule) or assumed to be randomly varying around a constant level.

*Lighting needs depend on the length of the night and should be just about directly proportional to the length.

*The heating and cooling consumption depends on the amount of time a building falls below a heating threshold or above a cooling threshold.
(4) is a complex relationship.  Consider heating; the analysis of cooling is similar.  As the external temperature varies, the internal temperature will vary, too, but with a lag in time and with a dampening effect.  Heating is needed only when the internal temperature would fall beneath the heating threshold $h$, and then only to supply enough heat to bring the building up to the temperature $h$.  Mathematically we can conceive of $T$ as an instantaneous function of time $t$.  The hypothetical internal temperature of the building $S(t)$ would depend on previous temperatures.  A good model for this would be the linear operator
$$S(t) = \int_{-\infty}^{t}\kappa(t-u) T(u) du$$
given by some (unknown) kernel $\kappa$.  The value $\kappa(x)$ gives the amount to weight $T(t-x)$ in estimating the internal temperature $S(t)$.  The amount of heating needed at time $t$ is then proportional to the difference between the desired temperature and the temperature the building otherwise would attain,
$$(h-S(t))^+ = \min(0, h - S(t)).$$
This part of the model is clearly apparent in both plots.  Cooling is required only at times in the middle of the first plot, when temperatures are high.  When temperatures are lower, there is no cooling burden.  The variation in power (blue) is small; essentially the power is constant on these days.  Once the temperature (red) exceeds 21 or so, power consumption starts growing roughly in proportion to the amount of exceedance.  After day 345, temperatures once again fall below 21 consistently, eliminating the cooling load, and once again power reaches its minimum.  This behavior is what squashes the bottom left of the scatterplot (second figure) into a vertically narrow interval.
If we ignore the problem of estimating the kernel $\kappa$ (which amounts to assuming the house is uninsulated), the model we need to fit would be something in the form
$$\int_{t-1}^{t}P(x)dx = \int_{t-1}^{t}\left(\beta_0 + \beta_{l}f(x) + \beta_h(h-T(x))^+ + \beta_c (T(x) - c)^+ + \varepsilon(x)\right)dx.$$
Here, $\beta_0$ is a parameter representing the base load, $\beta_{l}$ is a lighting load coefficient, $f(x)$ is the length of night as a function of the day $x$, $\beta_h$ is a heating load coefficient, $h$ is either known (from a thermostat setting) or is a parameter representing the heating threshold, $\beta_c$ is a cooling load coefficient, and $c$ is either known or is a parameter representing the cooling threshold, with $c \ge t$.  The random variation not otherwise accounted for is represented by a stochastic process $\varepsilon(x)$.  Over the long term its mean should be zero.
If we further neglect diurnal temperature variation (which is a poor idea when recording power over longer periods, such as weeks or months, but is may be a decent approximation for daily power usage), then we can approximate these integrals by their integrands, getting something like
$$P(t) = \beta_0 + \beta_{l}f(t) + \beta_h(h-T(t))^+ + \beta_c(T(t) - c)^+ + \delta(t).$$
Here, $\delta(t)$ is the daily average of the $\varepsilon(x)$ for $x$ between $t-1$ and $t$ plus some additional small amounts due to this point approximation of the integrals.  (Those additional small terms will roughly be proportional to the amount of variation in the integrands--large in the spring and fall, smaller in the summer and winter.  That gives useful clues about how to refine this model if it comes to that.)  It's likely these random terms are not identically distributed--their variance is probably related to the temporal rate of change of the temperature--and they also are likely to be serially correlated.  These possibilities will encourage us to check the model residuals carefully after fitting it and perhaps to use time series techniques in the fitting, but they don't change the basic nature of the deterministic terms that appear.
The night-length function $f(t)$ follows an annual cycle and should either be obtained from data for the location, an astronomical calculation, or can be estimated as a linear combination of sines and cosines; either way, it's nonlinear and will not be accurately estimated as a polynomial in $t$.  The most important terms, $(h-T(t))^+$ and $(T(t) - c)^+$, are sharply non-linear functions of the observed temperature $T(t)$.  Because of this, it would be a good idea to incorporate them as given (and to investigate what the values of $h$ and $c$ might be) rather than attempt to accommodate them merely by throwing a few extra powers of $T(t)$ into a linear regression.  Because of these important nonlinearities, beware of following the computationally expedient approach of modeling $P$ as a polynomial in $T$ and $t$: it is unlikely to work well and even if you throw in enough terms to get a decent fit, you can have little confidence that it will continue to fit well in the future.
We can obtain meaningful information from the parameters: $\beta_c$ is the marginal cost of cooling per additional degree of outside temperature above $c$ and $\beta_h$ is the marginal cost of heating for each lower degree of outside temperature below $h$.  If the thresholds $c$ and $h$ are not known, they can be estimated (using maximum likelihood, for instance), and thereby provide extremely useful indicators of how aggressively the building is being cooled or heated.  For instance, I found through an analysis of monthly utility bills that my value of $h$ is $15$ degrees Celsius, which is essentially the average thermostat setting across three heating zones in my house, and that the old heating system cost almost $2$ dollars per day per degree Celsius, which is $\beta_h$ converted from units of power into the cost of that power. (This made it easy to decide to replace it with a high-efficiency system.)
This analysis sketches out a path anyone can take for characterizing the relationship between power consumption and temperature in a building.  Simply follow it backwards: start with the simplified final model and a crude fitting procedure (like least squares).  If it's sufficiently accurate, stop.  If not, analyze the residuals to identify which approximations may have introduced the greater errors, then track backwards through this analysis to see how to improve those approximations and make them more accurate.  In principle, a dataset covering a sufficiently long period could suffice even to estimate the kernel $\kappa$, which would give interesting and potentially valuable information about the thermal characteristics of the building's insulation.
A: Have you tried some simple multiple linear regression? For example, 
\begin{equation}
P = \beta_0 + \beta_1 T + \beta_2 T^2 + 
    \beta_3 t + \beta_4 t^2 + 
    \beta_5 t \times T
\end{equation}
where $\beta_i$'s are coefficients to be estimated. In the model I've included squared terms and an interaction to try and capture the non-linear aspects of your model. 
