-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis.R
95 lines (76 loc) · 1.89 KB
/
analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
library(RSQLite)
library(ggplot2)
library(scales)
library(plyr)
library(reshape2)
library(lubridate)
conn <- dbConnect(dbDriver("SQLite"), dbname = "data/reval.db")
dbListTables(conn)
sales <-
dbGetQuery(conn, "
SELECT
SALEDATE,
SALEPRICE
FROM
sales
WHERE
SALECODE = '0' /* = valid sale */
")
sales <- mutate(sales,
SALEDATE = mdy(SALEDATE),
YEAR = (SALEDATE - min(SALEDATE)) / dyears(1))
sales_ts <- subset(sales, SALEPRICE > 1000 & SALEDATE > ymd("1998-01-01"))
qplot(SALEDATE, SALEPRICE, geom = c("point", "smooth"), log = "y",
data = sales_ts)
p <-
qplot(SALEDATE, SALEPRICE, geom = c("point", "smooth"), log = "y",
data = subset(sales, SALEPRICE > 1000 & SALEDATE > ymd("1970-01-01")))
p <- p + scale_y_log10(labels = dollar)
p <- p + opts(title = "OPA RE Sales (Since 1970)")
p <- p + labs(x = "Sale date", y = "Sale price (log scale)")
p
ggsave(p, file = "/tmp/opasales.png", width = 7, height = 5)
(m1 <- lm(log(SALEPRICE) ~ YEAR, data = sales_ts))
(m2 <- lm(log(SALEPRICE) ~ SALEDATE,
data = subset(sales_ts, SALEDATE > ymd("2000-01-1"))))
muni_revals <-
dbGetQuery(conn, "
SELECT
MuniDesc AS muni_name,
(0.0 + SUM(Total2013)) / SUM(Total2012) AS rel_asm
FROM
reval
WHERE
TaxDesc = 'Taxable'
GROUP BY
muni_name
ORDER BY
rel_asm DESC
")
sd_revals <-
dbGetQuery(conn, "
SELECT
SchoolDesc AS sd_name,
(0.0 + SUM(Total2013)) / SUM(Total2012) AS rel_asm
FROM
reval
WHERE
TaxDesc = 'Taxable'
GROUP BY
sd_name
ORDER BY
rel_asm DESC
")
## need homestead/farmstead exclusion here
county_reval <-
dbGetQuery(conn, "
SELECT
(0.0 + SUM(Total2013)) / SUM(Total2012) AS rel_asm
FROM
reval
WHERE
TaxDesc = 'Taxable'
")
options(digits = 3)
muni_revals
sd_revals