Trying to create a deterministic mathematical model that models birth cohorts (i.e. people born in the same year are modelled individually). Expecting ageing to be exponential. Very new to R. I have adapted from published example but do not know if it is doing what I want it to.
function(times, state, parameters) {
a= c(1/diff(x), 0)
n=length(parameters$a)
x=exp(x)
I=state[1:n]
T=state[2n+1]:[3n]
with(as.list(c(state,parameters)),{
dI <-c(phi, rep(0,n-1)) - gammaI - muI - aI - LTFUI
dT <-gammaI + c(0, a[1:n]T[1:n-1]) - muT - aT - LTFU*T
return(list(c(dI, dT)))
})
}
I would like to know if the example of code above correctly accounts for moving from one-year age group to the next at each one year time step? Any assistance or resources would be greatly appreciated. - Struggling student new to R
The specific question can't be answered in the abstract--without representative data and an algebraic notion of the model to be applied.
In general, it helps to think of R as school algebra writ large, f(x) = y, involving three objects -- the function f itself, the argument(s) x and the result(s), y. A problem in R` programming comes down to designing x and y and then finding or writing one or more functions f to make the transformation.
This is facilitated by tidy data in which each observation is a row and each column is an observation. In your case, each row could be an individual or an age cohort and one or more other variables from which the model f is calculated. The data object then yields a table of results for each individual that must be summarized somehow to be stratified by cohort.