Category Archives: Code

Finger Exercise: Throwing two Dice in R using the rpanel Package

After a period of examinations I needed to fresh up some R-vocabulary (the exact syntax) because I started to mix it up with other programming languages’ syntax. And here is my result: A dice game simulation. Not very innovative, not very difficult, but I suppose it could be quite useful for people being new to R as an easy example of how programming in R may work. Furthermore, it is an application of the nice rpanel package.

Dice Game with the rpanel package

For this program being very simple I skipped most comments on the code – but will add some more in the near future. The variables should be quite self-explaining. If not, feel free to write a comment. Of course more experienced programmers are welcomed to improve the code. 🙂

Usage: Run the code in R, use the sliders of the panel to choose the number of dice to throw, the number of throws and hit the Throw! button.

This small program enables you to investigate or illustrate, respectively, some aspects of convergence or simply to get a feeling for your chances to win your next dice game. Feel free to use the program for didactical purposes if you find it useful (see the license in the footer of this page). If you want to have reproducable results set a random number seed of your choice by using the set.seed() function implemented in R.

Happy R-ing.

Continue reading


How to generate bivariate pdfs given a copula and the margins in R and MATLAB

After finding a few unanswered requests for a solution of this problem in the web (including my own…) I’d like to share the final results of my work.

The problem:

Suppose you have two random variables, Z and T.

Z is N(0,1) distributed.
T is t(3) distributed.

Now you are supposed to produce four contour plots of the random variables’ joint pdf for the cases that the variables’ dependence structure is given by the

  1. Gaussian,
  2. Clayton,
  3. Frank- and
  4. Gumbel copula.

With the copula and the marginal distributions given the (bivariate) joint distribution of Z and T can be constructed. And this post is about doing exactly this in R and MatLab (and drawing the corresponding contour-plots).

Continue reading