Skip to content

Instantly share code, notes, and snippets.

View agila5's full-sized avatar

Andrea Gilardi agila5

View GitHub Profile
# Sia X1, ..., Xn un campione casuale estratto da X ~ N(0, 1). Dalla teoria
# dell'inferenza statistica, sappiamo che lo stimatore
#
# (n - 1) S^2 / sigma ^ 2= 1 / sigma ^ 2 * sommatoria di (x_i - x_medio) ^ 2
#
# ha distribuzione Chi-quadrato con n - 1 gradi di liberta. Proviamo a
# verificare empiricamente questa affermazione.
m <- 1e4 # numero di simulazioni usate per approssimare la distribuzione
n <- 100 # numero di elementi nel campione
# get data
library(osmextract)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Check the package website, https://docs.ropensci.org/osmextract/, for more details.
munich_multilines <- oe_get(
  place = "Muenches", 
  layer = "multilinestrings", 
  provider = "bbbike", 
 extra_tags = "route"
# packages
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(sfnetworks)
data_old <- tibble::tibble(
  "Location_Northing_OSGR" = c(1, 2, 3), 
  '1st_Road_Number' = c("a", "b", "c")
)
janitor::clean_names(data_old, replace = c("1" = "fir"))
#> # A tibble: 3 x 2
#>   location_northing_osgr first_road_number
#>                    <dbl> <chr>            
#&gt; 1 1 a 
# packages
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(osmextract)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Check the package website, https://docs.ropensci.org/osmextract/, for more details.
# packages
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.geom
#> spatstat.geom 2.2-2
#> Loading required package: spatstat.core
#> Loading required package: nlme
#> Loading required package: rpart
#> spatstat.core 2.3-0
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
string <- "\"sidewalk\"=>\"none\""
print(string, quote = FALSE)
#> [1] "sidewalk"=>"none"
read.table(
  text = gsub(',?([^,]+)=>',"\n\\1:", string, perl = TRUE), 
  sep = ":", 
  col.names = c("key", "value")
)
#&gt; key value
# packages
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(sfnetworks)

# create network
roxel_sfn <- as_sfnetwork(roxel, directed = FALSE)

# sample two points in that area
# packages
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter