Articles

Affichage des articles du avril, 2018

Error during packages compilation about -lomp

If you have an error about -lomp, y ou must verify that you have libomp.dylib. The simplest way to do is to in terminal and  activate locate database: sudo /usr/libexec/locate.updatedb This function can be used also to update the database. Then you can do: locate libomp.dylib  | xargs ls -l And the result is for example: -rwxrwxr-x  1 root          admin  508044 26 aoû 22:31 /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libomp.dylib -r--r--r--  1 marcgirondot  admin  442396 31 jan  2018 /usr/local/Cellar/llvm/5.0.1/lib/libomp.dylib -r--r--r--  1 marcgirondot  admin  491820 12 mar 09:38 /usr/local/Cellar/llvm/6.0.0/lib/libomp.dylib -r--r--r--  1 marcgirondot  admin  495888  6 jul 17:11 /usr/local/Cellar/llvm/6.0.1/lib/libomp.dylib Choose the one that you want (here the first one because it is the most recent), and do: sudo ln -s /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libomp.dylib /usr/local/lib/libomp.dylib

Development version of optimx

optimx is a nice replacement of  optim(): install.packages("optimx", repos="http://R-Forge.R-project.org") See  optimx for R - Journal of Statistical Software

Update a package and the dependencies

update.packages(checkBuilt=TRUE, ask=FALSE)

Install rJava in R 3.6 with MacOSX 10.13

Instal homebrew:  https://brew.sh/index_fr In terminal: brew install --with-toolchain llvm in .profile, add: PATH="/usr/local/opt/llvm/bin:${PATH}" LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib" CPPFLAGS="-I/usr/local/opt/llvm/include" export LDFLAGS export CPPFLAGS Install the latest java jdk:  http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Look at here:  https://biostatsr.blogspot.fr/2018/02/set-javahome-to-correct-value-in-profile.html In terminal, enter: cd $(/usr/libexec/java_home)/jre/bin/ sudo ln  $(/usr/libexec/java_home) /bin/javac javac sudo ln  $(/usr/libexec/java_home) /bin/javah javah sudo ln  $(/usr/libexec/java_home) /bin/jar jar cd  $(/usr/libexec/java_home)/jre/lib/ sudo ln  $(/usr/libexec/java_home) /lib/tools.jar tools.jar cd $HOME sudo R CMD javareconf And in R install.packages("rJava")

Some problems about duplicated packages

The libraries are in : R .libPaths() I don't know why but I should set these permissions to allow some packages to be updated. sudo chmod -R 777 /usr/lib/R/library sudo chmod -R 777 /usr/share/R sudo chmod -R 777 /usr/lib/R/site-library sudo chmod -R 777 /usr/local/lib/R/site-library To have the list of duplicated packages: library(HelpersMG) duplicate.packages() To remove some packages, I was forced to run R as root. I don't know why. To do this from Rstudio: (replace PASSWORD, PKG and LIB what what is needed. system("echo PASSWORD | sudo -k -S R -e 'remove.packages(\"PKG\", lib=\"LIB\")'")

stepAIC from package MASS with AICc

Due to a bug in dropterm() and addterm() in package MASS, it is impossible to use AICc with stepAIC() . Here is a solution. Enter these commands and now you can use: stepAIC(g0, criteria="AICc") or stepAIC(g0, criteria="BIC") For example: datax <- data.frame(y=rnorm(100), x1=rnorm(100),                     x2=rnorm(100), x3=rnorm(100), x4=rnorm(100)) g0 <- glm(y ~ x1+x2+x3+x4, data=datax) gx_AICc <- stepAIC(g0, criteria="AICc") gx_AIC <- stepAIC(g0, criteria="AIC") gx_AIC <- stepAIC(g0, criteria="BIC")

Bivariate plot of a bivariate normal distribution

Image
An example: # Standard deviations and correlation sig_x <- 1 sig_y <- 2 rho_xy <- 0.7 # Covariance between X and Y sig_xy <- rho_xy * sig_x *sig_y # Covariance matrix Sigma_xy <- matrix(c(sig_x ^ 2, sig_xy, sig_xy, sig_y ^ 2), nrow = 2, ncol = 2) # Load the mvtnorm package library("mvtnorm") # Means mu_x <- 0 mu_y <- 0 # Simulate 1000 observations set.seed(12345)  # for reproducibility xy_vals <- rmvnorm(1000, mean = c(mu_x, mu_y), sigma = Sigma_xy) # Have a look at the first observations head(xy_vals) # Create scatterplot # plot(xy_vals[, 1], xy_vals[, 2], pch = 16, cex = 2, col = "blue", #      main = "Bivariate normal: rho = 0.0", xlab = "x", ylab = "y") library(graphics) x <- xy_vals[, 1] y <- xy_vals[, 2] par(mar=c(4, 4, 2, 6)+0.4) smoothScatter(x, y, asp=1,               main = paste("Bivariate normal: rho = ", rho_xy),               xlab = "x&quo