I want to run some maximum likelihood code on the data sample I have created. This is what I have so far:
library("maxLik")
data <- replicate(20, rnorm(100))
logLikFun <- function(param) {
mu <- param[1]
sigma <- param[2]
sum(dnorm(data, mean = mu, sd = sigma, log = TRUE))
}
mle <- maxLik(logLik = logLikFun, start = c(mu = 0, sigma = 1))
summary(mle)
I am having some problems extracting the mean and standard deviation for each sample of the 20, I amended the apply function to try to suit this but nothing has worked yet. Any ideas?
Create a function (
find.mlein this example) that takes a vector of data and calculates the MLE based on it, and then useapplyto apply that to the columns ofdata:This will give you a 2×20 matrix with your estimates: