I'm trying to create a regression model for a set of data that includes time and temperature, among others, for 30 minutes intervals throughout the course of a month. I want to build a model that shows how these factors affect air conditioning energy usage. Basically, given time and temperature, I want to predict AC energy usage. This sounds easy enough, and the model for one household would be easily found with:
model = lm(ACEnergy ~ Time + Temperature, data)
One wrinkle that I wanted to add in is a conditional coefficient on the time and temperature data to differentiate between weekends and weekdays (because household behavior is very different based on whether it is a weekend/weekday) and another conditional coefficient for temperature above and below 70 degrees (because people may use energy very differently at this cutoff). If this isn't clear, here is the basis for the model I want to create:
$$Y = \beta_0 + \beta_1 \times \rm{WeekendTime} + \beta_2 \times \rm{WeekdayTime} + \beta_3 \times \rm{LowTemp} + \beta_4 \times \rm{HighTemp} + \beta_5 \times \rm{LowTemp} + \epsilon$$
Where Y is AC usage for a given household and time. If the given time stamp is during a weekday, $\beta_1$ is equal to 0 and vice versa. If the temperature is below 70 degrees, $\beta_4$ is equal to 0 and vice versa.
I'm having trouble figuring out a way to do this in R. Given a chunk of data for a particular household, I can easily separate the chunk into separate lists where one list has all the records with temperature above 70 degrees, another with all the records with timestamps indicating weekends, etc. I can then find the regression models for each of these lists. The problem is that each sub-list will not just have a different coefficient for the differing time or temperature category, but for all variables and intercepts. This makes it impossible to build the model in the way that I want. Or is there a better way to do this altogether?
I would appreciate any help you can offer. I am new to both R and the finer points of regression.
For clarity, here is an example of some of my data:
Record TimeStamp Energy Temp
1 2009-08-17 16:45:00 0.19 75
2 2009-08-17 17:15:00 0.28 76
3 2009-08-17 17:45:00 0.20 76
4 2009-08-17 18:15:00 0.32 76
5 2009-08-17 18:45:00 0.27 66