Articles

Affichage des articles du 2023

install ggdist for R 4.4 dev on Mac M2

 I get an error when I tried install ggdist package for R 4.4 dev on Mac M2. The dynamic library was not present at the correct place. Here is the solution: cd /Library/Frameworks/R.framework/Resources/lib/ ln -s /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib/libtbb.dylib libtbb.dylib And it works.

Print messages on console during parallel computing

An exemple that print messages during parallel computing library(pbmcapply) # Can work with mclapply also cores <- 2 lazyChattySqrt <- function(num, name) {      # Sleep 2 seconds      Sys.sleep(2)      system(sprintf("echo '\nHello\n'"))      return(sprintf("Hello %s, the sqrt of %f is %f.", toString(name), num, sqrt(num)))  } chattyResult <- pbmclapply(1:3, lazyChattySqrt, "Bob", mc.cores = cores)

Install RNetCDF in Ubuntu 22

 I was force to do: cd /usr/lib/R/ mkdir share cd share mkdir make cd /usr/lib/R/share/make/ sudo ln -s /usr/share/R/share/make/shlib.mk shlib.mk And then in R,  install.packages("RNetCDF", type="source") was possible.

Binomial confidence limit

Hmisc: version 5.1-1 binom: version 1.1-1.1 binomCI: version 1.0 DescTools:  version 0.99.50 I just notice a difference when x=1 or x=n-1 is observed between the different implementations of the Wilson method: n <- 2 x <- 1 sr_binom <- binom::binom.confint(x=x, n=n, methods = "wilson", conf.level = 0.95) sr_Hmisc <- Hmisc::binconf(x=x, n=n, method = "wilson", alpha = 0.05) sr_binomCI <- binomCI::binomCI(x=x, n=n, a = 0.05) # Warning message: # In sqrt(n - z^2 - 2 * z/sqrt(n) - 1/n) : NaNs produced sr_binom #   method x n mean      lower     upper # 1 wilson 1 2  0.5 0.09453121 0.9054688 sr_Hmisc  # PointEst      Lower     Upper  #     0.5 0.02564665 0.9743534 sr_binomCI$ci["Wilson", ] #    0.025%     0.975%  # 0.09453121 0.90546879  No difference between packages is observed for x=2 for example with n <- 4 and x <- 2. The discrepancy is not observed also with exact method (or exact binomial). When checking the code, I see that in packa

Estimating the SE of MCMC outputs; different methods

# Strategy to manage correctly the MCMC timeseries to get SE set.seed(123) val <- rnorm(30, 10, 2) dnormx <- function(data, x) {   data <- unlist(data)   return(-sum(dnorm(data, mean=x['mean'], sd=x['sd'], log=TRUE))) } parameters_mcmc <- data.frame(Density=c('dnorm', 'dlnorm'),                                Prior1=c(10, 0.5), Prior2=c(2, 0.5), SDProp=c(0.35, 0.2),                                Min=c(-3, 0), Max=c(100, 10), Init=c(10, 2), stringsAsFactors = FALSE,                                row.names=c('mean', 'sd')) # Use of trace and traceML parameters # trace=1 : Only one likelihood is printed mcmc_run <- MHalgoGen(n.iter=50000, parameters=parameters_mcmc, data=val,                        likelihood=dnormx, n.chains=1, n.adapt=100, thin=1, trace=1) # The function as.paramaters gives the best likelihood; it is not really what we want # in the context of MCMC; it is more related to ML as.parameters(mcmc_run) # I have

Run an UNIX application within R

The R command system2() can be very useful when you want run a unix command and get the result in R.  Note that system2() is recommended instead system(). For example: out_grep <- system2("grep", args = " -rnw '.' -e 'essai'", stdout=TRUE) #  I am not sure that it is still true... it seems to work now with path in .zshrc But if you want use a software locate in your path defined in .zshrc, it will not find it. The reason is about interactive versus login shell.  You must include your path in .profile to be sure it will be available both in login and interactive shell. system2("R", args="-e \"print('bonjour');q('no')\"") system2("which", args="R") system2("echo", args="$PATH")