Minimize error of linear regression by changing input x-vector

Hi!
I´ve got data for heating use (kWh)per day over a year for a house in a cold climate as well as the average temperature per day of the same year. The space heating dependency of the outside temperature can be described by a simple linear regression of kWh in relation to outside temperature as shown below.
But since the building has got a thermal inertia the temperature of yesterday is also affecting the heating needs of today. Therefore it is more correct to describe the space heating need as dependent of the weighted temperature t. This can be described by the following equation:
t=w*tc + (1-w)*ty
Where t: weighted temperature
tc:Outdoor temperature of current day
ty: Outdoor temperature of day before current day
w: the weight factor describing the thermal inertia of the house, which i want to calculate.
The sum of squared error of the linear regression should be mostly dependent of the thermal inertia of the house (but also in random variations of heat and tap water use by the inhabitants). By minimizing the SSE by changing the weighted temperature (vector) by variating w the most correct weight factor (w) should be found.
To clarify I want to "calculate" the thermal inertia of the building, expressed by the thermal weight factor (w). I am therefore not so interested in fitting the best curve to the data, but instead "fit" the best data to the linear negative correlation line of temperatuer and kWh (by changing the original temperature to weighted temperature).
I have been trying to achieve this by using fminbnd as following
tw = @(w) ((w*tc)+(1-w)*ty);
errorfun = @(w) "Sum of squared error of the linear regression of" (tw,kWh);
wOptimal = fminbnd(errorfun,0,1);
(tw,tc,ty and kWh are vectors)
But i struggle to find a function which returns the "Sum of squared error of the linear regression of" two vectors, and i´m also not sure if i´m using fminbnd the right way.
Does anyone have any idea how this can be written?
Example data is attached.
/Carl

Answers (1)

If you want to predict kWh from tc and ty, you might simply use the 2-predictor linear regression model kWh = a + b1*tc + b2*ty. fitlm will estimate a, b1, and b2 for you, and you might not need w any more after you have those. If you do still need w, you might be able to compute it as w = b1/(b1+b2) (but I'm not too sure about that).
You need to be a little bit cautious in interpreting the results, though, because the estimates of b1 and b2 are pretty unstable (i.e., large sampling error), especially when tc and ty are strongly correlated, as they surely are in the situation you describe.

1 Comment

Thank you!
I am most interested in the thermal inertia of the house (w). And it would be good to be able to calculate it from t=w*tc + (1-w)*ty , in order to get a clear ratio which can be used for comparison between buildings.

Sign in to comment.

Asked:

on 23 Nov 2017

Commented:

on 27 Nov 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!