[R] Using optim function for logistic model simulation

Charlotte Chang c.h.w.chang at gmail.com
Mon Apr 26 08:00:36 CEST 2010


Hello!

I'm a college undergrad desperately trying to finish up my thesis. I
have a dataset on the distribution of a grassland bird from the
Breeding Bird Survey. I have a very straightforward and simple version
of the logistic growth model to describe changes in this bird's
abundance over time. The variables are the natural birth rate,
mortality, and carrying capacity. The equation itself looks like this:
birds <- c*birds + b*birds*(1-birds/K) where c = mortality, b = birth
rate, and K = carrying capacity.

I'm trying to find the optimal value of K and I've been using the
optim function. The problem is that it doesn't really work. My code is
below:

b<-1.22
c<-0.55
bird<-bird.density[0]
eqn1<- function(K1, bird) {
	for (i in 1:8) {
		b<-1.22
		c<-0.55
		bird <- 0.55*bird + b*bird*1-b*bird*bird/K
	}
}

k1<-optim(c(0,10),eqn)

I realize this is a painfully amateurish question, but I really
appreciate any help! The other tricky part about this is that it looks
like there are 3 distinct time periods where the bird is increasing,
declining, and increasing again. I'm thinking that there are 3
different carrying capacity values, but my understanding of optim is
that it can only optimize one parameter variable at a time. So I was
going to take the brute force approach of artificially breaking up the
equation into 3 parts (i.e. make eqn1, eqn2, and eqn3, and optimize
each separately, with the input values for the later two functions
coming from the last number of birds from the previous loop).

Thank you all very much!

charlotte



More information about the R-help mailing list