# Multifractals in Ecology Using R - Day 4

## Percolation

• First we will generate a random forest: set each position of a matrix to 1 or 0 with some probability $$p$$

• First we need to fill a matrix with numbers
• what we really need are random numbers
• now we need to decide which will become 0 or 1 with some probability, the best way to do that is using a function
• the last line don’t works because we need to apply the condition to each site individually
• So we set a matrix of 1’s and 0’s with probability 0.5, we can plot it
• Now we can put all together and make a function that does all things
• We can see how the matrix is filled when we change $$p$$
• The next thing is to burn the trees, we forget to return the matrix with the random forest
• Now we need a function to explore the neighborhood and fire the actual site if one on the adjacent sites is fired. We can try to use a loop.
• But we have to do that for all the rows of the matrix
• something is wrong, we need to test all the neighborhood
• So now we are ready to build the function
• Now to finish we have to count the number of burned sites, a simple function will do, but first we test the commands
• next we create the function

## Exercise 1

• Make a plot of the proportion of burned sites versus the probability $$p$$ of the trees

## Infection

• We can do this in a similar way, first we need a matrix but now one dimension will be the time
• At time 1 we need to infect some sites to have a start
• Now we have to propagate the infection, there are two possibilities: contagion with probability $$\lambda$$ or recuperation with probability $$\mu$$
• Then we put all in a function
• We can try with different parameters and see what happens at $$\lambda > \mu$$ or $$\lambda < \mu$$

## Exercise 2

• Build the plot with a fixed $$\mu$$ of the probability of propagation versus $$\lambda$$

• Estimate the fractal dimension and the multifractal spectrum of the infection