我一直在使用deSolve函数来解决ODE,我有一个参数,' e,它在整个代码中发生变化,也用于确定其他一些代码。我刚刚添加了另一个参数r,它在整个代码中执行了类似的操作,并收到了此警告消息:
DLSODA- Warning..Internal T (=R1) and H (=R2) are
such that in the machine, T + H = T on the next step
(H = step size). Solver will continue anyway.
In above message, R1 = 0, R2 = 0
DINTDY- T (=R1) illegal
In above message, R1 = 1
T not in interval TCUR - HU (= R1) to TCUR (=R2)
In above message, R1 = 0, R2 = 0
DINTDY- T (=R1) illegal
In above message, R1 = 2
T not in interval TCUR - HU (= R1) to TCUR (=R2)
In above message, R1 = 0, R2 = 0
DLSODA- Trouble in DINTDY. ITASK = I1, TOUT = R1
In above message, I1 = 1
In above message, R1 = 2
我的原始代码是:
parameters <- c(a = 0.32,
b = (9/140),
c = (5/1400),
d = (95/700),
k = 1/140,
i = 0.25,
r = 0.2,
n = 6000000,
x = 0.3 ,
t = 1/180, # important in looking at the shape
u = 1/180, # important in looking at the shape
p = 10,
s = 100,
g = 100,
# e = .3,
h = 1000)
# where a is contact with infected patient
# where b is safely burried percentage
# where c is chance of being cured with no medical help
# where d is the chance that patients will go from infected to dead with no safe burial
# where e is the education percentage (percentage of patients that go into quarentine)
# where k is the chance of being cured with medical help
# where i is the infection rate (assuming contact with dead and alive ebola people are the same)
# where n is the population
# where r is the riual burial rate (unsafe contact of the dead patients with alive non infected people)
# where x is the percentage of money spent on hospitals
# where t is how fast the education is implemented
# where m is how fast hospitals go from money to actual hospitals
# where is the price placed on one life (the constant that is multiplied by the burrials)
state <- c(S = 5999900,
E = 0,
I = 100,
Q = 1,
D = 0,
B = 0,
C = 0,
Y = 0,
#H = 0,
R = 1,
#h = 100,
e = 0
)
# where S is suseptable
# where E is effected
# where I is infected
# where Q is quarentined
# where B is burried
# where C is cured
# where D is dead but not burried
# where Y is income
# where is education that we have funding for
# where is hospitals that we have funding for
# where is education deployed
# where is hospitals deployed
# set up the equations
equation <- (function(t, state, parameters)
with(as.list(c(state, parameters)),{
# rate of change
dS <- (-(a*S*I)/n) - ((r*S*D)/n)
dE <- (a*S*I)/n + ((r*S*D)/n) - i*E
#if (h >= Q)
# e = e
#else if (h < Q )
# e = 0
dI <- i*E - (e)*I - c*I - d*I
#(if (h >= Q)
# e = 1
#else if (h < Q )
# e = 0
dQ <- (e)*I - b*Q - k*Q
dD <- d*I - r*D
dB <- b*Q + r*D
dC <- c*I + k*Q
dY <- p * (b*Q + r*D)
dR <- (1-x)* (p*(b*Q + r*D)) -t*(R)
de <- t*(s/R)
#dH <- (x)* (p*(b*Q + r*D)) -u*(H)
#dh <- u*(H/g)
# return the rate of change
list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dR, de))
}))
# , dH, dh
# solve the equations for certain starting parameters
library(deSolve)
times <- seq(0, 1000, by = 1)
out <- ode(y = state, times = times, func = equation, parms = parameters)
head(out)
tail(out)
# graph the results (need to know how to add D to the graph)
par(oma = c(0, 0, 3, 0))
plot(out, xlab = "Time", ylab = "People")
#plot(out[, "X"], out[, "Z"], pch = ".")
mtext(outer = TRUE, side = 3, "Ebola Model", cex = 1.5)
并且已更改为:
parameters <- c(a = 0.32,
b = (9/140),
c = (5/1400),
d = (95/700),
k = 1/140,
i = 0.25,
# r = 0.2,
n = 6000000,
x = 0.3 ,
t = 1/180, # important in looking at the shape
u = 1/180, # important in looking at the shape
v = 1, # important in looking at the shape
p = 10,
s = 100,
g = 100,
# e = .3,
h = 1000)
# where a is contact with infected patient
# where b is safely burried percentage
# where c is chance of being cured with no medical help
# where d is the chance that patients will go from infected to dead with no safe burial
# where e is the education percentage (percentage of patients that go into quarentine)
# where k is the chance of being cured with medical help
# where i is the infection rate (assuming contact with dead and alive ebola people are the same)
# where n is the population
# where r is the riual burial rate (unsafe contact of the dead patients with alive non infected people)
# where x is the percentage of money spent on hospitals
# where t is how fast the education is implemented
# where m is how fast hospitals go from money to actual hospitals
# where is the price placed on one life (the constant that is multiplied by the burrials)
state <- c(S = 5999900,
E = 0,
I = 100,
Q = 1,
D = 0,
B = 0,
C = 0,
Y = 0,
#H = 0,
R = 1,
J =0,
#h = 100,
e = 0.3,
r = 0.3
)
# where S is suseptable
# where E is effected
# where I is infected
# where Q is quarentined
# where B is burried
# where C is cured
# where D is dead but not burried
# where Y is income
# where is education that we have funding for
# where is hospitals that we have funding for
# where is education deployed
# where is hospitals deployed
# set up the equations
equation <- (function(t, state, parameters)
with(as.list(c(state, parameters)),{
# rate of change
dS <- (-(a*S*I)/n) - ((r*S*D)/n)
dE <- (a*S*I)/n + ((r*S*D)/n) - i*E
#if (h >= Q)
# e = e
#else if (h < Q )
# e = 0
dI <- i*E - (e)*I - c*I - d*I
#(if (h >= Q)
# e = 1
#else if (h < Q )
# e = 0
dQ <- (e)*I - b*Q - k*Q
dD <- d*I - r*D
dB <- b*Q + r*D
dC <- c*I + k*Q
dY <- p * (b*Q + r*D)
dR <- (1-x)* (p*(b*Q + r*D)) -t*(R)
de <- t*(s/R)
dJ <- (x)* (p*(b*Q + r*D)) -v*(J)
dr <- v*(s/J)
#dH <- (x)* (p*(b*Q + r*D)) -u*(H)
#dh <- u*(H/g)
# return the rate of change
list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dR, de, dJ, dr))
}))
# , dH, dh
# solve the equations for certain starting parameters
library(deSolve)
times <- seq(0, 100, by = 1)
out <- ode(y = state, times = times, func = equation, parms = parameters)
head(out)
tail(out)
# graph the results (need to know how to add D to the graph)
par(oma = c(0, 0, 3, 0))
plot(out, xlab = "Time", ylab = "People")
#plot(out[, "X"], out[, "Z"], pch = ".")
mtext(outer = TRUE, side = 3, "Ebola Model", cex = 1.5)
任何帮助都会很棒!