{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "7a6dd026-c62e-d0d0-1205-3c8d1f27ab93"
      },
      "source": [
        "Semi-Elasticities are useful in determining the percentage change in y given a 1-unit change in x. This exploratory analysis seeks to understand how bedrooms/bathrooms drives list price in a simple model. \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "76c23c81-b4d7-ebdf-005f-d4370f2e6b29"
      },
      "outputs": [],
      "source": [
        "packages <- c(\"jsonlite\", \"dplyr\", \"purrr\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a8f3d737-9577-28e0-d934-366f90b37e5a"
      },
      "outputs": [],
      "source": [
        "purrr::walk(packages, library, character.only = TRUE, warn.conflicts = FALSE)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "b5bc7f98-5dad-9844-a35c-dcdcf6165d56"
      },
      "outputs": [],
      "source": [
        "data <- fromJSON(\"../input/train.json\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "fa34edb1-5766-2fff-9b3e-49da18d92aa7"
      },
      "outputs": [],
      "source": [
        "vars <- setdiff(names(data), c(\"photos\", \"features\"))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "05303b75-112c-7759-33e5-dd4603207637"
      },
      "outputs": [],
      "source": [
        "data <- map_at(data, vars, unlist) %>% tibble::as_tibble(.)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a5af9269-ef9b-f8bc-ec26-98f31cf5e7aa"
      },
      "outputs": [],
      "source": [
        "bed=data$bedrooms\n",
        "bath=data$bathrooms\n",
        "price=data$price\n",
        "lprice=log(price)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "ad620ea5-a156-5bde-d85d-988a9f7cdd9d"
      },
      "outputs": [],
      "source": [
        "fit <- lm(lprice ~ bed + bath, data=data)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "13342a32-28e3-585e-1510-636c6284f4fd"
      },
      "outputs": [],
      "source": [
        "summary(fit)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3f103e19-478a-74ee-0116-ba18de8300c0"
      },
      "outputs": [],
      "source": [
        "#this means bathrooms could be a bigger driver of price than bedrooms"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "R",
      "language": "R",
      "name": "ir"
    },
    "language_info": {
      "codemirror_mode": "r",
      "file_extension": ".r",
      "mimetype": "text/x-r-source",
      "name": "R",
      "pygments_lexer": "r",
      "version": "3.3.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}