1
$\begingroup$

I have a dataset of home listings, in R. Here is a sample:

City      Price      Term    Size    Bedrooms     Bathrooms    Description

Appleton  3400       12      1150    1            2            Good location
Appleton  3780       12      1600    7            2            Nice area; 
Barstow   1400       6       900     3            2            Shady st
Raleigh   3700       12      1400    1            1            Quiet st, *veranda*
Ames      2200       12      1300    3            2            Good location
Ames      3400       12      1150    1            2            Good location, *veranda*

What I would like to do is ascertain which cities have the highest premiums and discounts for verandas. Certainly one way to do this would be to build two datasets: get cities WITHOUT verandas (i.e regular listings), and get cities WITH verandas. I could then get the mean rent per city using aggregate, and calculate the difference in mean between the two datasets.

But, I think there is a better way. The above approach does not take into consideration confounding factors like Size, Bedrooms, Bathrooms, etc. How might I take a multiple regression approach which would look at the impact of "veranda-ness" while controlling for other factors? I still want to answer the question of which cities have highest premiums/discounts, only using a more quantitative, robust approach.

I'm familiar with R's lm function and how to run a regression, but not sure how to extrapolate that to answer the question.

Thanks in advance!

$\endgroup$
1
$\begingroup$

One solution is to create a feature HasVeranda representing whether or not the listing has a veranda. To answer the question of how verandas impact pricing across cities (the interaction of City and HasVeranda), perform a regression of Price on HasVeranda interacted with city, allowing the confounds (e.g. Size, BedRooms) as effects in the model. In R, the formula for the regression might look like:

Price ~ City*HasVeranda + Bedrooms + Bathrooms + Size

From here typical linear model inference can be carried out. Checking the coefficients & p-values of the City:HasVeranda interaction terms will suggest the per-city veranda effect size & associated significance (probability the effect is non-zero).

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ City*HasVeranda - do you know how i would search for this? Have already filtered data by using GREP $\endgroup$ – DiamondJoe12 Jun 25 '18 at 22:36
  • $\begingroup$ What do you mean "search for this"? If you mean how to create the feature, something like my_data$HasVeranda <- grepl('veranda', my_data$Description) may work. $\endgroup$ – khol Jun 25 '18 at 22:55
  • $\begingroup$ wash.listings.Recode<-mutate(wash.listings, Check=ifelse(wash.listings$ListingDescription == grepl('Veranda', wash.listings$ListingDescription, ignore.case=TRUE), 'Veranda','NonVeranda')) $\endgroup$ – DiamondJoe12 Jun 25 '18 at 23:04
  • $\begingroup$ The above code is my attempt to re-class the data set based on the keyword "Veranda". It's not working though! NonVeranda is logged successfully, but not the first "if" part of the ifelse statement. $\endgroup$ – DiamondJoe12 Jun 25 '18 at 23:07
  • $\begingroup$ That's a question for StackOverflow since it only relates to programming. There's a couple odd qualities of that code that I can point out. $\endgroup$ – khol Jun 25 '18 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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