Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit cc903be May 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R add quote May 14, 2019
inst add quote May 14, 2019
man
.Rbuildignore
.gitignore first commit May 5, 2019
DESCRIPTION update Imports May 14, 2019
Kung.Rproj
LICENSE Initial commit May 5, 2019
NAMESPACE
README.md Update README.md May 13, 2019

README.md

Kung

turn your compartmental model to a Shiny app

Installation

devtools::install_github("slphyx/Kung")

Usage

library(deSolve)

init <- c(S = 1-1e-6, I = 1e-6, R= 0.0)
times <- seq(0, 70, by = 1)

sir <-function(time, state, parameters) {
  with(as.list(c(state, parameters)), {
    dS <- -beta*S*I
    dI <- beta*S*I - gamma*I
    dR <- gamma*I
    
    return(list(c(dS, dI, dR)))
  })
}

parameters <- c(
  gamma = 0.14286, 
  beta = 0.6
)

out <- as.data.frame(ode(y = init, times = times, func = sir, parms = parameters))

matplot(times, out[,c("S","I","R")], type = "l", xlab = "Time", ylab = "Susceptibles and Recovereds", main = "SIR Model", lwd = 1, lty = 1, bty = "l", col = 2:4)
legend(40, 0.7, c("Susceptibles", "Infecteds", "Recovereds"), pch = 1, col = 2:4)

from the code above, you can use Kung package to create a simple Shiny app easily to see what happen to the shape of the graphs when you change the value of your model parameters, i.e., beta and gamma by adding these keywords into your code and save it as a new file: !Start, !Parameters, !ODECMD, !PostProcess, !Plots, !Controls, !End. See the example below.

!Start

library(deSolve)

init <- c(S = 1-1e-6, I = 1e-6, R= 0.0)
times <- seq(0, 70, by = 1)

sir <-function(time, state, parameters) {
  with(as.list(c(state, parameters)), {
    dS <- -beta*S*I
    dI <- beta*S*I - gamma*I
    dR <- gamma*I

    return(list(c(dS, dI, dR)))
  })
}

!Parameters
parameters <- c(
  gamma = 0.14286,
  beta = 0.6
)

!ODECMD
out <- as.data.frame(ode(y = init, times = times, func = sir, parms = parameters))

!PostProcess

!Plots
matplot(times, out[,c("S","I","R")], type = "l", xlab = "Time", ylab = "Susceptibles and Recovereds", main = "SIR Model", lwd = 1, lty = 1, bty = "l", col = 2:4)
legend(40, 0.7, c("Susceptibles", "Infecteds", "Recovereds"), pch = 1, col = 2:4)

!Controls
sliderInput("beta","beta", min = 0,max = 10,step = 0.001,value = 1.4),
sliderInput("gamma","gamma", min = 0,max = 1,step = 0.001,value = 0.14)

!End

To create the Shiny app, just type

runSystem('yournewfile').

You can’t perform that action at this time.