# Modelling explanatory variables which depend on each other

I'm trying to estimate the value of an apartment, by doing a regression through similar apartments. The regression model looks now like this lmRob(price ~ ., data = data), but this is clearly wrong.

My problem is modelling / defining explanatory variables which depend on each other. For example elevator and floor number depend on each other. If the apartment is at ground floor, the existence of a elevator is irrelevant. But if the floor number is higher, the importance of the existence of the elevator is also higher. How could I model this in my regression model?

[UPDATE]

I also don't want a model that requires an apartment which is located at ground floor and an elevator exists to be equally valuable as a similar apartment also located at ground floor but without elevator. Instead, what I want is to have a variable which substitutes the two variables floor number and elevator and in which the importance of an elevator depending on the floor number is shown.

• Can you please check the correlation between elevator and floor number? – JohnK May 21 '15 at 9:30
• R gives me a low correlation 0.34 for them. – Paul May 21 '15 at 9:37
• Since there does not appear to be any multicollinearity in your model, what makes you think it is not good? – JohnK May 21 '15 at 9:43
• I think you might want to edit the question to make it clearer you're not just interested in the case where the explanatory variables are related to each other (correlated), but where the effect of one explanatory variable on the response (elevator) depends on another explanatory variable (floor number). I think you should be investigating the interaction between the two variables: it seems reasonable that the presence of an elevator may be more important at higher floor numbers. – Silverfish May 21 '15 at 10:46
• I dont think this really is a duplicate of stats.stackexchange.com/questions/86269/… so should not be closed. The problem is subtler---if first floor, then whatever is the value of variable "elevator" is logically irrelevant to an individual buyer, but, maybe, it could carry information as a proxy variable, as an indication of generally higher quality. – kjetil b halvorsen May 21 '15 at 11:32

Some commenters wanted to close this because they thought it is a duplicate of What is the effect of having correlated predictors in a multiple regression model? but that is not entirely correct. Even if there is little correlation (or colinearity) in your data, there is the problem that whether the building has an elevator or not does not seem to be relevant for the buyer who is not going to use the elevator, because he is living on the ground floor! There are other problems: it does seem strange to use floor number as variable in a linear regression, for why should value depend linearly on floor number? If floor 0, no need to use stairs, if floor 1, you need stairs but still burglars can reach the windows, if higher not much difference, but maybe from the highest floors there is better sun and sight? So no reason to expect a linear effect. You try try a quadratic, or even use a spline ...

Or you could compare with results from tree modelling ... but for now, lets see some options for a linear model. Some commenters argue for an interaction between floor and elevator, we write that floor*elevator (which includes separate terms for each variable).Then you can see if the effect of floor is different when there is an elevator or not. Or you could use a quadratic model for floor, then you need to cross each term with elevator, so both the linear and quadratic part in floor can have effects differing if elevator or not. Or you could build some new discrete variable with categories depending on both variables floor and elevator. Such a variable could be informed from results of a tree modelling exercise.

• I use the floor number in the regression because mostly, an apartment which is located at a higher floor is more valuable than a apartment located at a ground floor. Reasons for this are for example: you get more sun light, it is almost impossible for a thieve to break you window, etc. – Paul May 21 '15 at 13:19
• That,s OK, but is the effect linear---is really 20th floor much more valuable that 10th? You should at least try with a square term in the model. We could also use some more information---what are the purposes of your model, prediction, understanding, something else, and number of variables, number of cases, ... – kjetil b halvorsen May 21 '15 at 14:02
• the purposes of the model is prediction. – Paul May 26 '15 at 7:32

You can create another variable:

new_elevator_var = num_of_elevators * floor_number


This will reflect the presence and importance of elevator(s). It will be 0 even if there are many elevators but floor number is 0 and will increase as the number of floors increase.

• you mean that for each observation, I should create a new variable which is equal with: the number of elevators existing in the data set multiplied with the floor number of the current observation? – Paul May 21 '15 at 13:39
• Yes. This will become a new independent or predictor variable which you can use in your regression. – rnso May 21 '15 at 13:41
• ok, i'll try it. But this will give me big numbers, because my data set has ~ 700 observations. – Paul May 21 '15 at 13:44
• Should not be too difficult for any software. – rnso May 21 '15 at 14:05
• rnso's suggestion is similar to the suggestion of Silverfish: the interaction of 'elevator' and 'floor number' will be entered into your model as 'elevator*floor numbers'. However, the number of observations in your data sets will have no influence on the value of the interaction for a specific observation. In addition, kjetil has a point: it is unlikely that floor relates linearly to value (if only because buildings will have variable number of floors). – Antoine Vernet May 21 '15 at 14:06