Category Archives: statistical software

Enjoy R: Do two consecutive seeds behave independently?

I’ve always wondered whether two random seeds in R provide independent results, whatever they are. In particular, I wanted to check if repeating a sampling operation with two consecutive seeds, say set.seed(20) and set.seed(21), this would produce unrelated outputs as expected. Pseudo-randomness in R is based on algorithms I honestly have read nothing about, and …

Continue reading

Enjoy R: install packages “on the fly”

It is annoying when you load a package and you find out you don’t have it installed. So you need to install it first, and finally load it. As I am used to installing LaTeX packages on the fly, I thought of a simple script to do the same in R. The following is a …

Continue reading

Enjoy R: Looping in R

Loops are run in most applications and are supported by all languages. In general, there are more than one way to execute the same task via looping, and the efficiency of each choice varies among languages. This post is not intended to demonstrate any general truth about R loops, but aims to provide some insights into some …

Continue reading

Enjoy R: how to automatically give readable names to variables in a loop

For making the same operations on each element of a collection — e.g. vector, matrix, list —, we generally use loops. Sometimes, we want to save the results of each iteration in variables which are related only to the current iteration. To do that properly, we should give each variable a name that simoultaneously refers …

Continue reading

Enjoy R: is my x included in these bounds?

How many times have you written code like the following? if(x > lower_bound & x < upper_bound) return(T)  return(F) Throughout my coding experience so far, I’ve faced that a lot. And everytime this happened, I started thinking that I was not really writing it in the same way as I would have written it using basic …

Continue reading

Enjoy R: A useful function for clearing the workspace

Today I was coding with my supervisor, and we actually had a bunch of things saved in our workspace which we wanted to get rid of. The annoying matter was that we aimed to delete almost all the workspace and keep only a couple of functions. R has a fast way to clear all the workspace, which is rm(list …

Continue reading

Enjoy R: Simulations of the Monty Hall problem

The Monty Hall problem is a recurring and charming game in which the probability theory plays an essential role. A very simple and clear explanation may be found here: http://www.youtube.com/watch?v=7u6kFlWZOWg. Anyway, let’s just summarize how it goes. There are three shut doors: behind two of them there is a goat, whereas the remaining door hides …

Continue reading

Enjoy R

How the probability of type II error varies The type II error is what we may call a miss. When we test, our usual preference is to keep valid the null hypothesis, unless there is a strong evidence we should reject it, given the data we have. When H0 is not true at population level …

Continue reading

Enjoy R

A tool which is often left aside : the class person The class person is useful to keep information like name and email address about one person or a group of. Some problem arose to me when I tried to convert an object of this class to a well-specified data frame. So, I implemented a …

Continue reading

Enjoy R

A practical demonstration of linearity of MAD We know that if we have a variable named X, to which we apply a linear transformation like Y = a X + b we can demonstrate that the computation of indexes related to Y may be easily deduced from the indexes we have obtained for X. This …

Continue reading