2
$\begingroup$

I'm trying to find transformation for my explanatory variable (outside temperature) to better explain heating power usage. I have data from one year here.

data <- read.table(file="data.txt", header=TRUE, sep="\t")
Power <- as.ts(data$y)
Temp <- as.ts(data$temp_MA)
dLen <- as.ts(data$dLen)

linearfit <- lm(Power~Temp)

This linear model is not that good with $R^2=0.213$. I tried linear piece-wise transformation for the temperature and it got a little better ($R^2 = 0.228$)

x <- seq(from = -19, to = 25, by = 2) #breakpoints
require(segmented)
fit <- segmented(linearfit,seg.Z= ~Temp, psi=list(Temp=x))
summary(fit)
plot.segmented(fit) 

Does anyone have an idea what other approaches I should try for my data?

Power usage: enter image description here Temperature: enter image description here Power~Temp enter image description here

Update: I'm using temperature as external regressors with day length and 168h seasonality. Day length data here. seasonality was created with:

x<- ts(1:8760,freq=168,start=1)
seasonaldummy <- seasonaldummy(x)

Auto.arima give me a nice model (4,1,1). But i'm still not happy with my temperature as an regressor.

Model <- auto.arima(Power,seasonal=TRUE,max.order=20,stepwise=FALSE,xreg=cbind(Temp,dLen,seasonaldummy),allowdrift=TRUE,parallel=TRUE,num.cores=32)
$\endgroup$
8
  • $\begingroup$ Are you sure the relationship between power and temperature is linear? I could figure that during heating season, the colder it is the more power is used for heating; but if there is a hot summer, too, then the colder it is the less power will be used for cooling (air conditioning). Thus the slope of the regression line reverses within one year. This is just one example. Also, what is your data frequency? If it's daily, you may expect seasonal days-of-the-week effects. If it's intra-daily, there will be intra-daily seasonality extra to that (little power usage at night, more at daytime). $\endgroup$ Commented Mar 29, 2015 at 9:44
  • $\begingroup$ I have data for every hour of the day. quantmod function Lag() also gives little improvement. I'm using this regressors(temp) as part external xreg in ARIMA model because there is a lot of correlation between lags. And yeah I think I have to split my model to parts (summer-winter). $\endgroup$
    – ELEC
    Commented Mar 29, 2015 at 10:06
  • $\begingroup$ I suggest to update your post with these details. They may be important. What you could do, for example, is fit an ARIMA model with auto.arima with the following external regressors: 23 hourly dummies, 6 weekday dummies and an appropriate transformation of temperature to account for the non-linearity (this is the tricky part; piece-wise linear temperature effect could make sense). Dummies could perhaps be replaced by Fourier terms. You need not split your model into summer and winter periods, I would rather try to allow for a non-linear effect of temperature in one global model. $\endgroup$ Commented Mar 29, 2015 at 10:16
  • $\begingroup$ Im using seasonal dummy matrix for 1 week seasonality (168h) ($8760\times 167$) and day length as regressors also. I'll post them update my post. $\endgroup$
    – ELEC
    Commented Mar 29, 2015 at 10:21
  • $\begingroup$ Oh, of course, 168 hours seasonality makes more sense for power consumption than hourly+weekday seasonality; keep using that. Reagrding the non-linear power usage, you could create new variables of the form temperature $\times$ dummy with dummies corresponding to temperature being, say, between -20 and -10, then between -10 and 0, 0 and 10, 10 and 20 and the like? Including these interaction variables instead of the original temperature variable would allow for the piece-wise linearity. $\endgroup$ Commented Mar 29, 2015 at 10:28

1 Answer 1

1
$\begingroup$

Are you sure the relationship between power and temperature is linear? I could figure that during the heating season, the colder it is, the more power is used for heating; but if there is a hot summer, too, then the colder it is, the less power will be used for cooling (air conditioning). Thus the slope of the regression line reverses twice within one year.

One solution to this problem is to assume piece-wise linearity for the temperature effect on power consumption. You would create new interaction variables of the form temperature $\times$ dummy with the dummies corresponding to temperature being, say, below -20°C, then between -20°C and -10°C, between -10°C and 0°C, between 0°C and 10°C, between 10°C and 20°C, and above 20°C. That is, dummy1 corresponds to $\mathbf{1}(temp<-20)$, dummy2 corresponds to $\mathbf{1}(-20<temp \leqslant -10)$, etc. Including these interaction variables instead of the original temperature variable would allow for the piece-wise linearity.

The break points should be selected based on subject-matter considerations like heating threshold (when the central heating kicks in, perhaps at +10°C), cooling threshold (when cooling kicks in in most places, perhaps at +25°C) etc.

$\endgroup$
3
  • $\begingroup$ By the way. Couldn't this be done with the segmented package. And put breakpoints for the linear piece-wise fit for -20,-10,0,10,20? like: fit <- segmented(linearfit,seg.Z= ~Temp, psi=list(Temp=c(-20,-10,0,10,20))) $\endgroup$
    – ELEC
    Commented Mar 29, 2015 at 12:48
  • $\begingroup$ I meant that, isn't that what my segmented example does already? $\endgroup$
    – ELEC
    Commented Mar 29, 2015 at 13:05
  • $\begingroup$ Perhaps. I do not know exactly how segmented works. It might be the case that after some discussion, I arrived to the solution that you had already proposed yourself. Of course, your original question was about a simple regression using (lm) rather than a model with ARMA errors. Without the ARMA errors it could be easier to make the temperature effect even more flexible than piece-wise linear, but given ARMA errors this might be more complicated. After all, do you expect that a decent power consumption model should have a high $R^2$? Maybe yours is already quite good given the context? $\endgroup$ Commented Mar 29, 2015 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.