Articles

Affichage des articles du octobre, 2018

Analyse de la sensibilité de la sortie d'un automate cellulaire

Image
Analyse de la sensibilité d'un automate cellulaire # Fonction qui calcule le nombre de cases occupées (=1) en fonction d'une variable X # qui est un data.frame qui contient les probabilités de mourir à chaque pas de temps (p) et  # le nombre de cases (/9) pour obtenir un décès d'étouffement. # La variable t donne les temps pour lesquels on retourne la taille de la population # Si t est une valeur, on retourne juste la valeur pour ce temps, si t est un vecteur,  # on retourne toutes les valeurs pour les temps t ac <- function(X, t=t) {   Nfinal <- NULL   for (grandtotal in 1:nrow(X)) {     penc <- X[grandtotal, 1]     v <- X[grandtotal, 2]*9     m <- matrix(data = 0, ncol=12, nrow=12)   for (i in 1:10) {     col <- sample(1:10, 1)+1     row <- sample(1:10, 1)+1     m[row, col] <- 1   }   N <- NULL   for (tps in 1:max(t)) {     m1 <- m       for (col in 2:11) {       for (row in 2:11) {         voisins <- sum(

The mess of linear regressions

Image
Everyone has done a linear regression... but not everyone knows really how to do a linear regression. There are several methods which produce different outputs. Here is a little synthesis: # Let generate data. Note the the scale for x and y are different. # the set.seed(1) makes sure that the data are always the same # to make reproduced examples set.seed(1) x <- 1:10 y <- 10*x+rnorm(10, 5, 20) plot(x, y, bty="n", las=1) # First method. Only error on y axis is supposed # The square of the residuals on y axis is minimized # Why the sum of square? It is grounded on the likelihood of Gaussian distribution for residuals lm(y~ x) abline(lm(y~ x), col="red") # second, very similar to previous one, only error on x axis is supposed # The square of the residuals on x axis is minimized ir <- coef(lm(x~y)) print(c(-ir[1]/ir[2],1/ir[2])) abline(-ir[1]/ir[2],1/ir[2], col="blue") # The choice between error inputed

To read grib and grib2 file format

grib and grib2 are format used to store meteorological data. It is the native format used by ECMWF server. To read it in R with MacOSX: Using Macport, install the library wgrib2: sudo port install wgrib2 You must also install the wgrib library: Look at here: https://rda.ucar.edu/datasets/ds083.2/software/wgrib_install_guide.txt Then you can install rNOMAD package in R You must install gdal library You can use also the raster package with rgdal and goal library 4 packages can be used: rNOMAD, rgdal, raster, stars I found that the simple is to use rgdal