Archive of articles classified as' "programming"

Back home

Trellis graphs in functions

15/01/2004

I wrote a small script in Splus to test the effect of different sampling intensities for mammal browsing in plantations. The function included a call to levelplot, viagra a trellis function that represents three dimensional data using different colours for the z variable. You can see an example below:

Level plot of mammal browsing

The function would run with a normal ‘plot’ function, information pills but it would not produce any output if placed inside my function. However, urologist a call to levelplot in the command line would produce the desired results. Quick email to the Splus discussion group and in ten minutes I had the answer: “Trellis functions don’t actually plot anything, but return an object; printing that object actually creates the plot. Outside of a function the ‘printing’ happens automatically, but inside the function you have to do it explicitly” (from an email by Tim Hesterberg, Insightful Corp.). Thus, something like print(levelplot(…)) does the trick.

Filed in programming, statistics No Comments

Back into writing

13/10/2003

It has been a while, overweight months actually, since the last note. It hasn’t been lack of motivation, but actually many things going on at the same time. Starting on mid-July and going through August there were quite a few field trips across Tasmania, participating in the measurement calendar of trials for this year. Some days were cold, windy and rainy (even with some snow), while others were full of sunshine.

It was a time for programming too, switching from my old, trusty Python to Visual Basic 6 (we will later switch to VB.net). As a language, I think that Python is much better, but it is much more difficult to deploy than Visual Basic, especially if I needed a decent GUI. At the same time, I decided to learn VB.net, which seems to be a much more civilised language. I purchased a copy of Programming Microsoft Visual Basic .NET (Core Reference) (link to Amazon.com) that, with over 1,600 pages, does quite a good job at explaining the intricacies of VB.net. When reading the comments of users in Amazon, it appears to be a good choice for C# programmers too.

I have also been quite active running longitudinal analyses for designed experiments using Splus and GenStat.

P.S. 2008. At the end I did not need to get into VB.net.

Filed in miscellanea, programming, statistics No Comments

Note to self: random positions in circle

1/08/2003

Yesterday I spent the day near Orford, this site attending a demonstration of standing tree quality assessment (in a ~250 years old Eucalyptus delegatensis native forest). The idea was to visually estimate the log grading that would come from eight standing trees and compare the estimate with the results after felling the trees. It seems that a properly trained field crew can give a (very?) rough estimate of what is going to happen with individual trees, and a (plain?) rough idea for the average. Office boffins have a much smaller chance of getting things right.

It never stops to surprise me the degree of variability encountered when working with native forest and estimates about its productivity. We’ll need to discuss ways of taking into account that large ’surprise factor’ on terms of final product specification obtained from growth models.

Orford
Yesterday I wanted to generate a virtual forest with aggregated spatial distribution (clusters of trees) to test different sampling schemes. I started with the number of clusters defined by a Poisson distribution and then randomly assigning trees to each cluster with probability p and not clustering them with probability 1 – p. The position around the clusters was determined by a random allocation using polar coordinates; i.e., impotent
randomly generating an angle (between 0 and 2*PI) and a proportion of a maximum radius rand()*R. Adrian pointed out to me that the procedure was not uniformly random in the circle, with higher density near the centre than further away.

If you like analogies, tracing a large number of lines with a pencil at various angles, but always though the centre of a circle, leaves more gray near the centre of the circle than near the border of it. Same thing happens with the spokes of a wheel. To make a long story short, this can be corrected taking the square root of the uniform random number that is used to multiply by the radius. Then, the proportion of the maximum radius is sqrt(rand())*R. Note to self: always take the square root when randomly assigning points in a circle.

Filed in programming, statistics No Comments