The SIMNORMAL Procedure

Example: SIMNORM Procedure

(View the complete code for this example.)

The following example illustrates the use of PROC SIMNORMAL to generate variable values conditioned on a set of related or correlated variables.

Suppose you are given a sample of size 50 from ten normally distributed, correlated random variables, . The first five variables represent input variables for a chemical manufacturing process, and the last five are output variables.

First, the data are input and the correlation structure is determined by using PROC CORR, as in the following statements. The results are shown in Figure 106.2.

data a ;
   input in1-in5 out1-out5 ;
   datalines ;
 9.3500    10.0964     7.3177    10.3617    10.3444    9.4612
10.7443     9.9026     9.0144    11.7968
 7.8599    10.4560    10.0075     8.5875    10.0014   10.3869

   ... more lines ...   

 8.9174     9.9623     9.5742     9.9713
run ;
proc corr data=a cov nocorr outp=outcov ;
   var in1-in5 out1-out5 ;
run ;

Figure 106.2: Correlation of Chemical Process Variables

Statistics for PROC SIMNORM Sample Using NUMREAL=5000

The CORR Procedure

10 Variables:in1 in2 in3 in4 in5 out1 out2 out3 out4 out5

Covariance Matrix, DF = 49
 in1in2in3in4in5out1out2out3out4out5
in11.0191983310.1280867990.2916463820.3270149160.4175467320.0976507130.2066984030.5162711210.1187261060.261770905
in20.1280867991.0564608180.1435817990.0959377070.1041177430.056612934-0.1217007310.2665814510.092288067-0.020971411
in30.2916463820.1435817991.3840512490.0588539600.3261077300.0934988390.0782940870.4815765540.0578163220.259053423
in40.3270149160.0959377070.0588539601.0231286780.3479168640.0229156450.1259614910.1796272370.0750282300.078147576
in50.4175467320.1041177430.3261077300.3479168641.6068581400.3602703180.2970465930.7492129450.2201963370.349618466
out10.0976507130.0566129340.0934988390.0229156450.3602703180.8070075540.2172858790.064816340-0.0539314480.037758721
out20.206698403-0.1217007310.0782940870.1259614910.2970465930.2172858790.9294558060.2068256640.1385510080.054039499
out30.5162711210.2665814510.4815765540.1796272370.7492129450.0648163400.2068256641.8375052680.2929639750.165910481
out40.1187261060.0922880670.0578163220.0750282300.220196337-0.0539314480.1385510080.2929639750.832831377-0.067396486
out50.261770905-0.0209714110.2590534230.0781475760.3496184660.0377587210.0540394990.165910481-0.0673964860.697717191

Simple Statistics
VariableNMeanStd DevSumMinimumMaximum
in15010.189881.00955509.494007.6350012.58860
in25010.106731.02784505.336408.1258013.78310
in35010.148881.17646507.444207.3177012.40080
in45010.038841.01150501.942007.4049011.99060
in55010.225871.26762511.293407.2335012.93360
out1509.853470.89834492.673408.0122012.24660
out2509.968570.96408498.428407.7642012.09450
out35010.295881.35555514.794107.2966013.74200
out45010.158560.91260507.927808.4309012.45230
out55010.260230.83529513.011307.8606011.96000


After the mean and correlation structure are determined, any subset of these variables can be simulated. Suppose you are interested in a particular function of the output variables for two sets of values of the input variables for the process. In particular, you are interested in the mean and variability of the following function over 500 runs of the process conditioned on each set of input values:

Although the distribution of these quantities could be determined theoretically, it is simpler to perform a conditional simulation by using PROC SIMNORMAL.

To do this, you first append a _TYPE_=’COND’ observation to the covariance data set produced by PROC CORR for each group of input values:

data cond1 ;
   _TYPE_='COND' ;
   in1 = 8    ;
   in2 = 10.5 ;
   in3 = 12   ;
   in4 = 13.5 ;
   in5 = 14.4 ;
   output ;
run ;

data cond2 ;
   _TYPE_='COND' ;
   in1 = 15.4 ;
   in2 = 13.7 ;
   in3 = 11 ;
   in4 = 7.9 ;
   in5 = 5.5 ;
   output ;
run ;

Next, each of these conditioning observations is appended to a copy of the OUTP=OUTCOV data from the CORR procedure, as in the following statements. A new variable, INPUT, is added to distinguish the sets of input values. This variable is used as a BY variable in subsequent steps.

data outcov1 ;
   input=1 ;
   set outcov cond1 ;
run ;

data outcov2 ;
   input=2 ;
   set outcov cond2 ;
run ;

Finally, these two data sets are concatenated:

data outcov ;
   set outcov1 outcov2 ;
run ;
proc print data=outcov ;
   where (_type_ ne 'COV') ;
run ;

Figure 106.3 shows the added observations.

Figure 106.3: OUTP= Data Set from PROC CORR with _TYPE_=COND Observations Appended

Statistics for PROC SIMNORM Sample Using NUMREAL=5000

Obsinput_TYPE__NAME_in1in2in3in4in5out1out2out3out4out5
111MEAN 10.189910.106710.148910.038810.22599.85359.968610.295910.158610.2602
121STD 1.00961.02781.17651.01151.26760.89830.96411.35550.91260.8353
131N 50.000050.000050.000050.000050.000050.000050.000050.000050.000050.0000
141COND 8.000010.500012.000013.500014.4000.....
252MEAN 10.189910.106710.148910.038810.22599.85359.968610.295910.158610.2602
262STD 1.00961.02781.17651.01151.26760.89830.96411.35550.91260.8353
272N 50.000050.000050.000050.000050.000050.000050.000050.000050.000050.0000
282COND 15.400013.700011.00007.90005.5000.....


You now run PROC SIMNORMAL, specifying the input data set and the VAR and COND variables. Note that you must specify a TYPE=COV or TYPE=CORR for the input data set. PROC CORR automatically assigns a TYPE=COV or TYPE=CORR attribute for the OUTP= data set. However, since the intermediate DATA steps that appended the _TYPE_=’COND’ observations turned off this attribute, an explicit TYPE=CORR in the DATA= option in the PROC SIMNORMAL statement is needed.

The specification of PROC SIMNORMAL now follows from the problem description. The condition variables are IN1–IN5, the analysis variables are OUT1–OUT5, and 500 realizations are required. A seed value can be chosen arbitrarily, or the system clock can be used. Note that in the following statements, the simulation is done for each of the values of the BY variable INPUT:

proc simnormal data=outcov(type=cov)
      out = osim
      numreal = 500
      seed = 33179
      ;
   by input ;
   var out1-out5 ;
   cond in1-in5 ;
run;

data b;
   set osim ;
   denom = sum(of out1-out5) ;
   if abs(denom) < 1e-8 then ff = . ;
   else ff = (out1-out3)/denom ;
run ;

The DATA step that follows the simulation computes the function ; in the following statements the UNIVARIATE procedure computes the simple statistics for this function for each set of conditioning input values. This is shown in Figure 106.4, and Figure 106.5 shows the distribution of the function values for each set of input values by using the SGPANEL procedure.

proc univariate data=b ;
   by input ;
   var ff ;
run ;
title ;
proc sgpanel data=b ;
   panelby input ;
   REFLINE 0 / axis= x ;
   density ff ;
run ;

Figure 106.4: Simple Statistics for ff for Each Set of Input Values

Statistics for PROC SIMNORM Sample Using NUMREAL=5000

The UNIVARIATE Procedure
Variable: ff

Moments
N500Sum Weights500
Mean-0.0134833Sum Observations-6.7416303
Std Deviation0.02830426Variance0.00080113
Skewness0.56773239Kurtosis1.31522925
Uncorrected SS0.49066351Corrected SS0.39976435
Coeff Variation-209.92145Std Error Mean0.0012658

Basic Statistical Measures
LocationVariability
Mean-0.01348Std Deviation0.02830
Median-0.01565Variance0.0008011
Mode.Range0.21127
  Interquartile Range0.03618

Tests for Location: Mu0=0
TestStatisticp Value
Student's tt-10.6519Pr > |t|<.0001
SignM-106Pr >= |M|<.0001
Signed RankS-33682Pr >= |S|<.0001

Quantiles (Definition 5)
LevelQuantile
100% Max0.11268600
99%0.07245656
95%0.03270269
90%0.02064338
75% Q30.00370322
50% Median-0.01564850
25% Q1-0.03247389
10%-0.04716239
5%-0.05572806
1%-0.07201126
0% Min-0.09858350

Extreme Observations
LowestHighest
ValueObsValueObs
-0.09858354710.075053822
-0.09081794720.0794747245
-0.0802423900.084016048
-0.07606452490.1004812222
-0.07560702260.112686050

Statistics for PROC SIMNORM Sample Using NUMREAL=5000

The UNIVARIATE Procedure
Variable: ff

Moments
N500Sum Weights500
Mean-0.0405913Sum Observations-20.295631
Std Deviation0.03027008Variance0.00091628
Skewness0.1033062Kurtosis-0.1458848
Uncorrected SS1.28104777Corrected SS0.4572225
Coeff Variation-74.57289Std Error Mean0.00135372

Basic Statistical Measures
LocationVariability
Mean-0.04059Std Deviation0.03027
Median-0.04169Variance0.0009163
Mode.Range0.18332
  Interquartile Range0.04339

Tests for Location: Mu0=0
TestStatisticp Value
Student's tt-29.985Pr > |t|<.0001
SignM-203Pr >= |M|<.0001
Signed RankS-58745Pr >= |S|<.0001

Quantiles (Definition 5)
LevelQuantile
100% Max0.06101208
99%0.02693796
95%0.01008202
90%-0.00111776
75% Q3-0.01847726
50% Median-0.04169199
25% Q1-0.06187039
10%-0.07798499
5%-0.08606522
1%-0.11026564
0% Min-0.12231183

Extreme Observations
LowestHighest
ValueObsValueObs
-0.1223129370.0272906688
-0.1198849800.0291769652
-0.1135129200.0388217670
-0.1123455230.0477261845
-0.1104978970.0610121632


Figure 106.5: Frequency Plot for ff for Each Set of Input Values

Frequency Plot for ff for Each Set of Input Values