This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(deldir) | |
| library(ggplot2) | |
| library(firatheme) | |
| N <- 40 | |
| dat <- matrix(rnorm(N*2), N) | |
| dat <- dat %*% chol(matrix(c(1, 0, 0, 1.5), 2)) %*% chol(solve(cov(dat))) | |
| dat2 <- deldir(dat[,1], dat[,2]) | |
| dat1 <- data.frame(dat) | |
| colnames(dat1) <- c("x1", "y1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(sf) | |
| library(httr) | |
| library(tidyverse) | |
| url <- parse_url("https://geodata.nationaalgeoregister.nl/bag/wfs/v1_1") | |
| postcode_filter <- function(postcode, gebruiksdoel = "woonfunctie") { | |
| sprintf( | |
| "<Filter> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(sf) | |
| library(osmdata) | |
| library(osmenrich) | |
| library(patchwork) | |
| # conditional IDW functions | |
| conditional_idw <- function(formula, data, p = 1, max.iter = 100, tol = 1e-10) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rtrunc <- function(rdist, min, max) { | |
| # deal with pipe and also with normal evaluation | |
| # https://github.com/tidyverse/magrittr/issues/115#issuecomment-173894787 | |
| parents <- lapply(sys.frames(), parent.env) | |
| is_magrittr_env <- vapply(parents, identical, logical(1), y = environment(`%>%`)) | |
| if (any(is_magrittr_env)) { | |
| distcall <- get("lhs", sys.frames()[[base::max(which(is_magrittr_env))]]) | |
| } else { | |
| distcall <- substitute(rdist) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Gierzwaluw (common swift) analysis using osmenrich | |
| # Last edited 2021-02-09 by @vankesteren | |
| # CC-BY ODISSEI SoDa team | |
| # Packages | |
| # Data | |
| library(tidyverse) | |
| library(sf) | |
| library(osmenrich) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Meuse universal kriging for a large grid | |
| # The grid is enriched with osm data | |
| # CC-BY @vankesteren | |
| # load packages ---- | |
| library(tidyverse) | |
| library(sf) | |
| library(ggspatial) | |
| library(osmdata) | |
| library(gstat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Bayesian test for partial intransitivity using monte-carlo posterior approximation | |
| # (c) Erik-Jan van Kesteren, 2021 | |
| # Based on an e-mail discussion with Tony Marley | |
| library(expm) | |
| library(tidyverse) | |
| # Beta prior (1, 1 means uniform) | |
| prior_a <- 1 | |
| prior_b <- 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kmedoids <- function(X, K, max_iter = 100) { | |
| X <- as.matrix(X) | |
| N <- nrow(X) | |
| P <- ncol(X) | |
| C <- matrix(0, nrow = K, ncol = P) | |
| clus <- sample(K, N, replace = TRUE) | |
| converged <- FALSE | |
| iter <- 0 | |
| while (!converged && iter < max_iter) { | |
| old_clus <- clus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # gaussian mixture modeling with EM | |
| priorp <- 0.6 | |
| m1 <- 0 | |
| m2 <- 2 | |
| s1 <- 1 | |
| s2 <- 0.707 | |
| # generate some data with 2 classes | |
| N <- 1000 | |
| cl <- rbinom(N, 1, priorp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lavPredict from tensorsem parameters | |
| library(lavaan) | |
| library(tensorsem) | |
| mod <- " | |
| # three-factor model | |
| visual =~ x1 + x2 + x3 | |
| textual =~ x4 + x5 + x6 | |
| speed =~ x7 + x8 + x9 | |
| " |