Tony Tsai

May the force of science be with you

Apr 20, 2015 - 1 minute read - Comments - R

Stratified Importance Sampling

The following R codes implement the Example 5.13 in Statistical Computing with R, and compare the estimate \(\hat{\theta}\) and \(\hat{\sigma}\) from stratified importance sampling to the results from importance sampling. The example illustrates that stratification can reduce the varinace of importance sampling estimator. M <- 100000 # number of replicates g <- function(x) { exp(-x - log(1 + x^2)) * (x > 0) * (x < 1) } # importance sampling u <- runif(M) # f3, inverse transform method x <- -log(1 - u * (1 - exp(-1))) fg <- g(x) / (exp(-x) / (1 - exp(-1))) (theta.

Dec 4, 2014 - 17 minute read - Comments - Influenza

SIRS Model with Time Dependent Transmission Rate

1 SIRS Model The SIRS model is simply an extension of the SIR model as it allows members of the recovered class to rejoin the susceptible class at a defined rate, which integrates the impact of waning immunity following antigenic drift. Similar to the SIR model, a fixed population without births and deaths is considered in the SIRS model. The standard form of SIRS model is described as \[ \begin{equation} \begin{aligned} & \frac{dS}{dt} = fR - \frac{\beta SI}{N} \\ & \frac{dI}{dt} = \frac{\beta SI}{N} - \gamma I \\ & \frac{dR}{dt} = \gamma I - fR \end{aligned} \label{eq1} \end{equation} \] where \(f\) is the average loss of immunity rate of recovered indiviuals, and the other notations are the same as the SIR model.

Nov 24, 2014 - 1 minute read - Comments - Numerical Computation

Precision Difference of ode45 between R and MATLAB

ode45 solvers from both R and MATLAB are used to run simulations of the spread of Hong Kong flu in New York city with different initial susceptible individuals \(S\_0 =\) 790, 7900, 79000, 790000, and 7900000. The maximum infected people \(I_{max}\) under each condition is recorded for comparison. The following codes draw a figure showing the precision difference of ode45 solvers between R and MATLAB. Imax <- data.frame(S0 = 79 * 10 ^ (1:5), R = c(57.

Nov 24, 2014 - 18 minute read - Comments - Influenza

RK4 Method for Solving SIR Model

My object is to rewrite the 4th order Runge-Kutta (abbreviated for RK4) method for solving the absolute humidity-driven SIRS model developed by Yang et al. (2014) in R language. The details of the SIRS model are provided in the paper. 1 RK4 1.1 Preliminary RK4 is one of the classic methods for numerical integration of ODE models. A brief introduction of RK4 refers to Wikipedia. Consider the following initial value problem of ODE \[ \begin{equation} \begin{aligned} & \frac{dy}{dt} = f(t, y) \\ & y(t_0) = y_0 \end{aligned} \label{eq1-rk4} \end{equation} \] where \(y(t)\) is the unknown function (scalar or vector) which I would like to approximate.