library(deSolve)
library(tidyverse)
2 The Basic Model of Virus Dynamics
Set Up the ODE
<- function(time, state, parameters){
base_ode with(as.list(c(state, parameters)),{
<- lambda - d*x - beta * x * v
dx <- beta * x * v - a * y
dy <- k * y - u * v
dv
return(list(c(dx,dy,dv)))
})
}
<- seq(0,30,.1)
t
<- c(
params lambda =1e5,# Uninfected cell production rate
d = .1, # Cell Death Rate
a = .5, # Infected Cell Death Rate
beta = 2e-7, # "Rate Constant"
k = 100, # Virus productin from Infected cell
u = 5 # Free Virus lifestapn
)
Guessing Initial values from a graph
<- params["lambda"][1]/params["d"][1]
x0 <- c(x = unname(x0),
init y = 1, v = 1)
<- ode(init, t, base_ode, params)
out
<- as_tibble(as.data.frame(out)) out_df
Funny side note is that the differences in the scales are almost immediately reproduced as in the book.
<- c("Uninfected Cells",
compartment_names "Infected Cells",
"Free Virus")
<- out_df %>%
p setNames(c("time", compartment_names)) %>%
gather(compartment, value, -time) %>%
mutate(compartment = factor(compartment, compartment_names)) %>%
ggplot(aes(time, y = value))+
geom_line()+
facet_grid(rows = vars(compartment),scales = "free_y")+
theme_classic()+
labs(
title = "Viral Dynamics of Primary Phase of HIV or SIV Infection",
x = "Days",
y = "Count"
+
)scale_y_continuous(labels = scales::comma_format(accuracy = 1000))
p