Articles

Affichage des articles du septembre, 2019

Gamma distribution parameters from mean and variance of data distribution

set.seed(31234) x <- rgamma(100, shape=2.0, rate=11.0) hist(x) #print(x) shape <- 2.0 rate <- 11.0 scale <- 1/rate m <- mean(x) print(shape * scale) print(shape * 1 / rate) v <- var(x) print(shape * scale^2) print(shape * (1 / rate) ^2) print(m) print(v) scale <- v/m shape <- m*m/v rate <- 1/scale print(shape) print(rate) library(fitdistrplus) fitdist(data=x, distr="gamma", method = "mle") fitdist(data=x, distr="gamma", method = "mme") Note that the gamma distribution cannot be fitted when standard deviation (and then variance) is null: scale <- v/m # is 0 shape <- m*m/v # is +Inf rate <- 1/scale # is +Inf And > x <- rep(100, 1000) > library(fitdistrplus) > fitdist(data=x, distr="gamma", method = "mle") <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data,     gr = gradient, ddistnam = ddistname, hessian = TRUE

Bug in R 3.6.1: When file.copy deletes your file !

A <- 10 save(A, file="A.Rdata") file.symlink(from="A.Rdata", to="B.Rdata") rm(A) load(file="B.Rdata") print(A) system("ls -l") file.copy(from="A.Rdata", to="B.Rdata", overwrite = TRUE) # A.Rdata becomes empty: 0B system("ls -l") # In terminal marcgirondot$ ls A.Rdata marcgirondot$ ln -s A.Rdata B.Rdata marcgirondot$ ls -l -rw-r--r--  1 marcgirondot  staff      70 13 sep 11:38 A.Rdata lrwxr-xr-x  1 marcgirondot  staff       7 13 sep 11:38 B.Rdata -> A.Rdata marcgirondot$ cp A.Rdata B.Rdata cp: B.Rdata and A.Rdata are identical (not copied).

Error in foreign and nlme packages installation

I just get some errors in the update of foreign and nlme packages (R 3.6.1): In both cases, I had this error: dyld: Library not loaded: /opt/local/lib/libcrypto.1.0.0.dylib   Referenced from: /opt/local/lib/libxar.1.dylib   Reason: image not found fatal error: otool: fatal error in /opt/local/bin/llvm-objdump-mp-7.0 dyld: Library not loaded: /opt/local/lib/libcrypto.1.0.0.dylib   Referenced from: /opt/local/lib/libxar.1.dylib   Reason: image not found fatal error: otool: fatal error in /opt/local/bin/llvm-objdump-mp-7.0 dyld: Library not loaded: /opt/local/lib/libcrypto.1.0.0.dylib   Referenced from: /opt/local/lib/libxar.1.dylib   Reason: image not found fatal error: otool: fatal error in /opt/local/bin/llvm-objdump-mp-7.0 dyld: Library not loaded: /opt/local/lib/libcrypto.1.0.0.dylib   Referenced from: /opt/local/lib/libxar.1.dylib   Reason: image not found fatal error: otool: fatal error in /opt/local/bin/llvm-objdump-mp-7.0 dyld: Library not loaded: /opt/local/li

Install R and Rstudio in Lubuntu 18.04

Installing R and Rstudio was not so easy in a fresh Lubuntu 18.04 install. Here is the solution : First open the terminal and enter: sudo apt update sudo apt upgrade Edit the file    /etc/apt/sources.list and add: deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Enter these commands also in terminal: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 sudo apt update sudo apt upgrade sudo apt install r-base r-base-dev Load this file: https://download1.rstudio.org/desktop/bionic/amd64/rstudio-1.2.1335-amd64.deb (or any newer) And install it In terminal, enter: sudo apt install at-spi2-core sudo apt install build-essential sudo apt install qtcreator sudo apt install qt5-default Restart using: sudo reboot And run Rstudio with: export QT_XCB_FORCE_SOFTWARE_OPENGL=1 export QT_STYLE_OVERRIDE="" /usr/lib/rstudio/bin/rstudio it forces to not use the  xserver-xorg-v