Skip to content

Instantly share code, notes, and snippets.

View agila5's full-sized avatar

Andrea Gilardi agila5

View GitHub Profile
# 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"
# 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
suppressPackageStartupMessages({library(spatstat)}) 

vertices <- ppp(
  c(0, 1, 2,  1, 1), 
  c(0, 1, 0, -1, 0),
  window = owin(c(-1, 3), c(-2, 2))
) 

#matrice di adiacenza 
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Download global NDVI data which average the values from 2024-05-01 to 2024-05-10
options(timeout = 1200)
tmp_nc <- tempfile(fileext = ".nc")
download.file(
@agila5
agila5 / st_covers.md
Last active April 7, 2025 08:26
Covers vs intersects
# Packages
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Let's work on the unit square
unit_square <- st_as_sfc(st_bbox(c(xmin = 0, xmax = 1, ymin = 0, ymax = 1)))

# Let's divide the unit square into 1600 (regular) cells
cells <- st_as_sf(st_make_grid(unit_square, cellsize = c(0.025, 0.025)))
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.univar
#> spatstat.univar 3.1-3
#> Loading required package: spatstat.geom
#> spatstat.geom 3.4-1
#> Loading required package: spatstat.random
#> spatstat.random 3.4-1
#> Loading required package: spatstat.explore
@agila5
agila5 / boundary-points.md
Created August 6, 2025 17:47
boundary-points
library(tidyverse)
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
library(spData)
#> To access larger datasets in this package, install the spDataLarge
#> package with: `install.packages('spDataLarge',
#> repos='https://nowosad.github.io/drat/', type='source')`
# You need the development version of sfnetworks: 
# remotes::install_github("luukvdmeer/sfnetworks")
@agila5
agila5 / mppm-error.md
Created September 28, 2025 20:48
Showcase error with mppm
# Packages and data
library(spatstat)
library(dplyr)
library(splines)
dataNBA <- read.csv(unz("data/newDataNBA.zip", "newDataNBA.csv"))

# The observation window
crcl <- function(x0, y0, r, span = r, nsteps = 100) {
  x <- seq(x0 - span, x0 + span, length.out = nsteps)
library(ggplot2)

toy <- data.frame(
  x = 1:5, 
  y = exp(1:5)
)

ggplot(toy) + 
 geom_point(aes(x, y))
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.univar
#> spatstat.univar 3.1-4
#> Loading required package: spatstat.geom
#> spatstat.geom 3.5-0.008
#> Loading required package: spatstat.random
#> spatstat.random 3.4-1
#> Loading required package: spatstat.explore