[R] DeSolver giving "NA" as output, but running fully.

2015-04-27 Thread walke554
Hello All,

I am currently looking on a transmission model for STD transmission within a
population.  I am able to run my full code and the ODE function, but when I
look at my output, all I get is "NA" for each time step beyond the first. 
There doesn't seem to be any syntax error, and I do get my entire program to
run.  Here is my code:

setwd("C:/Users/L/Documents/MastersThesis")

require(deSolve);


#Model 1


#The function
HPVInfection<-function(t,y,p){
XFL = y[1]; #number of susceptible unvaccinated females low risk
XFM = y[2]; #number of susceptible unvaccinated females medium risk
XFH = y[3]; #number of susceptible unvaccinated females high risk
XML = y[4]; #number of susceptible unvaccinated males low risk
XMM = y[5]; #number of susceptible unvaccinated males medium risk
XMH = y[6]; #number of susceptible unvaccinated males high risk
Y1FL = y[7]; #number of infected unvaccinated females low risk infected
with vaccine strain
Y1FM = y[8]; #number of infected unvaccinated females medium risk low 
risk
infected with vaccine strain
Y1FH = y[9]; #number of infected unvaccinated females high risk low risk
infected with vaccine strain
Y1ML = y[10]; #number of infected unvaccinated males low risk low risk
infected with vaccine strain
Y1MM = y[11]; #number of infected unvaccinated males medium risk low 
risk
infected with vaccine strain
Y1MH = y[12]; #number of infected unvaccinated males high risk low risk
infected with vaccine strain
Y2FL = y[13]; #number of infected unvaccinated females low risk infected
with non-vaccine strain
Y2FM = y[14]; #number of infected unvaccinated females medium risk low 
risk
infected with non-vaccine strain
Y2FH = y[15]; #number of infected unvaccinated females high risk low 
risk
infected with non-vaccine strain
Y2ML = y[16]; #number of infected unvaccinated males low risk low risk
infected with non-vaccine strain
Y2MM = y[17]; #number of infected unvaccinated males medium risk low 
risk
infected with non-vaccine strain
Y2MH = y[18]; #number of infected unvaccinated males high risk low risk
infected with non-vaccine strain
ZFL = y[19]; #number of immune females low risk
ZFM = y[20]; #number of immune females medium risk
ZFH = y[21]; #number of immune females high risk
ZML = y[22]; #number of immune males low risk
ZMM = y[23]; #number of immune males medium risk
ZMH = y[24]; #number of immune males high risk
VFL = y[25]; #number of susceptible vaccinated females low risk
VFM = y[26]; #number of susceptible vaccinated females medium risk
VFH = y[27]; #number of susceptible vaccinated females high risk
VML = y[28]; #number of susceptible vaccinated males low risk
VMM = y[29]; #number of susceptible vaccinated males medium risk
VMH = y[30]; #number of susceptible vaccinated males high risk
W1FL = y[31]; #number of infected vaccinated females low risk infected 
with
vaccine strain
W1FM = y[32]; #number of infected vaccinated females medium risk 
infected
with vaccine strain
W1FH = y[33]; #number of infected vaccinated females high risk infected
with vaccine strain
W1ML = y[34]; #number of infected vaccinated males low risk infected 
with
vaccine strain
W1MM = y[35]; #number of infected vaccinated males medium risk infected
with vaccine strain
W1MH = y[36]; #number of infected vaccinated males high risk infected 
with
vaccine strain
W2FL = y[37]; #number of infected vaccinated females low risk infected 
with
non-vaccine strain
W2FM = y[39]; #number of infected vaccinated females medium risk 
infected
with non-vaccine strain
W2FH = y[40]; #number of infected vaccinated females high risk infected
with non-vaccine strain
W2ML = y[41]; #number of infected vaccinated males low risk infected 
with
non-vaccine strain
W2MM = y[42]; #number of infected vaccinated males medium risk infected
with non-vaccine strain
W2MH = y[43]; #number of infected vaccinated males high risk infected 
with
non-vaccine strain
with(as.list(p), {
dXFL.dt = (0.5 * mew * omega[1,1] * (1-phi) * total) - 
((partner[1,1] *
beta[1,1] * Y1ML + Y2ML + (tau[1,1] * W1ML) + (tau[1,2] * W2ML)) /
population[1,2]) * rho[1,1]) + (((Y1MM + Y2MM + (tau[1,1]*W1MM) + (tau[1,2]
* W2MM))/population[2,2]) * rho[1,2]) + (((Y1MH + Y2MH + (tau[1,2] * W1MH) +
(tau[1,2] * W2MH)) / population[3,2]) * rho[1,3])) + mew) * XFL) + (sigma *
VFL);
dXFM.dt = (0.5 * mew * omega[2,1] * (1-phi) * total) - 
((partner[2,1] *
beta[1,1] * Y1ML + Y2ML + (tau[1,1] * W1ML) + (tau[1,2] * W2ML)) /
population[1,2]) * rho[2,1]) + (((Y1MM + Y2MM + (tau[1,1]*W1MM) + (tau[1,2]
* W2MM))/population[2,2]) * rho[2,2]) + (((Y1MH + Y2MH + (tau[1,1] * W1MH) +
(tau[1,2] * W2MH))

Re: [R] DeSolver giving "NA" as output, but running fully.

2015-04-29 Thread walke554
All of the data you need to run the ODE integrator is there.  all the
parameters and starting populations and values are given under the:

"#giving the parameters"

section of the code.



--
View this message in context: 
http://r.789695.n4.nabble.com/DeSolver-giving-NA-as-output-but-running-fully-tp4706497p4706620.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] deSolve ODE Output Question

2015-05-20 Thread walke554
Hello,

I am working on a simple ODE problem with the deSolve package, and I was
hoping that someone could answer a question about how the deSolve package
does integration.  

Here is my program:

#The function
STDMod<-function(t,y,p){
IH = y[1];
IL = y[2];
with(as.list(p), {
dIH.dt = Beta[1,1]*(nH-IH)*IH + Beta[1,2]*(nH-IH)*IL - gamma*IH;
dIL.dt = Beta[2,1]*(nL-IL)*IH + Beta[2,2]*(nL-IL)*IL - gamma*IL;
return(list(c(dIH.dt,dIL.dt)));
})
}

#giving the parameters

Beta = matrix(data=c(10, 0.1, 0.1, 1.0), ncol=2, nrow=2)
nH = 0.2
nL = 0.8
IH0 = 1e-5
IL0 = 0

gamma = 1

p = list(Beta=Beta, gamma=gamma, nH=nH, nL=nL)

y0 = c(IH0, IL0)

#Running the ode integrator

steps= 10;
t = seq(from=0, to=30, by=.01);
out = ode(y=y0, times=t, func=STDMod, parms=p);

My understanding is that the 'out' matrix would be the values of the STDmod
function at each time step, given the initial values of the state parameters
IH and IL.  However, for the very first time step, I am getting a value
different than what the derivative and the initial values add up to.

My output:
 

but 'IH0' + 'the value of dIH.dt = Beta[1,1]*(nH-IH)*IH +
Beta[1,2]*(nH-IH)*IL - gamma*IH for timestep one' = 1.999e-5.  Is there
something that I am missing?  I am hoping to use this for more complicated
derivatives, but I want to make sure I am using the package correctly first.

Thanks!



--
View this message in context: 
http://r.789695.n4.nabble.com/deSolve-ODE-Output-Question-tp4707448.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.