Articles

Affichage des articles du avril, 2023

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")