Articles

Partial coefficient of correlation

Let have 3 variables, x, y and a: x <- rnorm(100, mean=10, sd=2) y <- x+rnorm(100, mean=20, sd=5) a <- rnorm(100, mean=10, sd=2) df <- data.frame(x=x, y=y, a=a) The partial coefficient correlation between x and y relative to a is the correlation coefficient of the residuals of the linear regression of x and y over a: pcor <- function(df) {   ax <- lm(x ~ a, data=df)   ay <- lm(y ~ a, data=df)      rx <- residuals(ax)   ry <- residuals(ay)      return(cor(rx, ry)) } pcor(df) Let confirm with the package ppcor: library("ppcor") ppcor::: pcor(df)$estimate[2, 1] Note that I use ppcor:::pcor() to be sure that the version of pcor in the package is used. It works: we obtained the same result. It should be noted that ppcor:::pcor() is more rapid than my version of pcor() even if it estimate 3 partial correlations and me only one ! > system.time( +   for...

Memory error when using java in R

Try: options(java.parameters = "-Xmx1000m") or options(java.parameters = "-Xmx2048m") You should make sure that you are setting the Java parameters before any JVM is initialized, i.e. before java-dependent packages are loaded.

Change login user in Rstudio-server

The logout button gives an error if the current user has checked "stay log in" button. To change a user, just use this link: http://[IP]:[port]/auth-sign-in

Where are located the packages and who is the owner

I have done a function list.packages() in my package HelpersMG. .libPaths() returns the list of locations for packages... but who is where ?: structure(lapply(.libPaths(), FUN = function(path) {list.dirs(path=path, full.names = FALSE, recursive = FALSE)}), .Names=.libPaths()) To get the owner for each location: structure(as.list(system(paste("ls -ld ", .libPaths()," | awk '{print $3}'", collapse=";"), intern=TRUE)), .Names=.libPaths()) It works both in ubuntu and MacOSx. I don't have Windows computer to do the same. The path used by .libPaths() are defined in one of the files used for R configuration at startup: in ubuntu: /usr/lib/R/etc/Renviron in MacosX: /Library/Frameworks/R.framework/Resources/etc/Renviron > file.path(Sys.getenv("R_HOME"), "etc", "Renviron") [1] "/Library/Frameworks/R.framework/Resources/etc/Renviron" and  ~/.Renviron ~/.Rprofile The files /usr/lib/R/etc/R...

Run a R script from terminal

Let a.R being:  sayHello <- function(){    print('hello') } sayHello() In terminal, enter: Rscript a.R [1] "hello" Or: R CMD BATCH a.R Nothing is shown because the stdout() is store in a file: cat a.Rout to see the result. It is not very friendly: MacBook-Air-de-Marc:Documents marcgirondot$ cat a.Rout R version 3.4.2 beta (2017-09-19 r73321) -- "Short Summer" Copyright (C) 2017 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin15.6.0 (64-bit) R est un logiciel libre livré sans AUCUNE GARANTIE. Vous pouvez le redistribuer sous certaines conditions. Tapez 'license()' ou 'licence()' pour plus de détails. R est un projet collaboratif avec de nombreux contributeurs. Tapez 'contributors()' pour plus d'information et 'citation()' pour la façon de le citer dans les publications. Tapez 'demo()' pour des démonstrations, 'help(...

Install rJava on archlinux

First, be sure that your date system is correct. timedatectl If not setup a ntp server: sudo timedatectl set-ntp true sudo pacman -S ntp sudo vi /etc/ntp.conf Replace the server with your stp server: server ntp.u-psud.fr iburst Force the date/time update and start the daemon sudo ntpd -gq sudo ntpd start Check if everything is ok timedatectl Update the system sudo pacman -Syu sudo pacman -S jdk8-openjdk sudo R CMD javareconf R In R, do install.packages("rJava") install.packages("mailR")

rJava in ubuntu

To install rJava in ubuntu, run: sudo apt - get install r - cran - rjava Alternative to get the most recent update: sudo apt-get install openjdk-8-jdk sudo R CMD javareconf sudo R install.packages("rJava")