# What do additional arguments indicate in the simple.sim function in R?

In R suppose that we have the following code:

 require("UsingR") # required for "simple.sim" function below
f= function(n=100,mu=0,sigma=1) {
nos = rnorm(n,mu,sigma)
(mean(nos)-mu)/(sigma/sqrt(n))
}

simulations = simple.sim(100,f,100,5,5)
hist(simulations,breaks=10,prob=TRUE)


Does this basically simulate 100 normal random variables with mean 5 and standard deviation 5? In the simulations argument, what do the 5's indicate?

-
Have you read the help page for simple.sim? –  whuber May 15 '12 at 17:56
Is this homework? It should be tagged if it is. –  Seth May 15 '12 at 20:31
Do you want to simulate normal random variables? It seems like you are after something more complicated, but I am not sure what. –  Seth May 16 '12 at 4:43

When you look at the simple.sim() help page you see there are two arguments and an ellipsis("..."). The ellipsis allows you to pass any unspecified argument through simple.sim() into one of the nested functions, here f() and rnorm(). So you are getting mu is 5 and sigma is 5. It is pretty bad practice to pass unnamed arguments this way, so be careful!

Now you know where the numbers are being passed. Do you think the output of your f function is norm(mean=5,sd=5)?

f() creates a vector of random normals with mean mu=5 and standard deviation sigma=5 but then it applies a function. The results of that function may or may not be normal.

-
@Seth: Let the $X_i$ be normal with $\mu =5$ and $\sigma= 5$. Then the function above should have $\mu = 5$ and $\sigma=5$ instead of $\mu=0$ and $\sigma=1$. So maybe it was just a typo. –  user11347 May 16 '12 at 3:48
simulations = simple.sim(100,f,5,5) replaces $\mu = 0, \sigma = 1$ with $\mu = 5, \sigma=5$? –  Damien May 16 '12 at 4:31
where you see the mu = 1 and the sigma = 0 is where the function f() is defined. The way it is written the 0 and the 1 are just the default values. The default values are ignored because the simple.sim passes the two fives in as mu and sigma –  Seth May 16 '12 at 4:34