## Monte Carlo Simulation

### Description

Runs Monte Carlo simulation for a selected estimation method. The function can save a file and produce a statistical summary.

### Usage

 1 2 3 4 5 6 Estim_Simulation(AlphaBetaMatrix = abMat, SampleSizes = c(200, 1600), MCparam = 100, Estimfct = c("ML", "GMM", "Cgmm","Kout"), HandleError = TRUE, FctsToApply = StatFcts, saveOutput = TRUE, StatSummary = FALSE, CheckMat=TRUE,tolFailCheck=tolFailure, SeedOptions=NULL,...) 

### Arguments

 AlphaBetaMatrix Values of the parameter α and β from which we simulate the data. By default, The values of γ and δ are set to 1 and 0 respectively; matrix 2 \times n SampleSizes Sample sizes to be used to simulate the data. By default, we use 200 (small sample size) and 1600 (large sample size); vector of integer. MCparam Number of Monte Carlo simulation for each couple of parameter, default=100; integer Estimfct The estimation function to be used. User can choose between ML, GMM, Cgmm or Kout. HandleError Logical flag: if set to TRUE, the simulation doesn't stop when an error in the estimation function is encountered. A vector of (size 4) NA is saved and the the simulation carries on. See details. FctsToApply Functions used to produce the statistical summary. See details ; vector of character. saveOutput Logical flag: if set to TRUE, a csv file (for each couple of parameter α and β) with the the estimation information is saved in the current directory. See details StatSummary Logical flag: if set to TRUE, a statistical summary (using FctsToApply) is returned. See details. CheckMat Logical flag: if set to TRUE, an estimation is declared failed if the squared error of the estimation is larger than tolFailCheck; default TRUE tolFailCheck Tolerance on the squared error of the estimation to be declared failed; default 1.5 SeedOptions List to control the seed generation. See details. ... Other arguments to be passed to the estimation function.

### Details

Error Handling It is advisable to set it to TRUE when user is planning to launch long simulations as it will prevent the procedure to stop if an error occurs for one sample data. The estimation function will produce a vector of NA as estimated parameters related to this (error generating) sample data and move on to the next Monte Carlo step. Statistical summary The function is able to produce a statistical summary of the Monte Carlo simulation for each parameter (slices of the list). Each slice is a matrix where the rows represents the true values of the parameters and the columns the statistical information. In all cases, the following quantities are computed:

sample size:

the sample size used to produce the simulated data

alphaT, betaT:

the true values of the parameters

failure:

the number of times the procedure failed to produce relevant estimation.

time:

The average running time in seconds of the estimation procedure

Besides, the (vector of character) FctsToApply controls the other quantities to be computed by providing the name of the function object to be applied to the vector of estimated parameter. The signature of the function should be of the form fctName=function(p,...){...} where p is the vector (length(p)=MCparam) of parameter estimate and ... is the extra arguments to be passed the function. By default, the functions of the StatFcts will be applied but user can pass his own functions by providing their name ( in the FctsToApply vector and their definition in the global environment. Note that if CheckMat is set to TRUE, the estimation is considered failed if the squared error (of the first 2 parameters alpha and beta) is larger than tolFailCheck. Output file Setting saveOutput to TRUE will have the side effect of saving a csv file in the working directory. This file will have MCparam*length(SampleSizes) lines and its columns will be :

alphaT, betaT:

the true value of the parameters.

data size:

the sample size used to generate the simulated data.

seed:

the seed value used to generate the simulated data.

alphaE, betaE, gammaE, deltaE:

the estimate of the 4 parameters.

failure:

binary: 0 for success, 1 for failure.

time:

estimation running time in seconds.

The file name is informative to let the user identify the value of the true parameters, the MC parameters as well as the options selected for the estimation method. The csv file is updated after each MC estimation which is useful when the simulation stops before it finishes. Besides, using the check-pointing mechanism explained below, the simulation can re-start from where it stopped. Check-pointing Checkpointing is the act of saving enough program state and results so far calculated that a computation can be stopped and restarted. The way we did it here is to save a text file with some useful information about the state of the estimation. This text file is updated after each MC iteration and read at the beginning of function Estim_Simulation to allow the simulation to re-start from where it stopped. This file is deleted at the end of the simulation procedure. SeedOptions If user does not want to control the seed generation, he could ignore this argument (default value NULL). This argument can be more useful when one wants to cut the simulation (even for one parameter value) into pieces. In that case, he can control which part of the seed vector he wants to use.

MCtot:

total values of MC simulations in the entire process.

seedStart:

starting index in the seed vector. The vector extracted will be of size MCparam.

### Value

If StatSummary is set to TRUE, a list with 4 slices (corresponding to the 4 parameters) is returned. Each slice is a matrix. If SaveOutput is set to TRUE, only a csv file is saved and nothing is returned (if StatSummary is FALSE). If both are FALSE, the function stops.

Estim,CgmmParametersEstim, GMMParametersEstim,MLParametersEstim