Legendcsimulationtheoreticalselfing ltyc121colgrayc0005

The vector "initial" gives the starting state; it was denoted by above. The vector "het.count", denoted above by v, is used in order to compute the probability of heterozygosity from the distribution of transient states. The vector "hetero.prob" stores the computed probabilities. Initially this vector is assigned a null value. This creates an object that can be identified and manipulated by R, but contains no information. Information is accumulated in each iteration of the "for" loop. Note that the final length of "hetero.prob" need not be preassigned. The system automatically expands the object upon request. Finally, observe that the binary operation "%*%" corresponds to matrix multiplication, unlike the operation "*", which is applied term-by-term. (Try both "Q * Q" and "Q Q" to see the difference between the two operations.)

The results of the theoretical computation are added to the plot in Fig 3.2 with the aid of the function "lines". Note the good agreement between the simulation and the theoretical computation. For clarity, a legend is added with the low-level plotting function "legend". The first two arguments of the function are used in order to determine the location of the upper-left corner of the legend box in Fig 3.2; and the other arguments set the text, the type, and the color of the lines to appear inside the box. The line type must be provided. In the current case the first and the third lines are of the same type: "lty = 1", which corresponds to a solid line. The second line is of type 2, which correspond to a broken line. Observe that since there are three lines in the legend, the argument should be a vector of length three. If all lines were of the same type, then one could create a vector with repeated components by using the function "rep". The first argument to that function is the object to be repeated. If the second argument is an integer, then the output is a vector which is formed by repeating the object the given number of times. The function "rep" is very handy in order to create sequences, in particular when it is used in combination with the function "seq".

0 0

Post a comment