You are on page 1of 27

What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation in R: An Introduction

Presented By:
Varun Agiwal

Research Scholar
Department of Statistics
Central University of Rajasthan, Ajmer, Rajasthan
Email:varunagiwal.stats@gmail.com

March 22 , 2018
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Outline

1 What is Simulation

2 Need of Simulation

3 Importance

4 Application
Methods for generating random numbers
Random Sample Generation in R
Simulation study for properties of estimators
Simulation for properties of hypothesis tests

5 Necessary Information regarding Simulation


What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

What is Simulation

The fundamental objective of scientific research is to make bet-


ter inference. In decision modelling, simulation is the one of the
most widely used technique. This method were initially applied
by mathematicians and physicists to solve certain deterministic
problems that could be expressed as mathematical equations
whose solutions could not be easily obtained by the usual nu-
merical or analytical methods.
Simulation
A numerical technique for conducting experiments on the
computer. The act of simulating is to try to duplicate the
characteristics of a real system. Simulation is used when
conducting experiments on a real system is impossible or
impractical, often because of cost or time.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Need of Simulation

• Analysis when observable(real) data is not available.


• Get approximate results when no direct or closed
expressions are obtained.
• Provide solutions where analytic results are not available.
• To check validity of estimation and testing methods.
• To show the eventual real effects of alternative conditions.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Importance

• Save money and time: Experiments with simulation are less


expensive and take less time than experiments with real
datasets.
• Increased accuracy: It capture many more details than an
analytical model which provides increased accuracy and
more precise forecasting.
• Handle uncertainty: Outcome can be easily represented with
certainty and more robust solutions to be found.
• Handle complexity: Analytical results are easily obtained for
large and complex function.
• Visualization: Allowing concepts and ideas to be more easily
verified, communicated, and understood.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Steps Involving for Simulation

Step 1: Identifying all necessary information and defining


relevant objectives.
Step 2: Use random numbers to generate random values.
Step 3: Record the observation of interest to reach the desire
objective.
Step 4: Replicated many times to cover the full range of
variability.
Step 5: Summarize the information and draws conclusions.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Methods for generating random numbers

Methods for generating random numbers

We can simulate a random draw from any probability density


(mass) function if we know the expression of density function.
There are many techniques for generating random variates from
a specified probability distribution such as the normal, expo-
nential or gamma distribution. However, one technique stands
out because of its generality and simplicity is the inverse CDF
method. The inverse CDF technique for generating a random
sample uses the following step:
Step 1: Compute CDF of a desired random variable X.
Step 2: Set F(X)=U where U is generated from U(0,1).
Step 3: Compute X in terms of U that is X = F −1 (U)
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Methods for generating random numbers

Problem 1: Generate random numbers for Weibull


distribution using inverse CDF method

Output
2.316056 1.987240 2.006050 2.048347 1.612728 2.214568
1.858669 1.579586 2.005297 1.929183
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Random Sample Generation in R

Random Sample Generation in R

R has many functions that generate random variables that


follow many types of distributions.
runif() # Random Uniform distribution
rnormal() # Random Normal distribution
rt() # Random Student T distribution
rexp() # Random Exponential distribution
rchisq() # Random Chi-Square distribution
rbinom() # Random Binomial distribution
If you type help(Distributions) in R, you will get a complete
listing of those built into R. Many others are available in other
packages.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Simulation study for properties of estimators

For estimation purpose, three basic properties of statistical es-


timators that researchers might want to evaluate using simula-
tions:
B Bias
B Consistency
B Efficiency
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Simulation procedure

For a particular choice of Θ0 , n, and true underlying distribution


or model
1 Generate independent draws X1 , X2 , . . . , Xn from the
distribution or model
2 Compute MLE of the parameters.
3 Repeat S times: Θ̂(1) , Θ̂(2) , . . . , Θ̂(S)
  S
Calculate mean Θ̂ = S1 Θ̂(s) , standard deviation
P
4

s s=1
  S  2
1
Θ̂(s) − Θ̂
P
SD Θ̂ = S−1
s=1
S
1 P (s)
absolute bias = (Θ̂ − Θ0 ; mean square error

S
s=1
S  2
1
Θ̂(s) Θ0 =SD 2 + Bias2
P
= S −
s=1
5 Draw conclusion with varying sample size.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Problem 2:MLE of the exponential parameter


Perform 1000 simulations to estimate the parameter of
exponential distribution when true value of λ = 2 and also find
its mean square error and absolute bias with varying sample
size.

Problem 3:Estimation of simple linear regression


parameters.
Perform 1000 simulations to estimate the parameter of simple
linear regression model when true value of β0 = 0.2, β1 = 0.5
and then find its mean square error and absolute bias with
varying sample size.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Solution 2:
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Output

Table: Estimate value, Average Bias and MSE for λ

n Estimate SD Average Bias MSE


20 2.1292 0.5208 0.4014 0.2876
50 2.0524 0.2966 0.2321 0.0906
100 2.0044 0.2092 0.1647 0.0437
200 2.0040 0.1429 0.1135 0.0204
500 2.0030 0.0899 0.0722 0.0081
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators


What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Solution 3:
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Output

Table: Estimate value, Average Bias and MSE for intercept coefficient
Sample Size Estimate SD Average Bias MSE
100 0.2011 0.0993 0.0783 0.0099
200 0.1994 0.0712 0.0570 0.0051
300 0.1986 0.0580 0.0463 0.0034
400 0.1992 0.0514 0.0412 0.0026
500 0.2012 0.0444 0.0354 0.0020

Table: Estimate value, Average Bias and MSE for slope coefficient
Sample Size Estimate SD Average Bias MSE
100 0.5027 0.1729 0.1388 0.0299
200 0.4981 0.1193 0.0937 0.0142
300 0.5020 0.1027 0.0820 0.0106
400 0.5013 0.0847 0.0676 0.0072
500 0.4958 0.0782 0.0623 0.0061
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators


What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators


What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation study for properties of estimators

Conclusion

Figure shows the convergence for the parameters as well as


histogram, together with the respective MSE and ABs. From the
figure, see that estimate parameters distributed approximately
normal random variable. We also clearly see that in either case,
the mean square error and absolute bias is decreases as sam-
ple size increases.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation for properties of hypothesis tests

Simulation for properties of hypothesis tests

Simulation are not useful just for evaluating estimators, it is also


possible to conduct tests of a statistic when one has not able to
find a test statistic which free of parameters. Hence, using simu-
lation we test if the statistic from the observed data is consistent
with the statistics calculated from data generated under the null
hypothesis. In hypothesis, we mainly find
B Test statistic value
B P-value
B Power of a test
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation for properties of hypothesis tests

Simulation procedure

Under certain null hypothesis for a particular model


1 Generate random sample X1 , X2 , . . . , Xn from the null
distribution or model
2 Compute the test statistic.
3 Repeat S times: T (1) , T (2) , . . . , T (S)
4 check rejection criterion at significance level α.
5 Draw conclusion with varying sample size.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation for properties of hypothesis tests

Problem 4:
Generate a sample from normal random variable N(10, 25).
Consider the hypothesis test defined by H0 : µ = 10 against
H1 : µ 6= 10. Evaluate the type I error using 500 simulation at
5% significance level.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation for properties of hypothesis tests


What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Simulation for properties of hypothesis tests

Conclusion
On the basis of plot, concluded that rejection of the p-value is
more when sample size is small. As sample size increases,
rejection of null hypothesis is decreases at 5 % level of
significance.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

Necessary Information regarding Simulation

i. Careful planning is required.


ii. Do not only choose factors favourable to a proposed
method we have developed.
iii. Results must be recorded and saved in a systematic,
sensible way.
iv . Keep S small at first and increasing S when we are sure
everything is working correctly before carrying out final
simulation.
v . Ensure simulation runs are independent.
vi. Get an idea of how long it takes to process one time.
What is Simulation Need of Simulation Importance Application Necessary Information regarding Simulation

You might also like