-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathporj.R
483 lines (421 loc) · 18 KB
/
porj.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
install.packages(c("sf"
#, "tmap"
#, "tmaptools"
, "RSQLite"
, "tidyverse"
, "sandwich"
, "msm"), repos = "https://www.stats.bris.ac.uk/R/")
install.packages("sandwich")
install.packages("msm")
#sf: simple features, standard way to encode spatial vector data
#tmap: layer-based and easy approach to make thematic maps
#tmaptools: set of tools for reading and processing spatial data
#RSQLite: embeds the SQLite database engine in R
install.packages("rgdal") # FOR MAC
#install.packages("raster") # TO MANIPULATE RASTERS
install.packages("shinyjs") #FOR COOL COLORED MAPS
#install.packages("leaflet.extras")
install.packages('reshape')
install.packages("processx")
# LOAD LIBRARIES
library(processx)
library(rgdal)
#library(sf) #TO READ SHAPEFILES
#library(sp)
library(tidyverse) #TO MANIPULATE CSV FILES
#library(tmap) #TO PLOT MAPS
#library(tmaptools)
library(readr)
#library(RSQLite) #TO CONNECT CSV DATA TO GEOPACKAGE
#library(raster)
library(tibble)
library(leaflet)
library(leaflet.extras)
#library(maptools)
library(rgeos)
library(rgdal)
library(reshape)
library(dplyr)
library(plotly)
library(stats)
library(ggplot2)
library(sandwich)
library(msm)
setwd("~/desktop/QMfinalpaper")
LDDnewhousing <- read_csv2("LDD - Housing Completions unit level.csv", skip = 0
, col_types = cols(
Borough = col_character(),
`Planning Authority` = col_character(),
`Borough Reference` = col_character(),
`Permission type` = col_character(),
`Existing units` = col_double(),
`Proposed units` = col_double(),
`Net unit level` = col_double(),
`Number of bedrooms` = col_double(),
`Affordable (Yes/No)` = col_character(),
`Unit Tenure` = col_character(),
`Unit provider` = col_character(),
`Unit Type` = col_character(),
`Multiple Occupancy (Y/N)` = col_character(),
`Housing for Older People (Y/N)` = col_character(),
`Other Sheltered (Y/N)` = col_character(),
`Plot description` = col_character(),
`Maximum building height (storeys)` = col_double(),
`Development type` = col_character(),
`Permission Status` = col_character(),
`Permission Date` = col_date(format = "%d/%m/%Y"),
`Completed Date (Res)` = col_date(format = "%d/%m/%Y"),
`Completed Financial Year (Res)` = col_character(),
`Scheme Name` = col_character(),
`Site Name/Number` = col_character(),
`Primary Street Name` = col_character(),
`Secondary Street(s)` = col_character(),
`Post Code` = col_character(),
Ward = col_character(),
Easting = col_double(),
Northing = col_double(),
`Total proposed units` = col_number(),
`Residential Site Area` = col_double(),
`Total site area` = col_double(),
`Development Description` = col_character(),
X35 = col_logical(),
X36 = col_logical()
)
)
spec(LDDnewhousing)
LDDnewhousing
LDDnewhousing <- filter(LDDnewhousing, `Proposed units` != 0
& `Development type` == "New build"
& `Affordable (Yes/No)` == "Yes"
& `Residential Site Area`!=0)
LDDnewhousing <- LDDnewhousing[,-c(3,4,5,7,13,14,15,16,17,18,19,23,24,35,36)]
LDDnewhousing <- unique(LDDnewhousing)
colonnes <- colnames(LDDnewhousing)
unitTypes <- unique(LDDnewhousing$`Unit Type`)
boroughs <- unique(LDDnewhousing$Borough)
#UNITS DENSITY
unitdens <- data.frame(c(1:6850))
unitdens$east <- LDDnewhousing$Easting
unitdens$north <- LDDnewhousing$Northing
unitdens$total <- LDDnewhousing$`Total proposed units`
unitdens$area <- LDDnewhousing$`Total site area` #IN HECTARES
unitdens[,-1]
unitdens <- unique(unitdens)
unitdens$dens <- unitdens$total/unitdens$area
max(unitdens$dens)
boxplot(unitdens$dens,legend ="Density of units of housing per")
dwellingdens <- data.frame(c(2013:2018),c(21.3,21.5,21.7,21.9,22.1,22.3)) #dwellings per hectare
colnames(dwellingdens) <- c("Year","dwellhec")
plot(unitdens$area,unitdens$total)
#GRAPH OF DENSITY PER HECTRE
xaxis2 <- list(title = list(text = "data"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showline = TRUE
,showgrid = FALSE
,showticklabels = TRUE
,linecolor = 'rgb(204, 204, 204)'
,linewidth = 2
,autotick = FALSE
,ticks = 'outside'
,tickcolor = 'rgb(204, 204, 204)'
,tickwidth = 2
,ticklen = 5
,tickfont = list(family = 'Helvetica'
,size = 12
,color = 'rgb(82, 82, 82)')
)
yaxis2 <- list(title = list(text = "Density(units per hectare)"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showgrid = FALSE
,zeroline = FALSE
,showline = TRUE
,showticklabels = TRUE
,tickfont = list(family = 'Helvetica',
size = 12,
color = 'rgb(82, 82, 82)')
,range= c(0,1000))
density <- plot_ly(unitdens,y=~dens, type = "box",name = "1") %>%
# add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==2],name="2") %>%
# add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==3],name="3") %>%
# add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==4],name="4") %>%
layout(title ="Density of units per hectare"
, xaxis = xaxis2
, yaxis = yaxis2
, autosize = FALSE
, showlegend = FALSE
, margin = margin
)
density
unique(Hbrooms2018$`Unit provider`)
testdates <- filter(LDDnewhousing, `Completed Date (Res)` > "2013-01-01" & `Completed Date (Res)` < "2013-12-31")
testdates
# YEARS " 2013 - 2018
#HISTOGRAM OF THE NUMBER OF ROOMS PER UNIT BUILT
Hbrooms2018 <- filter(LDDnewhousing
, `Completed Date (Res)` > "2018-01-01"
& `Completed Date (Res)` < "2018-12-31") %>%
group_by(`Number of bedrooms`) #%>%
# summarise(`Number of units built`=sum(`Proposed units`))
Hbrooms2018
xaxis1 <- list(title = list(text = "Number of bedrooms"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showline = TRUE
,showgrid = FALSE
,showticklabels = TRUE
,linecolor = 'rgb(204, 204, 204)'
,linewidth = 2
,autotick = FALSE
,ticks = 'outside'
,tickcolor = 'rgb(204, 204, 204)'
,tickwidth = 2
,ticklen = 5
,tickfont = list(family = 'Helvetica'
,size = 12
,color = 'rgb(82, 82, 82)')
)
yaxis1 <- list(title = list(text = "Units built per project"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showgrid = FALSE
,zeroline = FALSE
,showline = TRUE
,showticklabels = TRUE
,tickfont = list(family = 'Helvetica',
size = 12,
color = 'rgb(82, 82, 82)')
,range= c(0,30))
p <- plot_ly(Hbrooms2018,y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==1], type = "box",name = "1") %>%
add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==2],name="2") %>%
add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==3],name="3") %>%
add_trace(y=~Hbrooms2018$`Proposed units`[`Number of bedrooms`==4],name="4") %>%
layout(title ="Building projects by units built with respect to number of bedrooms"
, xaxis = xaxis1
, yaxis = yaxis1
, autosize = FALSE
, showlegend = FALSE
, margin = margin
)
p
# Nbofroomsbuilt <- data.frame(nbrooms2013$`Number of bedrooms`
# ,nbrooms2013$`Number of units built`
# ,nbrooms2014$`Number of units built`
# ,nbrooms2015$`Number of units built`
# ,nbrooms2016$`Number of units built`
# ,nbrooms2017$`Number of units built`
# ,nbrooms2018$`Number of units built`
# ,check.rows = TRUE
# )
# histo <- plot(nbrooms2013, type = "h",main = "2013")
# plot(nbrooms2014, type = "h",main = "2014")
# plot(nbrooms2015, type = "h",main = "2015")
# plot(nbrooms2016, type = "h",main = "2016")
# plot(nbrooms2017, type = "h",main = "2017")
# plot(nbrooms2018, type = "h",main = "2018")
# colnames(Nbofroomsbuilt) <- c("Nb of units built 2013"
# ,"Nb of units built 2014"
# ,"Nb of units built 2015"
# ,"Nb of units built 2016"
# ,"Nb of units built 2017"
# ,"Nb of units built 2018"
# )
m1 <- glm(`Number of bedrooms` ~ `Number of units built`,family="poisson", data = nbrooms2018)
summary(m1, dispersion = 1)
anova (m1, dispersion = 1, test = "Chisq")
plot(m1)
mymean <- function(donnees){
return(sum(donnees[,1]*donnees[,2])/sum(donnees[,2]))
}
mu2018 <- mymean(nbrooms2018)
meanI <- data.frame(mu2013,mu2014,mu2015,mu2016,mu2017,mu2018)
mean <- data.frame(c(2013:2018), c(0))
for (i in c(1:6)){
mean[i,2] <- meanI[i]
}
colnames(mean) <- c("Year", "Average number of bedrooms")
mu2018 <- mymean(nbrooms2018)
totalunits <- data.frame(c(2013:2018),c(0))
totalunits[1,2] <- sum(nbrooms2018$`Number of units built`)
totalunits[2,2] <- sum(nbrooms2017$`Number of units built`)
totalunits[3,2] <- sum(nbrooms2016$`Number of units built`)
totalunits[4,2] <- sum(nbrooms2015$`Number of units built`)
totalunits[5,2] <- sum(nbrooms2014$`Number of units built`)
totalunits[6,2] <- sum(nbrooms2013$`Number of units built`)
colnames(totalunits) <- c("Year","Total units built")
ttunitsYear <- plot(totalunits, type = "b")
meanroomsYear <- plot(mean, type = "b")
vari <- var(nbrooms2013$`Number of bedrooms`)
resume <- data.frame(totalunits,mean$`Average number of bedrooms`)
margin <- list(autoexpand = FALSE,
l = 50,
r = 50,
t = 50)
xaxis <- list(title = list(text = "Year"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showline = TRUE,
showgrid = FALSE,
showticklabels = TRUE,
linecolor = 'rgb(204, 204, 204)',
linewidth = 2,
autotick = FALSE,
ticks = 'outside',
tickcolor = 'rgb(204, 204, 204)',
tickwidth = 2,
ticklen = 5,
tickfont = list(family = 'Helvetica',
size = 12,
color = 'rgb(82, 82, 82)'))
yaxis <- list(title = list(text = "Units built"
,font = list(family = 'Helvetica'
,size = 18
,color = 'rgb(82, 82, 82)')
,standoff = 0
)
,showgrid = FALSE
,zeroline = FALSE
,showline = TRUE
,showticklabels = TRUE
,tickfont = list(family = 'Helvetica',
size = 12,
color = 'rgb(82, 82, 82)'))
unitsbuilt <- plot_ly(totalunits
,x = ~Year
,y = ~`Total units built`
,type = 'scatter'
,mode = 'lines+markers'
,width = 500
,height = 400
,line = list(color = 'rgb(0, 0, 0)', width = 2)
,marker = list(size = 5
,color = 'rgb(0, 0, 0)'
,line = list(color = 'rgb(0, 0, 0)'
,width = 2)
)) %>%
layout(title = "Number of units built"
, xaxis = xaxis
, yaxis = yaxis
, autosize = FALSE
, showlegend = FALSE
, margin = margin)
unitsbuilt
avbedrooms <- plot_ly(mean
, x = ~Year
, y = ~`Average number of bedrooms`
, type = 'scatter'
, mode = 'lines+markers'
, width = 500
, height = 400
,line = list(color = 'rgb(0, 0, 0)', width = 2)
,marker = list(size = 5
,color = 'rgb(0, 0, 0)'
,line = list(color = 'rgb(0, 0, 0)'
,width = 2)
)
) %>%
layout(title = "Average number of bedrooms per unit"
, xaxis = xaxis
, yaxis = yaxis
, autosize = FALSE
, showlegend = FALSE
, margin = margin)
avbedrooms
colonnes
x <-c(1:5)
y <- dpois(x, lambda = mean$`2013`)
plot(x,y)
colnames(meanI) <- c(2013:2018)
mean <- meanI
nbrooms2013$poisson=dpois(nbrooms2013$`Number of bedrooms`,mean$`2013`)
nbrooms2014$poisson=dpois(nbrooms2014$`Number of bedrooms`,mean$`2014`)
nbrooms2015$poisson=dpois(nbrooms2015$`Number of bedrooms`,mean$`2015`)
nbrooms2016$poisson=dpois(nbrooms2016$`Number of bedrooms`,mean$`2016`)
nbrooms2017$poisson=dpois(nbrooms2017$`Number of bedrooms`,mean$`2017`)
nbrooms2018$poisson=dpois(nbrooms2018$`Number of bedrooms`,mean$`2018`)
nbrooms2013$`Number of units built` <- nbrooms2013$`Number of units built`/sum(nbrooms2013$`Number of units built`)
nbrooms2014$`Number of units built` <- nbrooms2014$`Number of units built`/sum(nbrooms2014$`Number of units built`)
nbrooms2015$`Number of units built` <- nbrooms2015$`Number of units built`/sum(nbrooms2015$`Number of units built`)
nbrooms2016$`Number of units built` <- nbrooms2016$`Number of units built`/sum(nbrooms2016$`Number of units built`)
nbrooms2017$`Number of units built` <- nbrooms2017$`Number of units built`/sum(nbrooms2017$`Number of units built`)
nbrooms2018$`Number of units built` <- nbrooms2018$`Number of units built`/sum(nbrooms2018$`Number of units built`)
totalunits
plot(Hbrooms2018$`Number of bedrooms`,Hbrooms2018$`Proposed units`)
# KIND OFF HISTOGRAMM OF THE SIZE OF EACH CONSTRUCTION PROJECT
Hbrooms <- plot_ly(Hbrooms2018
, x= ~`Number of bedrooms`
, y= ~`Proposed units`
, name = ''
, type = 'scatter'
, mode = 'markers'
#,connectgaps = TRUE
#,line = list(color = 'rgb(0, 0, 0)', width = 2)
,marker = list(size = 5
,color = 'rgb(0, 0, 0)'
,line = list(color = 'rgb(0, 0, 0)'
,width = 2))) %>%
layout(title ="Projects by units built with respect to bedrooms number"
, xaxis = xaxis
, yaxis = yaxis
, autosize = FALSE
, showlegend = FALSE
, margin = margin
)
Hbrooms
#OUTLINE OF THE POISSON DENSITY IN THE DATA
NBRooms <- plot_ly(nbrooms2018
, x= ~`Number of bedrooms`
, y= ~`Number of units built`
, name = ''
, type = 'scatter'
, mode = 'lines+markers'
#,connectgaps = TRUE
,line = list(color = 'rgb(0, 0, 0)', width = 2)
,marker = list(size = 5
,color = 'rgb(0, 0, 0)'
,line = list(color = 'rgb(0, 0, 0)'
,width = 2))) %>%
layout(title ="Units built in 2018"
, xaxis = xaxis
, yaxis = yaxis
, autosize = FALSE
, showlegend = FALSE
, margin = margin
)
NBRooms
# add_trace(nbrooms2017,x~=`Number of bedrooms`, y=~`Number of units built`
# ,type = 'scatter'
# , mode = 'markers'
# #,connectgaps = TRUE
# ,line = list(color = 'rgb(0, 0, 0)', width = 2)
# ,marker = list(size = 5
# ,color = 'rgb(0, 0, 255)'
# ,line = list(color = 'rgb(0, 0, 0)'
# ,width = 2)))
# add_trace(nbrooms2014
# ,x= ~`Number of bedrooms`
# ,y= ~`Number of units built`
# ,name = "2014"
# ,line = list(color = 'rgb(22, 96, 167)'
# , width = 4)
# ,marker = list(size = 5
# ,color = 'rgb(0, 0, 0)'
# ,line = list(color = 'rgb(0, 0, 0)'
# ,width = 2))
# ) %>%