Articles

Affichage des articles du octobre, 2021

phantom text in graphics

Image
  The title function allows you to change the color of the text using the col argument, but that color is applied to the entire text string -- there's no obvious way to set the color of individual words. Or is there?  Barry Rowlingson offers an  elegant solution  that uses the "overhead transparency" principle of R graphics: you can overlay additional graphical elements one atop another, to build up your graph layer by layer.  So you could add the title  Hair color  in red on the left, and  Eye color  in blue on the right, and put a black "and" in the middle.  The trick is in the positioning -- it could take a lot of trial and error to get the  x  position of each element correct.  But if you plot the same text three times in three different colors, but leave some words blank (so they won't overlay previously plotted elements) you don't have to worry about positioning at all.  The  phantom  notation allows you to do that, as shown in Barry's solution

Force system messages to be in English

 > warning("Essai") Message d'avis : Essai  > Sys.setenv(LANG = "en") > warning("Essai") Warning message: Essai 

Distribution when only quantiles are known

Imagine that you have a credible interval (0.01, 0.3) for (0.025, 0.975) probabilities for one proportion value and you would like to use this variable. The solution is to search for the beta distribution that gives this credible interval: library("HelpersMG") best <- fitdistrquantiles(quantiles = c(0.01, 0.3), probs=c(0.025, 0.975), scaled=FALSE, distribution = "beta") Then it is possible to try the result: rd10000 <- rbeta(10000, shape1 = best["shape1"], shape2 = best["shape2"]) quantile(rd10000, probs=c(0.025, 0.975)) It works ! This function can fit also more than 2 quantiles and can be used for gamma and normal distributions. Now let do a simple exercise Let p and q two independent proportions being known only from their confidence interval and median: p <- c("2.5%"=0.012, "50%"=0.14, "97.5%"=0.25) q <-  c("2.5%"=0.37, "50%"=0.52, "97.5%"=0.75) I want the confidence inte