3
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ Can you please check the correlation between elevator and floor number? $\endgroup$
    – JohnK
    Commented May 21, 2015 at 9:30
  • $\begingroup$ R gives me a low correlation 0.34 for them. $\endgroup$
    – Paul
    Commented May 21, 2015 at 9:37
  • $\begingroup$ Since there does not appear to be any multicollinearity in your model, what makes you think it is not good? $\endgroup$
    – JohnK
    Commented May 21, 2015 at 9:43
  • 5
    $\begingroup$ 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. $\endgroup$
    – Silverfish
    Commented May 21, 2015 at 10:46
  • 1
    $\begingroup$ 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. $\endgroup$ Commented May 21, 2015 at 11:32

3 Answers 3

4
$\begingroup$

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. If you really think elevator is completely irrelevant if on the ground floor, have a look at How do you deal with "nested" variables in a regression model?

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Paul
    Commented May 21, 2015 at 13:19
  • 2
    $\begingroup$ 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, ... $\endgroup$ Commented May 21, 2015 at 14:02
  • $\begingroup$ the purposes of the model is prediction. $\endgroup$
    – Paul
    Commented May 26, 2015 at 7:32
1
$\begingroup$

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.

$\endgroup$
12
  • $\begingroup$ 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? $\endgroup$
    – Paul
    Commented May 21, 2015 at 13:39
  • $\begingroup$ Yes. This will become a new independent or predictor variable which you can use in your regression. $\endgroup$
    – rnso
    Commented May 21, 2015 at 13:41
  • $\begingroup$ ok, i'll try it. But this will give me big numbers, because my data set has ~ 700 observations. $\endgroup$
    – Paul
    Commented May 21, 2015 at 13:44
  • $\begingroup$ Should not be too difficult for any software. $\endgroup$
    – rnso
    Commented May 21, 2015 at 14:05
  • $\begingroup$ 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). $\endgroup$ Commented May 21, 2015 at 14:06
0
$\begingroup$

This answer purely shows how to add a linear term. It is also interesting to model this different. For example an isotonically increasing function of floor number, a spline, or a decision tree model


Asside from defining variables manually, you can do this by introducing an interaction effect in the model, and drop the main effect.

This will cause the influence/effect of elevator to be zero when the the floor level is zero as well.

The example below demonstrates this by showing a linear model with an included interaction where the main effect is left out.

demonstration

set.seed(1)
n = 50
elevator = sample(0:1, n, replace = T)
floor = sample(0:10, n, replace = T)
z = rnorm(n)

mod = lm(z ~ 1 + floor + elevator:floor)
plot(floor, predict(mod), col = 1+elevator, 
     main = "lm(z ~ 1 + floor + elevator:floor)", cex.main = 1)
legend(0,0.6,c("without elevator", "with elevator"), col = c(1,2), cex = 0.7, pch = 1)

mod = lm(z ~ 1 + elevator + floor + elevator:floor)
plot(floor, predict(mod), col = 1+elevator, 
     main = "lm(z ~ 1 + elevator + floor + elevator:floor)", cex.main = 1)
legend(0,0.6,c("without elevator", "with elevator"), col = c(1,2), cex = 0.7, pch = 1)
$\endgroup$

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.