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
| ################################################################################## | |
| # How to calculate wAIC with JAGS: Linear regression example # | |
| # https://sourceforge.net/p/mcmc-jags/discussion/610036/thread/8211df61/#ea5c # | |
| ################################################################################## | |
| #--- Simulate data | |
| set.seed(2020) # set seed | |
| n <- 100 # sample size | |
| x <- sort(rnorm(n)) # covariate values | |
| int <- 30 # true intercept |
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
| # https://twitter.com/GeoffZahn/status/1318653420027273216?s=20 | |
| library(tidyverse) | |
| data_frame(t=seq(-pi, 0, .001), | |
| x1=16*(sin(t))^2, | |
| x2=-x1, | |
| y=13*cos(t) -5 * cos(2*t) -2*cos(3*t) - cos(4*t)) %>% | |
| gather(side, x, x1, x2) %>% | |
| ggplot(aes(x,y)) + | |
| geom_polygon(fill="red") + | |
| coord_fixed() + |
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
| # map highways in Switzerland - France | |
| # load packages | |
| library(tidyverse) | |
| library(sf) | |
| library(osmdata) | |
| library(mapview) | |
| # define zone of interest | |
| lonmin <- 6 |
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
| # simple example to mimic what predict.gam does | |
| library(mgcv) # GAM package, see Wood's book https://www.taylorfrancis.com/books/9781315370279 | |
| dat <- MASS::mcycle # get mcycle data | |
| head(dat) | |
| # set up a smoother | |
| sm <- smoothCon(s(times, k = 10), data = dat, knots = NULL)[[1]] | |
| # use it to fit a regression spline model | |
| beta <- coef(lm(dat$accel ~ sm$X - 1)) | |
| # plot data | |
| plot(dat$times, dat$accel) |
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
| # code from https://gist.github.com/d-qn/4f1c4ed80a4fd6a76cd1153c89f56134 | |
| library(tidyverse) | |
| library(sf) | |
| library(osmdata) # to get openstreetmap geo data | |
| # settings | |
| # olivier: get data on Montpellier | |
| bb <- getbb('Montpellier, France') # define the bbox, will be used to fetch OSM data within that box | |
| dest_proj <- 2056 |
NewerOlder