[R] Fitting a System of Difference Equations

Mark Orr mo2259 at columbia.edu
Tue Jun 17 06:46:35 CEST 2008


Hi R friends,

I’m interested in fitting data to the following system of difference 
equations:

Change in M = k*(1-M.prev)*(1-F.prev) + R*(1-M.prev)*F.pref
Change in F = k*(1-F.prev)*(1-M.prev) + S*(1-F.prev)*M.pref

Parameters:
k, R, S, are transition rates

Variables:

M = Proportion of Males Sexually Active
F = Proportion of Females Sexually Active

M.prev and F.prev are the t-1 values of M and F.

The modeling of this in R is straightforward. However, I’d like to fit 
the simulation to actual prevalence data such that I’m iteratively 
honing in on the three parameters, given my starting prevalence values, 
via some loss function. I’m thinking of using <nls> for this but in some 
way replacing the right side of the formula specification with a 
function that calls the system of equations. But, I’m not sure this will 
work and I don’t know how to do this (I’ve done a thorough search on R 
and Google, without luck).

Any help or direction would be much appreciated.

Thanks.

Mark




More information about the R-help mailing list