# Estimating parameters of simulated Normal Data sets

#### chamilka

##### New Member
I am doing a simulation study. For my study, I need to simulate 10,000 data sets from standard normal distribution(each with 100 observations) and need to estimate the mean and standard deviation parameters of all 10,000 data sets.

I used replicate function to generate 10,000 data sets and declared the Normal Negative Likelihood and trying to estimate parameters by using mle2(which is a wrapper of "optim" function) .

What I need to know is: After estimating the parameters of all 10,000 data sets I need to create a 10,000 x 2 matrix which contains means estimates in first locum and standard deviation estimates in the second column. Please see my R codes given below,

Code:
library(bbmle)
only.one=rnorm(100, mean = 0, sd = 1) #simulate 100 observations from a standard normal disttribution

all.data=replicate(1000,rnorm(100, mean = 0, sd = 1)) #generating 1000 data sets #from standard normal distribution with each 100 observations
#declaring negative log likelihood for the MLE estimation
Code:
NormalNegloglik <- function(mean,sd) {
-sum(dnorm(x,mean,sd,log=TRUE))
}

I can estimate the mean and standard deviation parameters of the only.one simulated data as below
Code:
Estimates <- mle2(NormalNegloglik ,start=list(mean=0,sd=1),data=list(x=only.one))

#where mle2 is a wrapper of optim function avaiable in bbmle package
My output for only.one data
Code:
> Estimates

Call:
mle2(minuslogl = NormalNegloglik, start = list(mean = 0, sd = 1),
data = list(x = only.one))

Coefficients:
mean        sd
-0.160810  1.001141

Log-likelihood: -142.01

Now I need to estimate parameters of all the columns of all.data matrix by maximum likelihood estimation method and store the estimated parameters in a 10,000 by 2 matrix(or dataframe). Where the two columns will be one for the estimated means and one for the estimated standard deviation.

I think I should use sapply, or tappy or any other loop function, But I do not have a clear idea and thus your advice is greatly appreciative... Thank you in advance.