
¡¡¡¡¡¡ Freedom !!!!!!
SPSS
ArcGIS
Notepad
GWR4.0
Notepad
ArcGIS
Word
# Load data data(LondonHP) # Create distance matrix DM <- gw.dist(dp.locat=coordinates(londonhp)) # Create optimized bandwidth bw1 <- bw.gwr(PURCHASE~FLOORSZ, data=londonhp, kernel = "gaussian",dMat=DM)
## Fixed bandwidth: 28008.52 CV score: 901202470969 ## Fixed bandwidth: 17313.68 CV score: 842907727581 ## Fixed bandwidth: 10703.9 CV score: 736181883398 ## Fixed bandwidth: 6618.837 CV score: 607130814353 ## Fixed bandwidth: 4094.128 CV score: 529769270141 ## Fixed bandwidth: 2533.772 CV score: 496244493691 ## Fixed bandwidth: 1569.419 CV score: 558268461315 ## Fixed bandwidth: 3129.775 CV score: 504912379213 ## Fixed bandwidth: 2165.422 CV score: 500148436808 ## Fixed bandwidth: 2761.425 CV score: 498237171785 ## Fixed bandwidth: 2393.075 CV score: 496399101924 ## Fixed bandwidth: 2620.728 CV score: 496732595196 ## Fixed bandwidth: 2480.03 CV score: 496150911653 ## Fixed bandwidth: 2446.816 CV score: 496183570335 ## Fixed bandwidth: 2500.558 CV score: 496166149711 ## Fixed bandwidth: 2467.344 CV score: 496154814854 ## Fixed bandwidth: 2487.871 CV score: 496153635785 ## Fixed bandwidth: 2475.184 CV score: 496151178429 ## Fixed bandwidth: 2483.025 CV score: 496151494463 ## Fixed bandwidth: 2478.179 CV score: 496150836405 ## Fixed bandwidth: 2477.035 CV score: 496150899230 ## Fixed bandwidth: 2478.886 CV score: 496150839373 ## Fixed bandwidth: 2477.742 CV score: 496150850527 ## Fixed bandwidth: 2478.449 CV score: 496150833774 ## Fixed bandwidth: 2478.616 CV score: 496150834475 ## Fixed bandwidth: 2478.346 CV score: 496150834229 ## Fixed bandwidth: 2478.513 CV score: 496150833832 ## Fixed bandwidth: 2478.41 CV score: 496150833868 ## Fixed bandwidth: 2478.474 CV score: 496150833765 ## Fixed bandwidth: 2478.489 CV score: 496150833779 ## Fixed bandwidth: 2478.465 CV score: 496150833764 ## Fixed bandwidth: 2478.459 CV score: 496150833766 ## Fixed bandwidth: 2478.468 CV score: 496150833764 ## Fixed bandwidth: 2478.47 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.466 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.468 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764 ## Fixed bandwidth: 2478.467 CV score: 496150833764
# Run GWR
gwr.res1 <- gwr.basic(PURCHASE~FLOORSZ, data=londonhp,
bw=bw1,kernel = "gaussian", dMat=DM)
# Make map interactive
tmap_mode("view")
# Take spatial data, change format, make sure projection is correct, create map
gwr.res1$SDF %>% st_as_sf() %>% st_set_crs(27700) %>%
tm_shape()+tm_dots(col="FLOORSZ", palette="RdYlGn") -> plot1
By the end of this session you will be able to:

Wiersma et al. 2022

Rijnks et al. 2022
Overview of RStudio
Basic R commands
Links to books / examples
File –> New Project
New Directory –> New Project
Give it a name (e.g. Winterschool) and location (e.g. Desktop)
Start a new file in that project: Quarto Document
Sort of optional: Change the “editor” from “visual” to “source”
# Install the packages
install.packages("tidyverse")
install.packages("sf")
install.packages("tmap")
install.packages("GWmodel")
install.packages("RColorBrewer")
install.packages("kableExtra")
install.packages("gridExtra")
# Load the packages (note the lack of quotation marks)
library(tidyverse)
library(sf)
library(tmap)
library(GWmodel)
library(RColorBrewer)
library(kableExtra)
# Data as part of packages
data(LondonHP)
# Change from SpatialPointsDataFrame (old) to SF (modern)
london_sf <- londonhp %>% st_as_sf() %>% st_set_crs(27700)
# CSV files
#read.csv("path_to_data")
# Dutch CSV files (if your data comes in as: however many observations of 1 variable...)
#read.csv2("path_to_data")
# R proprietary files
#load("name_of_data.Rda")
# SPSS files? See package: "foreign" or "haven". Stata13 files? see package "readstata13"
# Shapefiles? st_read("path_to_shape.shp")
head(london_sf)
## Simple feature collection with 6 features and 20 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 531900 ymin: 159400 xmax: 535700 ymax: 161700 ## Projected CRS: OSGB36 / British National Grid ## PURCHASE FLOORSZ TYPEDETCH TPSEMIDTCH TYPETRRD TYPEBNGLW TYPEFLAT BLDPWW1 ## 0 157000 77 1 0 0 1 0 0 ## 1 113500 75 0 0 1 0 0 1 ## 2 81750 64 0 0 0 0 1 0 ## 3 150000 95 0 1 0 0 0 0 ## 4 190000 107 1 0 0 0 0 0 ## 5 159950 100 0 1 0 0 0 0 ## BLDPOSTW BLD60S BLD70S BLD80S BLD90S BATH2 BEDS2 GARAGE1 CENTHEAT UNEMPLOY ## 0 0 0 0 0 0 0 1 0 1 0.03566768 ## 1 0 0 0 0 0 0 1 0 1 0.03566768 ## 2 0 0 0 1 0 0 0 1 0 0.03566768 ## 3 0 0 0 0 0 0 1 0 1 0.03566768 ## 4 0 0 0 0 0 0 1 1 1 0.03566768 ## 5 0 0 1 0 0 0 1 1 1 0.02408854 ## PROF BLDINTW geometry ## 0 0.4786992 1 POINT (533200 159400) ## 1 0.4786992 0 POINT (533300 159700) ## 2 0.4786992 0 POINT (532000 159800) ## 3 0.4786992 1 POINT (531900 160100) ## 4 0.4786992 1 POINT (532800 160300) ## 5 0.4773715 0 POINT (535700 161700)
#View(london_sf)
?LondonHP
- use the dollar sign to access variables: london_sf$BEDS2 - table(x) creates simple tables - cor(x,y) correlates variables - cor.test(x,y) runs correlation test - draw map: qtm(shapefilename, dots.col="VARIABLE_YOU_WANT") - note the quotation marks
london_sf %>% mutate(log_purch = log(PURCHASE)) %>% tm_shape() + tm_dots(col="log_purch", palette="-RdYlGn")
# to see more options go to:
# vignette("tmap-getstarted")

marathoninvestigation.com, 17-2-2017
london_sf %>% st_drop_geometry() %>%
ggplot(aes(x=FLOORSZ, y=PURCHASE))+
geom_point() + theme_classic()
london_sf %>% st_drop_geometry() %>% mutate(PURCHASE = log(PURCHASE), FLOORSZ = log(FLOORSZ)) %>% lm(PURCHASE ~ FLOORSZ, data=.) -> lm1 library(xtable) # make sure to mark the chunk with results='asis' print(xtable(summary(lm1)),type='html')
| Estimate | Std. Error | t value | Pr(>|t|) | |
|---|---|---|---|---|
| (Intercept) | 8.4775 | 0.1986 | 42.69 | 0.0000 |
| FLOORSZ | 0.7611 | 0.0450 | 16.92 | 0.0000 |
All of the following is from:
varianceexplained.org/r/trumptweets
varianceexplained.org/r/trumptweets
varianceexplained.org/r/trumptweets
varianceexplained.org/r/trumptweets
https://bookdown.org/yihui/bookdown/
“Reproducible science helps you do science, better science”
Reproducing science is a valid way of “doing” science
Reproducible science reduces errors in new studies
Reproducible science reduces publication bias, effect size bias, etc.
Reproducible science helps you do science
Better science
Reproducing science: Kuhn: The structure of Scientific Revolutions
It’s also a great way of getting cited…