Articles

Run long code in Ubuntu VM

 Run the R code xxxx.R in background. nohup Rscript xxxx.R > mon_script_$(date +%Y%m%d_%H%M).log 2>&1 & echo $! It seems safer than running a backgound job in Rstudio-server You can keep the PID in the name: LOG = "mon_script_ $(date +%Y%m%d_%H%M) .log" ; nohup Rscript xxxx.R > " $LOG " 2 >&1 & PID = $! ; mv " $LOG " " ${LOG%.log} _PID ${PID} .log" ; echo "PID= $PID "

Test for equality of all vector elements

Lets try 4 methods: Using https://www.geeksforgeeks.org/r-language/test-for-equality-of-all-vector-elements-in-r/ as reference Clearly the best solution is  all(x[1] == x)   or  any(x[1] != x)   > library(microbenchmark) > x <- runif(10000000) > microbenchmark({all(x[1] == x)}, {any(x[1] != x)},  +                     {length(unique(x)) != 1}, {var(x) != 0}) Unit: milliseconds                            expr        min         lq      mean     median         uq       max neval          {     all(x[1] == x) }   9.196095   9.388385  11.34733   9.563066  10.537984 119.53070   100          {  ...

Update rstudio-server

rstudio-server stop # look at the last version here:  https://docs.posit.co/ide/user/#rstudio-server-oss-downloads wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2026.08.2-200-amd64.deb sudo gdebi rstudio-server-2026.08.2-200-amd64.deb  rm rstudio-server-2026.08.2-200-amd64.deb  rstudio-server start

Update packages after R 4.6.0 install in Ubuntu 24.04

You must resinstall from source some packages: install.packages("rlang", type="source") install.packages("vctrs", type="source")  After it seems possible to update ggplot2, devtools and pkgload

xcrun produce an error during package compilation

 If you have this error: Avis dans system2("xcrun", "--show-sdk-version", TRUE, TRUE) :   l'exécution de la commande ''xcrun' --show-sdk-version 2>&1' renvoie un statut 1 using SDK: ‘NA’ based on  https://gist.github.com/Justintime50/2349ff5e62555aa097acbf519bbc27af You must reinstall Xcode: 1) Check if Xcode is installed xcode-select -print-path # If the output of the above command is not similar to the following line, Xcode is not installed. Skip to Step 3. # /Library/Developer/CommandLineTools 2) Remove Bad Xcode Installation # Remove Developer folder sudo rm -rf $( xcode-select -print-path ) # Remove CommandLineTools folder sudo rm -rf /Library/Developer/CommandLineTools 3) Install Xcode sudo xcode-select --install Messing with Xcode's Path If the above didn't resolve your issue, you may have a problem with the path Xcode is installed at. Use the following to help if necessary. # Switch Xcode's path sudo xcode-s...

Comparison using WAIC

  P ( Model 1 better than Model 2 ) = Φ ( elpd_diff ​/ se_diff) prob_model_better <- function(elpd_diff, se_diff) {   z <- elpd_diff / se_diff   p <- pnorm(z)   return(p) } elpd_diff <- 5 se_diff <- 3 prob_model_better ( elpd_diff , se_diff ) Result: [1] 0.952 So there is approximately  95% probability that model 1 predicts better than model 2 . It is  not  the probability that the model is  better  — only that its  predictive accuracy is higher . You can use also the function Probability_Best_Model_WAIC() in HelpersMG packages that uses original loo results to compare the predictive accuracy of several models.

When your autocorrelation becomes negative

The negative values appearing at larger lags in the sample autocorrelation function are usually not evidence of true negative dependence but arise from the finite-sample constraint that the estimated autocorrelations must balance around zero once the sample mean has been removed. Positive autocorrelation at small lags forces the estimated ACF at larger lags to become slightly negative  because the correlations must balance around zero in a finite sample .

Error in brm compilation of a Stan model

 Try this  # Compile packages using all cores Sys.setenv ( MAKEFLAGS = paste0 ( "-j" , parallel :: detectCores ( ) ) ) install.packages ( c ( "StanHeaders" , "rstan" ) , type = "source" )

Install ggiraph in MacosX

 nano ~/.R/Makevars Ajouter : CPPFLAGS=-I/opt/homebrew/include LDFLAGS=-L/opt/homebrew/lib Sauvegarder puis relancer R et installer : install.packages("ggiraph", type="source")

Update rJava in Ubuntu 22.04

 First, I have been forced to delete all old installations of open-jdk: sudo apt-get purge openjdk-\* sudo apt autoremove It can be necessary to do: sudo rm -rf /usr/lib/jvm Install most recent version for Ubuntu 22.04 sudo apt install openjdk-25-jdk sudo apt install libicu-dev Then update the variables using: sudo R CMD javareconf And the update of rJava was installing

Pourquoi la p-value est fausse et produit des faux-positifs

 Parce qu’une  p-value  est calculée  conditionnellement à l’hypothèse nulle étant vraie , elle ne représente pas la probabilité de commettre une erreur de type I dans la situation réelle dans laquelle on se trouve. Lorsqu’elle est interprétée de cette façon, elle  surestime systématiquement  le « risque de premier ordre ». Voici le raisonnement précis. 1. Ce qu’est réellement le « risque de premier ordre » Le taux d’erreur de type I (risque de premier ordre) est : α = P ( rejeter  H 0 ∣ H 0  est vraie ) Il s’agit d’une propriété  à long terme , fixée  a priori , d’une règle de décision (par exemple : « rejeter si  p < 0,05 »). Ce n’est  pas  une probabilité concernant l’expérience en cours. 2. Ce qu’est réellement une  p-value Une  p-value  est : p = P ( T ≥ t obs ∣ H 0 ) Points clés : Elle est conditionnelle au fait que  H 0  soit vraie Ce n’est pas  P ( H 0 ∣ donné e s ) Ce n’est pa...

Why p-values over-estimate first order risk ?

 The short answer is: 👉  Because a p-value is computed  conditional on the null hypothesis being true , it does  not  represent the probability of making a Type I error in the situation you are actually in. When it is interpreted as such, it systematically overstates (over-estimates) the “first-order risk”. Below is the precise reasoning. 1. What “first-order risk” really is The  Type I error rate  (first-order risk) is: α = P ( reject  H 0 ∣ H 0  is true ) This is a  long-run, pre-specified  property of a decision rule (e.g. “reject if  p < 0.05 ”). It is  not a probability about the current experiment . 2. What a p-value actually is A p-value is: p = P ( T ≥ t obs ∣ H 0 ) Key points: It is  conditional on  H 0 ​  being true It is  not   P ( H 0 ∣ data ) It is  not   P ( Type I error ) 3. Where the over-estimation comes from The common (incorrect) interpretation “If...

Hypotheses and ANOVA

👉  For ANOVA,  both  the homogeneity of variances and the normality assumptions concern the  errors of the model , so they should be assessed on the  residuals . Below is the precise reasoning, with practical nuances. 1. What ANOVA actually assumes The classical ANOVA model is: Y i j = μ + α i + ε i j Y ij ​ = μ + α i ​ + ε ij ​ with the assumptions: Normality : ε i j ∼ N ( 0 , σ 2 ) ε ij ​ ∼ N ( 0 , σ 2 ) Homoscedasticity : V a r ( ε i j ) = σ 2 Var ( ε ij ​ ) = σ 2  for all groups Independence  of  ε i j ε ij ​ So  both assumptions apply to the  errors , not to the raw response  Y Y . 2. Consequences for diagnostics ✅ Normality Should be assessed on  residuals , not on original data. Raw data can be non-normal simply because group means differ. Correct tools: Q–Q plot of residuals Histogram of residuals Shapiro–Wilk test  on residuals  (with caution) ✅ Homogeneity of variances Also concerns  residual variance ...

Install gsl package in Ubuntu 24.04

 You must first install  sudo apt install libgsl-dev and then you can install gsl package in R: install.packages("gsl")

Fitting an exponential model with log(y) = a + b t or y = exp(a + b t)

  Data x = 2010 : 2020 (11 points) y = ( 10 , 10 , 15 , 20 , 30 , 60 , 100 , 120 , 200 , 300 , 400 ) y = ( 10 , 10 , 15 , 20 , 30 , 60 , 100 , 120 , 200 , 300 , 400 ) To simplify interpretation, the year is often centered: t = x − 2010 = 0 , 1 , … , 10 t = x − 2010 = 0 , 1 , … , 10 1️⃣ Linear regression on log(y) Model log ⁡ ( y ) = α + β t + ε Key assumption the error is  additive on the log scale therefore  multiplicative on the original scale Fit (order of magnitude) One typically obtains something like: log ⁡ ( y ) ≈ 2.2 + 0.36   t Back to the original scale y ^ = exp ⁡ ( 2.2 + 0.36   t ) 👉 regular exponential growth 👉 relative errors are roughly constant 👉 small values have as much weight as large ones 2️⃣ Direct nonlinear regression on y Model y = a e b t + ε Key assumption the error is  additive on y variance is assumed constant on the original scale Typical fit y ^ ≈ 9.5   e 0.39 t Consequences large values (300, 400) strongly dominate the fit early years ...