Book Image

R Object-oriented Programming

By : Kelly Black
Book Image

R Object-oriented Programming

By: Kelly Black

Overview of this book

Table of Contents (19 chapters)
R Object-oriented Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
4
Calculating Probabilities and Random Numbers
Package Management
Index

Examples


We will now provide a brief example to demonstrate how to use the Simulation and MonteCarlo classes described in the previous sections. We focus on the discrete simulation class, but additional examples can be found in the code that accompanies this text. In this example, we assume that the definitions for the simulation and MonteCarlo classes are contained in two files, simulationS3.R and monteCarloS3.R.

The Monte-Carlo simulations can be created by first creating an object from the MontyCarlo class and setting the values of the parameters as follows:

> source('simulationS3.R')
> source('monteCarloS3.R')

> monty <- MonteCarlo()
> monty$setParams(100,1,
                1.0,2.0,
                1.2,-0.3,0.65,0.2,
                0.03,0.04)

Now that an object from the MonteCarlo class is defined, an object from the DiscreteSimulation class is created, and the simulation object is used to generate the results from 500 simulations:

> a <- DiscreteSimulation()
&gt...