Publications by Bogumił Kamiński
Solving mastermind with R
In my last post I have shown a solution to classical sorting problem in R. So I thought that this time it would be nice to generate a strategy for playing Mastermind using R.It was shown by D.E. Knuth that Mastermind code can be broken in at most five guesses. The algorithm is to always choose guess that minimizes the maximum numb...
3955 sym
Emulating dynamic scoping in GNU R
By design GNU R uses lexical scoping. Fortunately it allows for at least two ways to simulate dynamic scoping.Let us start with the example code and next analyze it:x “global”f1 function() cat(“f1:”, x, “\n”)f2 function() cat(“f2:”, evalq(x, parent.frame()), “\n”)fun function() { x “f1” f1() �...
2092 sym
Changing function scope in GNU R example
In my last post I have discussed how to work around GNU R scoping rules using environment function. This time let us look at a practical example using recode function from car package.First let us look at how recode works:library(car)x rep(1:3, 2)recode(x, “1=’a'”)transforms 1 23 12 3 into “a” “2” “3” �...
2623 sym
Animation basics for a vacation
Since I have a vacation this time I decided to implement some entertaining graphics. I have chosen to animate a Cassini oval.The task is can be accomplished using polar equation:The implementation of the animation is given by the following code:library(animation)xy function(angle, a, b) { ca cos(2 * angle) r2 a ^ 2 * ca + sqrt(...
1354 sym 4 img
An example of OOP in GNU R using S4 Classes
Recently I have discussed with my friend from WLOG Solutions an implementation of banking cash management engine in GNU R. The code made a nice use of S4 classes so I thought it would be worth showing as an example.The problemEvery commercial bank needs to provide its customers with access to cash via hundreds of cash access points li...
6393 sym 2 img
Exporting ctree object to Asymptote
When producing regression or classification trees (standard rpart or ctree from party package) in GNU R I am often unsatisfied with the default plots they produce. One of many possible solutions is to export a tree plot to Asymptote.The code I have prepared generates an Asymptote file based on generated ctree object. Here is the ...
4228 sym 4 img
Simulation metamodeling with GNU R
I am one of the organizers of ESSA2013 conference that will take place in September 2013 in Warsaw, Poland. The conference scope is social simulation and in particular methods of statistical analysis of simulation output (metamodeling). As we have just issued Call for Papers for the conference so I decided to post a simple example ...
4008 sym 4 img
Simulation metamodeling with constraints
Last week I have posted about using simulation metamodeling to verify results of analytical solution of the model. After posting it I realized that the solution presented there can be improved by using knowledge of simulation model structure.The story is about calculation of the variance of the random variable given by formula:q(p-...
3991 sym 2 img
Plotting Watts-Strogatz model
Recently I wanted to reproduce Figure 2 from Watts and Strogatz (1998). The task using igraph is simple but an interesting task was annotation of the resulting plot.Watts-Strogatz model generates graphs that have so called small-world network property. Such networks should have low average path length and high clustering coefficien...
2656 sym 2 img
Simple Bayesian bootstrap
Bootstrapping is a very popular statistical technique. However, its Bayesian analogue proposed by Rubin (1981) is not very common. I was looking for an example of its implementation in GNU R and could not find one so I decided to write a snippet presenting it.In standard bootstrapping observations are sampled with replacement. This im...
1724 sym