vendredi 30 juin 2017

How to randomise a matrix element for each iteration of a loop?

I'm working with the popbio package on a population model. It looks something like this:

library(popbio)

babies <- 0.3 
kids <- 0.5 
teens <- 0.75
adults <- 0.98

A <- c(0,0,0,0,teens*0.5,adults*0.8,
         babies,0,0,0,0,0,
         0,kids,0,0,0,0,
         0,0,kids,0,0,0,
         0,0,0,teens,0,0,
         0,0,0,0,teens,adults
)
A <- matrix ((A), ncol=6, byrow = TRUE)

N<-c(10,10,10,10,10,10)
N<-matrix (N, ncol=1)

model <- pop.projection(A,N,iterations=10)
model

I'd like to know how I can randomise the input so that at each iteration, which represents years this case, I'd get a different input for the matrix elements. So, for instance, my model runs for 10 years, and I'd like to have the baby survival rate change for each year. babies <- rnorm(1,0.3,0.1)doesn't do it because that still leaves me with a single value, just randomly selected.

Hope you can help.




Aucun commentaire:

Enregistrer un commentaire