Docsity

Simulation Speed up Methods - Notes | STAT 705, Study notes of Statistics

Toggle sidebar
bg1
4 Introductory Graphics
We discussed in class the commands plot,points,lines,legend, along with
the graphical parameters typ e (= ”p” points, ”n” none, ”l” lines, ”b” both),
xlab,ylab,main,xlim,ylim,pch,lty. These and lots more can be studied
by invoking the help window on “par” once the Rhelp is started.
An extended example, for you to repeat and study, is given in the Rlogs
directory of the course web-page
http://www.math.umd.edu/∼evs/s705/Rlogs
as Rlog2.txt.
5 Simulation Speed-up Methods
We have already discussed the mechanics of (Uniform) pseudo-random num-
ber generation. Most interesting applications of Simulation or the ‘Monte
Carlo Method’ in applied probability and statistics concern evaluation of
expectations of combinations of random variables and stochastic-process tra-
jectories
E(f((Z(t),t>0),Y
1,Y
2,...) ) (1)
which are (much) too complicated to evaluate or approximate analytically.
The function fwill often be an indicator for occurrence of a particular
event within a single realization of a data structure. In useful statistical and
probabilistic simulations, there is usually need to simulate complicated data
structures or large batches with a view to tabulating relative frequencies of
occurrence, sometimes of relatively rare events such as those associated with
type I and type II errors in statistical hypothesis tests. This can be slow,
not only because of the need for looping in R, but because of complicated
dependencies among data or nontrivial analyses for each simulated batch of
data.
There are several well-recognized methods for speeding up generation of
random data, especially with respect to specific purposes involving uncom-
mon events. Two good general references (the first of which is much longer
and more detailed, and the second of which will serve us later as a reference
45
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Simulation Speed up Methods - Notes | STAT 705 and more Study notes Statistics in PDF only on Docsity!

4 Introductory Graphics

We discussed in class the commands plot, points, lines, legend, along with the graphical parameters type (= ”p” points, ”n” none, ”l” lines, ”b” both), xlab, ylab, main, xlim, ylim, pch, lty. These and lots more can be studied by invoking the help window on “par” once the R help is started.

An extended example, for you to repeat and study, is given in the Rlogs directory of the course web-page

http://www.math.umd.edu/∼evs/s705/Rlogs

as Rlog2.txt.

5 Simulation Speed-up Methods

We have already discussed the mechanics of (Uniform) pseudo-random num- ber generation. Most interesting applications of Simulation or the ‘Monte Carlo Method’ in applied probability and statistics concern evaluation of expectations of combinations of random variables and stochastic-process tra- jectories E ( f((Z(t), t > 0), Y 1 , Y 2 ,... ) ) (1)

which are (much) too complicated to evaluate or approximate analytically. The function f will often be an indicator for occurrence of a particular event within a single realization of a data structure. In useful statistical and probabilistic simulations, there is usually need to simulate complicated data structures or large batches with a view to tabulating relative frequencies of occurrence, sometimes of relatively rare events such as those associated with type I and type II errors in statistical hypothesis tests. This can be slow, not only because of the need for looping in R, but because of complicated dependencies among data or nontrivial analyses for each simulated batch of data.

There are several well-recognized methods for speeding up generation of random data, especially with respect to specific purposes involving uncom- mon events. Two good general references (the first of which is much longer and more detailed, and the second of which will serve us later as a reference

for more elaborate Monte Carlo methods) are:

Devroye, L., Non-Uniform Random Variate Generation. Springer, 1986.

Robert, C. & Casella, G. , Monte-Carlo Statistical Methods. Springer, 1999.

There are also many texts on ‘Discrete-Event Simulation’, concerning the methodology of designing and programming (in some high-level languages especially suited to the purpose) simulations which arise in queueing, inven- tory, finance, and operations research generally. One major author who has written several well-regarded texts is George Fishman. Our resident expert on this at UMCP is Dr. Michael Fu of BMGT.

We concentrate our attention on defining and giving brief examples of three general simulation speed-up methods:

(1). Rejection Methods

(2). Control-Variate Methods

(3). Importance-sampling Methods

Of these methods, the first and third involve directly simulating something different from data with the desired behavior: we simulate something easier, and then discard or modify certain cases systematically, using a theoretical idea to justify that the expectation in formula (1) is obtained from what is actually simulated. The second method is a pure variance-reducer: it is essen- tially a regression of a difficult-to-obtain quantity (the integrand in Equation (1)) on one or several related quantities whose corresponding expectations are known from some other (typically theoretical) considerations.

5.1 Rejection Methods

An example of this method — generation of Normal deviates from Cacuhy — has already been covered in class. Here we give an abstract description. Suppose that we know how to generate a random vector W from a specified probability density g and that we define a modified variable Y as being

via least-squares, recalling that a = E(Z) is what we are after. Once we have assumed that Yi has the exactly known expectation m, this is an ‘orthogonal regression design’ in the sense that the design column consisting of all 1’s is uncorrelated with (and therefore in large samples approximately orthogonal to) the design column (Yi − m, i = 1,... , N). From well known results of linear regression theory, the variance of ˆa conditionally given (Yi − m, i = 1,... , N) (and therefore also unconditionally) is

1 N

Var(e 1 ) =

N

( Var(Z 1 )−b^2 Var(Y 1 −m)

)

N

Var(Z 1 ) (1−Corr^2 (Y 1 , Z 1 ))

So the benefit of this approach is to decrease the width of simulation-based

confidence intervals for E(Z) by a factor

√ 1 − (Corr(Y, Z))^2. The benefit can sometimes be amplified by regressing on more than one control variate, as we indicate in the next Example.

5.2.1 A Toy Clinical Trial Case-Study Example

We describe an example in which the variable Z of interest is the ‘total time on test’ of all patients in a small clinical trial conducted as follows. Sixty (60) patients are ‘accrued’ (i.e. brought) into the trial at times Ui which are uniformly distributed within the first year and randomly allocated (by an independent fair coin toss for each patient) to group Zi = 1 or 0. From the time of their entry into the study, the individuals have lifetimes Ti which in group 0 are Exponentially distributed with rate λ 0 , and which in group 1 are Exponential lifetimes with rate-parameter λ 0 · e∆. At the end of each of t = 1, 2 years a statistic is calculated, defined by

St =

T T (1, t) D(0, t) − T T (0, t) D(1, t) (T T (0, t) + T T (1, t))^2

√ D(1, t) + D(0, t)

where T T (z, t) denotes the total time on test in group z up to time t, and D(z, t) denotes the total number in group z who have died by time t. Note that in large-sample settings, S 1 is approximately a normal variable (with mean and variance which are easily calculated numerically, no matter what ∆ is), and S 1 is approximately standard-normal if ∆ = 0.

This statistic St is a variant of some commonly used (weighted logrank) test statistics commonly used in clinical trials: large positive values indicate

that there are fewer group-1 deaths than would have been expected if both groups have the same survival distribution, i.e., if ∆ = 0.

Here is a decision rule for the clinical trial which allows ‘early stopping’: stop and reject at t = 1 if S 1 ≥ 2 .4, otherwise continue to t = 2 and reject if S 2 > 1 .7. (Accept at t = 2 if neither of these rejection conditions holds.)

One problem of interest is: for clinical trials like this one, what is the expected total time on test, for various choices of ∆? (This total time on test is the sum over patients of the number of years each patient is in the trial before the trial stops. It is one measure of clinical trial cost.) Although I have approximate formulas, I do not know how to calculate this (even asymptotically, if 60 is replaced by n going to ∞).

So our Z is taken equal to total time on test. What is a relevant set of control variates? A simple and natural choice is the pair of variables

T T 1 = T T (0, 1) + T T (1, 1) , T T 2 = T T (0, 2) + T T (1, 2)

This choice is useful because the expected time on test variables up to the fixed times 1, 2 are easily shown to be given by simple formulas which under the null hypothesis (after an integration by parts) become

E(T T 1 ) = 60

∫ (^1)

0

(1 − t)e−λ^0 t^ dt =

λ 0

[ 1 −

1 − e−λ^0 λ 0

]

E(T T 2 ) = 60

∫ (^2)

0

min(2 − t, 1)e−λ^0 t^ dt = e−λ^0 E(T T 1 ) + 60

1 − e−λ^0 λ 0

The simulation of such a clinical trial including all relevant statistics, was implemented in an Splus function when Stat 705 was taught in 2005. The defaults, which were used here, included λ 0 = 0. 7 and ∆ = 0. The outputted data, from which we can not only calculate the desired expectation two ways but can see the factor by which the contol-variate method reduces variance, is as follows [where a few irrelevant entries have been deleted]:

> unlist(TrialSim(0, Nrep=1000)) Power ET VarT S1sq1 S1sq2 S2sq1 S2sq 0.053 0.915158 0.0069185 1.2471 4.7832 1.0317 2.

5.3 Importance Sampling

The idea of Importance Sampling is that, when we are simulating the occur- rence of a rather unlikely event, we may be able to simulate instead under a different probability law, and find the expectation of a suitable multiple of the indicator-function of the event of interest. So if we are interested in the occurrence of an event D with respect to a vector X of variables with a joint density f, and if D is unlikely according to f but not according to a simple related joint density g, then instead of

simulating X 1 ,... , XN ∼ f , estimating Pˆ (D) = N−^1

∑^ N

i=

ID(Xi)

we could

simulate Y 1 ,... , YN ∼ g , and estimate Pˆ (D) = N−^1

∑^ N j=

f(Yj ) g(Yj )

ID(Yj )

5.3.1 Example: Power of a Test

Suppose that we plan to have a moderately large (n = 40) sample of Expo- nential(λ 0 ) data-values for which we want to test λ 0 = 1 versus λ 0 = 0.6. The Neyman-Pearson test statistic is S = X 1 + ... + X 40 , and we would often use the CLT to approximate the rejection region by

{ X : (S − 40)/

We want to know whether the significance level is really 0.05 for this small a sample-size, whether the related rejection-region {(S − 40)/

S > 1. 645 }

has the same significance level, and which of the two regions has the better power. (Normal theory suggests that this power ought to be roughly 1 −

Φ(50. 40 − 40 · 5 /3)/

√ 40 · (5/3)^2 = 0.9386.)

Note that the events which we are trying to simulate have small proba- bilities! We will use N = 10000 and explore the gain in accuracy which is possible by importance sampling, when we recognize that we know some- thing about likelihood ratios in the particular problem. Note that f and

g respectively denote the joint densities of 40 exponential variates with different exponential parameters λ, λ′, so

f(y, λ) g(y, λ′)

( λ λ′

) 40 exp

( −(λ − λ′)

∑

i

yi

)

The function used to accomplish the simulation is called SmExpTst, and it is also available in the course Splus-data directory. The first input pa- rameter is the value λ′^ used to generate simulated variates (Yi with density g), and the second parameter is the value λ for which we want to calculate a rejection tail-probability. (There are two further input parameters: the size nsiz of each data-sample, with default value 40, and the number Nrep of simulation-replications with default value 10000. A typical simulated re- sult (in this case corresponding to the direct null-hypothesis simulation) is as follows:

> SmExpTst(1,1)[1:2] [1] 0.05890000 0.

So for the direct null-hypothesis simulation, we have (for the original rejection region) the slightly above-nominal size 0.059. The second output component is the empirical variance of the rejection indicator (essentially p(1 − p) for p = .0589), which implies because of the large number of replications that the confidence interval for the actual significance level does lie above the nominal value .95.

The corresponding information for power (based on a direct simulation) is:

> SmExpTst(0.6,0.6, Upper=F)[1:2] [1] 9.4860e-01 4.8763e-

The theoretical prediction of 0.95 turned out to be very accurate: the empirical answer is around 0.948, with confidence interval tolerances around

± 1. 96

√

. 04876 / 104 ≈ ± 0 .004.

Now let us simulate these with the importance-sampling approach. The simplest idea for λ′^ is to use a value for which bare rejection is the most likely occurrence, i.e., to use as rate parameter the value given by the cutoff:

Further small comparisons show that it does not help to choose the importance-sampling λ′^ still smaller than 0 .7936, even though the num- ber of nonzero items to average goes up, because those nonzero things have bigger variance!

Additional simulations to find the actual power of the test-statistic with denominator

S could be done using a completely analogous importance- sampling method, and we leave this as an optional exercise.