Articles

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)) {   ...

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

Migration to MacOSX 10.14 Mojave

After install, open Xcode and install commande line tools at front. In terminal: sudo xcodebuild -license type agree after many pages then sudo xcode-select --install defaults write org.R-project.R force.LANG fr_FR.UTF-8 sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Bayesian or frequentist test

This note is based on a discussion with Jean-Michel Guillon. The idea was to test an idea from this this paper: Sterne, J.A.C., Smith, G.D., 2001. Sifting the evidence-what’s wrong with significance tests? British Medical Journal 322, 226-231. If our prior opinion about the risk ratio is vague (we consider a wide range of values to be equally likely) then the results of a frequentist analysis are similar to the results of a bayesian analysis; both are based on what statisticians call the likelihood for the data: • The 95% confidence interval is the same as the 95% credible interval, except that the latter has the meaning often incorrectly ascribed to a confidence interval; • The (one sided) P value is the same as the bayesian posterior probability that the drug increases the risk of death (assuming that we found a protective effect of the drug). The two approaches, however, will give different results if our prior opinion is not vague, relative to the amount of informatio...

On the use of OR | operator in regular expression

I had some difficulties to use the OR | operator in regular expressions. Let do some exercises and examine the results: gregexpr("bc", "abcd") : return 2; normal, bc is located at the second position gregexpr("b|c", "abcd") : return 2 3; | is the OR operator and it will return the position of b OR c this is the same than : gregexpr("[bc]", "abcd") or gregexpr("[b|c]", "abcd") But | and [] are not always the same: Let do more complicated: gregexpr("ab|cd", "abcd") My problem was about the priority order of | operator. The return here is 1 3 It means that the search was for a followed by b OR c followed by d. Let do more complicated : gregexpr("a[bc]d", "abcd") : return -1; it search for abd or acd. None exist In practice, it is good to remember that | separates blocks of comparisons.

[0-9] or \d or [:digit:] in grep

If you want search for a number using grep, you have 4 options: [0123456789] or [0-9] or \d or [:digit:] Here is a comparison: library(microbenchmark) microbenchmark({grep(pattern="[0123456789][0123456789][0123456789][0123456789]", "Ussiosuus8980JJDUD98")},                 {grep(pattern="[0-9][0-9][0-9][0-9]", "Ussiosuus8980JJDUD98")},                 {grep(pattern="[[:digit:]][[:digit:]][[:digit:]][[:digit:]]", "Ussiosuus8980JJDUD98")},                 {grep(pattern="\\d\\d\\d\\d", "Ussiosuus8980JJDUD98")}, times = 1000L)     min      lq      mean  median      uq    max neval  cld  21.729 22.1840 22.887585 22.3090 22.4645 64.542  1000    d   5.219  5.3740  5.696937  5.4665  5.8495 47.618  1000 a     ...