The SMC Procedure

Example 23.1 Stochastic Susceptible-Infected-Recovered Model with a Constant Transmission Rate

This example illustrates how to define a stochastic susceptible-infected-recovered (SSIR) model with a constant transmission rate in the SMC procedure and then estimate the parameters using the PMCMC method.

Consider the following SSIR model within the framework of the state space model:

  • Initialization distribution:

    StartLayout 1st Row 1st Column upper I upper D 1 2nd Column equals upper Y 1 2nd Row 1st Column upper I upper U 1 2nd Column tilde uniform left-parenthesis 0.75 StartFraction upper I upper D 1 Over p EndFraction comma 1.75 StartFraction upper I upper D 1 Over p EndFraction right-parenthesis 3rd Row 1st Column upper R upper C 1 2nd Column equals 0 4th Row 1st Column upper S 1 2nd Column equals upper N minus upper I upper D 1 minus upper I upper U 1 5th Row 1st Column xi 1 2nd Column tilde Poisson left-parenthesis StartFraction r Over upper N upper D EndFraction upper S 1 left-parenthesis upper I upper D 1 plus upper I upper U 1 right-parenthesis right-parenthesis EndLayout
  • Transition distribution:

    StartLayout 1st Row 1st Column upper R upper C Subscript t 2nd Column equals upper R upper C Subscript t minus 1 Baseline plus StartFraction 1 Over upper D EndFraction left-parenthesis upper I upper D Subscript t minus 1 Baseline plus upper I upper U Subscript t minus 1 Baseline right-parenthesis 2nd Row 1st Column upper I upper D Subscript t 2nd Column equals left-parenthesis 1 minus StartFraction 1 Over upper D EndFraction right-parenthesis upper I upper D Subscript t minus 1 Baseline plus upper Y Subscript t minus 1 Baseline 3rd Row 1st Column upper I upper U Subscript t 2nd Column equals left-parenthesis 1 minus StartFraction 1 Over upper D EndFraction right-parenthesis upper I upper U Subscript t minus 1 Baseline plus xi Subscript t minus 1 Baseline minus upper Y Subscript t minus 1 Baseline 4th Row 1st Column upper S Subscript t 2nd Column equals upper S Subscript t minus 1 Baseline minus xi Subscript t minus 1 Baseline 5th Row 1st Column xi Subscript t 2nd Column tilde Poisson left-parenthesis StartFraction r Over upper N upper D EndFraction upper S Subscript t Baseline left-parenthesis upper I upper D Subscript t Baseline plus upper I upper U Subscript t Baseline right-parenthesis right-parenthesis EndLayout
  • Measurement distribution:

    upper Y Subscript t Baseline tilde binomial left-parenthesis int left-parenthesis upper I upper U Subscript t Baseline right-parenthesis comma p right-parenthesis

Here xi Subscript t, a Poisson distributed instance, denotes the number of new infections at time t plus 1; upper S Subscript t denotes the number of susceptible individuals at time t; upper Y Subscript t is the number of new observed infections at time t; upper R upper C Subscript t is the cumulative number of recovered infections until time t; upper I upper D Subscript t is the number of documented active infectious individuals at time t; and upper I upper U Subscript t is the number of undocumented active infectious individuals at time t. Moreover, N denotes the population, r denotes the basic reproduction number, p is the diagnosis rate, D denotes the average time to removal after infection, StartFraction 1 Over upper D EndFraction denotes the recovery rate, and StartFraction r Over upper D EndFraction is the transmission rate. In this SSIR model, there are three parameters: r, D, and p; and there are five state variables: xi, S, upper I upper D, upper I upper U, and upper R upper C.

The prior specification for the parameters are given as follows:

StartLayout 1st Row 1st Column r 2nd Column tilde uniform left-parenthesis 2.6 comma 3.3 right-parenthesis 2nd Row 1st Column upper D 2nd Column tilde gamma left-parenthesis 325.5 comma 0.0285714286 right-parenthesis 3rd Row 1st Column p 2nd Column tilde uniform left-parenthesis 0.1 comma 0.4 right-parenthesis EndLayout

The initial values and bounds for the parameters are given by

StartLayout 1st Row 1st Column r 2nd Column equals 2.9 comma r Subscript l Baseline equals 2.6 comma r Subscript u Baseline equals 3.3 2nd Row 1st Column upper D 2nd Column equals 9.3 comma upper D Subscript l Baseline equals 6.5 comma upper D Subscript u Baseline equals 11 3rd Row 1st Column p 2nd Column equals 0.25 comma p Subscript l Baseline equals 0.1 comma p Subscript u Baseline equals 0.4 EndLayout

where the bounds of r and p are identical to the supports of their prior distributions, whereas the bounds of D are different from the support of its prior distribution, which is left-parenthesis 0 comma normal infinity right-parenthesis. To achieve this, the bounds can be specified in the PARAMETER statement as a supplement to the supports of the prior distributions.

The following statements simulate 89 observations based on the given stochastic volatility model. The first 75 observations are used as a training data set, and the remaining 14 observations are used as a test data set.


*macro variables;
%let N=20000000; *population;
%let Y_1 = 100;
%let IU_1 = 500;
%let RC_1 = 0;
%let D = 8.7;
%let r = 3.1;
%let p = 0.25;
data sir_all;
   call streaminit(1);
   t = 1;
   ID = &Y_1;
   IU = &IU_1;
   RC = &RC_1;
   S = &N - ID - IU;
   xi = RAND('POISSON', &r/(&N*&D)*S*(ID+IU));
   Y = &Y_1;
   sum = S + IU + ID + RC;
   output;
   do t = 2 to 89;
      RC = RC + 1/&D*(IU + ID);
      IU = (1-1/&D)*IU + xi - Y;
      ID = (1-1/&D)*ID + Y;
      S = S - xi;
      xi = RAND('POISSON', &r/(&N*&D)*S*(ID+IU));
      Y = RAND('BINOMIAL', &p, int(IU));
      sum = S + IU + ID + RC; *sum is always equal to N;
      output;
   end;
run;

The following DATA steps load the first 75 observations of the data set sir_all into a data set sir_train and then load that data set into a data table in your CAS session that is associated with the mycas CAS engine libref. The DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref. The last 14 observations of the data set sir_all are loaded into a data set sir_test.

data sir_train;
   set sir_all;
   if (t le 75) then output;
run;

data sir_test;
   set sir_all;
   if (t > 75) then output;
run;

data mycas.sir_train;
   set sir_train;
run;

The following statements use PROC SMC to define the preceding SSIR model and then use the PMCMC method to estimate the three parameters for the simulated data set. The posterior medians will be used as the parameters in the smoothing and forecasting process.

proc smc data=mycas.sir_train seed = 1234 nthreads = 32;
   id time = t;
   var y;
   statevar S ID IU xi RC;
   smooth nparticle=20480 parm=median alg=sir method=fixedlag(16)
      out(pct=2.5,97.5)=mycas.sm;
   forecast nparticle=20480 parm=median alg=sir lead=14
      out(pct=2.5,97.5)=mycas.fc;
   parm r=2.9, D=9.3, p=0.3 /lower=(2.6 6.5 0.1) upper=(3.3 11 0.4);

   prior r ~ uniform(2.6, 3.3);
   prior D ~ gamma(325.5, 0.0285714286);
   prior p ~ uniform(0.1, 0.4);

   initstate ID ~ degenerate(100);
   initstate IU ~ uniform(0.85*ID/p, 2*ID/p);
   initstate RC ~ degenerate(0);
   initstate S ~ degenerate(&N - ID - IU);
   initstate xi ~ poisson(r/(&N*D)*S*(ID+IU));

   state RC ~ degenerate(RC.l1 + 1/D*(ID.l1+IU.l1));
   state ID ~ degenerate((1-1/D)*ID.l1 + Y.l1);
   state IU ~ degenerate((1-1/D)*IU.l1 + xi.l1 - Y.l1);
   state S ~ degenerate(S.l1 - xi.l1);
   state xi ~ poisson(r/(&N*D)*S*(ID+IU));

   model y~normal(p*IU,ifn(IU>1,2*sqrt(p*(1-p)*IU),2*sqrt(p*(1-p))));
   learn nparticle=256 algorithm=sir method=PMCMC(nsample=25000
      nchain=8 nbi=5000 thin=5 seed=1
      outpost=mycas.out samset samsum
      sampler=rwm(ntu=250)
      statistics=all diagnostics=all);
run;

The summary tables of the model information are shown in Output 23.1.1.

Output 23.1.1: Model Information Summary

The SMC Procedure

State Space Model Information
Number of Parameters3
Number of State Variables5
Number of Dependent Variables1
Number of Independent Variables0
Seed Value1234

Number of Observations75
Number of Missing Observations0

Initial Parameters Information
ParameterInitial
Value
Lower
Bound
Upper
Bound
r2.900002.600003.30000
D9.300006.5000011.00000
p0.300000.100000.40000


The summary tables of the posterior samples are shown in Output 23.1.2.

Output 23.1.2: Posterior Summary

MCMC Sampler Settings
MCMC Sampling MethodRWM
Random Seed1
Transformed SamplingFalse
Number of Chains8
Number of Sampling Iterations25000
Number of Burn-in Iterations5000
Thinning Interval5
Number of Tuning Iterations per Tuning Stage250
Number of Tuning Stages24
Target Metropolis Acceptance Rate0.234
Initial RWM Proposal Scale2.38
Tuning Weight0.75
Acceptance Tolerance0.075

The SMC Procedure

Posterior Summaries
ParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
r400003.15800.06143.07523.11123.13673.24283.2577
D400008.92080.23388.60508.74288.84019.24729.2949
p400000.24160.008600.22800.22980.24430.24810.2538

Posterior Intervals
Parameter95% Equal-Tail Interval95% HPD Interval
r3.07523.25773.08373.2577
D8.60509.29498.63769.2950
p0.22800.25380.22790.2524


The correlation and covariance matrices of the parameter samples that are generated by the PMCMC method are shown in Output 23.1.3.

Output 23.1.3: Correlation and Covariance Matrices

Posterior Covariance Matrix
ParameterrDp
r0.0037680.014348-0.00053
D0.0143480.05466-0.00201
p-0.00053-0.002010.000074

Posterior Correlation Matrix
ParameterrDp
r1.00000.9998-0.9994
D0.99981.0000-0.9994
p-0.9994-0.99941.0000


The following statements load the smoothing estimates for each state variable into the Work library and then sort each data set by the time ID:

data smo_1; set mycas.sm(where=(VariableID=1 and TimeID>=1)); run;
proc sort data=smo_1; by timeId; run;

data smo_2; set mycas.sm(where=(VariableID=2 and TimeID>=1)); run;
proc sort data=smo_2; by timeId; run;

data smo_3; set mycas.sm(where=(VariableID=3 and TimeID>=1)); run;
proc sort data=smo_3; by timeId; run;

data smo_4; set mycas.sm(where=(VariableID=4 and TimeID>=1)); run;
proc sort data=smo_4; by timeId; run;

data smo_5; set mycas.sm(where=(VariableID=5 and TimeID>=1)); run;
proc sort data=smo_5; by timeId; run;

The following statements create a relevant data table, combine_S, in the Work library to record the smoothing estimates and actual values of the number of susceptible individuals. Then they draw a plot to compare the smoothing estimates to the actual values at each time step. The plot is shown in Output 23.1.4, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

data combine_S;
   set smo_1 (keep=P_1 P_2 Q2);
   set sir_train (keep=t S);
run;

proc sgplot data=combine_S;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   series x=t y=S /legendlabel='Actual Value' lineattrs=(color=red);
   series x=t y=Q2 /legendlabel='Smoothing Median'
      lineattrs=(color=blue pattern=shortdash);
   yaxis label='S, Smoothing Median';
   xaxis label='Day';
run;

Output 23.1.4: Smoothing Estimates vs. Actual Values, S

Smoothing Estimates vs. Actual Values, S


The following statements create a relevant data table, combine_ID, in the Work library to record the smoothing estimates and actual values of the number of documented active infectious individuals. Then they draw a plot to compare the smoothing estimates to the actual values at each time step. The plot is shown in Output 23.1.5, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

data combine_ID;
   set smo_2 (keep=P_1 P_2 Q2);
   set sir_train (keep=t ID);
run;

proc sgplot data=combine_ID;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   series x=t y=ID /legendlabel='Actual Value' lineattrs=(color=red);
   series x=t y=Q2 /legendlabel='Smoothing Median'
      lineattrs=(color=blue pattern=shortdash);
   yaxis label='ID, Smoothing Median';
   xaxis label='Day';
run;

Output 23.1.5: Smoothing Estimates vs. Actual Values, ID

Smoothing Estimates vs. Actual Values, ID


The following statements create a relevant data table, combine_IU, in the Work library to record the smoothing estimates and actual values of the number of undocumented active infectious individuals. Then they draw a plot to compare the smoothing estimates to the actual values at each time step. The plot is shown in Output 23.1.6, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

data combine_IU;
   set smo_3 (keep=P_1 P_2 Q2);
   set sir_train (keep=t IU);
run;

proc sgplot data=combine_IU;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   series x=t y=IU /legendlabel='Actual Value' lineattrs=(color=red);
   series x=t y=Q2 /legendlabel='Smoothing Median'
      lineattrs=(color=blue pattern=shortdash);
   yaxis label='IU, Smoothing Median';
   xaxis label='Day';
run;

Output 23.1.6: Smoothing Estimates vs. Actual Values, IU

Smoothing Estimates vs. Actual Values, IU


The following statements create a relevant data table, combine_xi, in the Work library to record the smoothing estimates and actual values of the number of new infectious individuals the next day. Then they draw a plot to compare the smoothing estimates to the actual values at each time step. The plot is shown in Output 23.1.7, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

data combine_xi;
   set smo_4 (keep=P_1 P_2 Q2);
   set sir_train (keep=t xi);
run;

proc sgplot data=combine_xi;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   series x=t y=xi /legendlabel='Actual Value' lineattrs=(color=red);
   series x=t y=Q2 /legendlabel='Smoothing Median'
      lineattrs=(color=blue pattern=shortdash);
   yaxis label='xi, Smoothing';
   xaxis label='Day';
run;

Output 23.1.7: Smoothing Estimates vs. Actual Values, xi

Smoothing Estimates vs. Actual Values, xi


The following statements create a relevant data table, combine_RC, in the Work library to record the smoothing estimates and actual values of the cumulative number of recovered individuals. Then they draw a plot to compare the smoothing estimates to the actual values at each time step. The plot is shown in Output 23.1.8, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

data combine_RC;
   set smo_5 (keep=P_1 P_2 Q2);
   set sir_train (keep=t RC);
run;

proc sgplot data=combine_RC;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   series x=t y=RC /legendlabel='Actual Value' lineattrs=(color=red);
   series x=t y=Q2 /legendlabel='Smoothing Median'
      lineattrs=(color=blue pattern=shortdash);
   yaxis label='RC, Smoothing';
   xaxis label='Day';
run;

Output 23.1.8: Smoothing Estimates vs. Actual Values, RC

Smoothing Estimates vs. Actual Values, RC


The median smoothing estimates of all the state variables are close to the actual values of the simulated data set. The following statements load the forecasting result for each state variable into the Work library and then sort each data set by the time ID:

data fc_4; set mycas.fc(where=(VariableID=4)); run;
proc sort data=fc_4; by _t; run;

data fc_6; set mycas.fc(where=(VariableID=6)); run;
proc sort data=fc_6; by _t; run;

The following statements create a relevant data table, combine_xi_forecast, in the Work library to record the forecasting estimates and actual values of the number of new infectious individuals the next day. Then they draw a plot to compare the forecasting estimates to the actual values at each time step. The plot is shown in Output 23.1.9, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the forecasting estimates.

data combine_xi_forecast;
   set fc_4 (keep=P_1 P_2 Q2);
   set sir_test (keep=t xi);
run;

proc sgplot data=combine_xi_forecast;
   band x=t upper=P_2 lower=P_1 /transparency=.3;
   scatter x=t y=xi /legendlabel='Actual Value'
      markerattrs=(color=red size=6 symbol=circlefilled);
   series x=t y=Q2 /legendlabel='Forecasting Median'
      markers markerattrs=(color=blue size=6 symbol=triangle)
      lineattrs=(color=blue pattern=solid);
   yaxis label='xi, Forecasting';
   xaxis integer label='Day';
run;

Output 23.1.9: Forecasting Estimates vs. Actual Values, xi

Forecasting Estimates vs. Actual Values, xi


The following statements create a relevant data table, combine_Y_forecast, in the Work library to record the forecasting estimates and actual values of the new confirmed cases. Then they draw a plot to compare the forecasting estimates to the actual values at each time step. The plot is shown in Output 23.1.10, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the forecasting estimates.

data combine_Y_forecast;
   set fc_6 (keep=P_1 P_2 Q2);
   set sir_test (keep=t Y);
run;

proc sgplot data=combine_Y_forecast;
   band x=t upper=P_2 lower=P_1 / transparency=.3;
   scatter x=t y=Y /legendlabel='Actual Value'
      markerattrs=(color=red size=6 symbol=circlefilled);
   series x=t y=Q2 /legendlabel='Forecasting Median'
      markers markerattrs=(color=blue size=6 symbol=triangle)
      lineattrs=(color=blue pattern=solid);
   yaxis label='Number of the New Observed Infections, Forecast';
   xaxis integer label='Day';
run;

Output 23.1.10: Forecasting Estimates vs. Actual Values, New Case

Forecasting Estimates vs. Actual Values, New Case


Last updated: September 15, 2022