This file contains 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 |
This file contains 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 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 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 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 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
# Fit model combining live recapture and dead recoveries in Jags using SSM formulation of multistate models | |
# Warning: if initial values are generated from the ld.init() function, we failed at recovering the values | |
# used to simulate the data; everything goes well if we use the true latent states (data are simulated) as initial values | |
# Define function to simulate multistate capture-recapture data | |
simul.ms <- function(PSI.STATE, PSI.OBS, marked, unobservable = NA){ | |
# Unobservable: number of state that is unobservable | |
n.occasions <- dim(PSI.STATE)[4] + 1 | |
CH <- CH.TRUE <- matrix(NA, ncol = n.occasions, nrow = sum(marked)) | |
# Define a vector with the occasion of marking |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains 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
h1;h2;h3;h4;h5;h6;h7;males;females | |
1;1;1;1;1;1;0;1;0 | |
1;1;1;1;1;0;0;0;1 | |
1;1;1;1;0;0;0;1;0 | |
1;1;1;1;0;0;0;0;1 | |
1;1;0;1;1;1;0;0;1 | |
1;1;0;0;0;0;0;1;0 | |
1;1;0;0;0;0;0;1;0 | |
1;1;0;0;0;0;0;1;0 | |
1;1;0;0;0;0;0;1;0 |
This file contains 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
# illustrates grouped lasso with simulations | |
# with normal and non-normal responses | |
# and a mix and discrete/continuous predictors | |
#----- normal response | |
library(gglasso) | |
create_factor <- function(nb_lvl, n = 100 ){ | |
factor(sample(letters[1:nb_lvl],n, replace = TRUE))} |
This file contains 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
#------- inspiration: https://www.nytimes.com/2020/12/28/science/math-conway-game-of-life.html | |
#------- see also https://medium.com/tebs-lab/optimizing-conways-game-of-life-12f1b7f2f54c | |
#---- implementation 1 | |
install.packages("fun") | |
library(fun) | |
demo("GameOfLife") | |
#---- implementation 2 (https://www.r-bloggers.com/2012/11/fast-conways-game-of-life-in-r/) |
This file contains 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
# je suis parti de ce post | |
# https://darrenjw.wordpress.com/2012/11/20/getting-started-with-bayesian-variable-selection-using-jags-and-rjags/ | |
# je n ai utilise que le code de la section "Basic variable selection" c'est a dire que | |
# j ai laisse tombé les modifs sur le code que l'auteur propose dans les sections | |
# "Variable selection with random effects" et "Variable selection with random effects and a prior on the inclusion probability" | |
# j ai rajoute des lignes de code a la fin pour calculer les probabilites a posteriori des modeles | |
# (voir par exemple la table 2 dans https://dl.dropboxusercontent.com/u/23160641/my-pubs/Gimenezetal2009Evolution.pdf) |
OlderNewer