I'm trying to figure out the negative log likelihood function to get the maximum likelihood and the optim to get estimates. the first line runs fine but when i try and run the second I get the error:
Error in dnorm(data$height, mean = x[1](1 - exp((x[2] * data$age)), sd = sqrt((exp(x[3])), :
attempt to apply non-function
and I don't quite understand what I'm doing wrong.
nll.log.data <- function(x) -sum(dnorm(data$height, mean=x[1] (1-exp((x[2]*data$age)), sd=sqrt((exp(x[3])), log=TRUE))))
fit.data <- optim(c(150,-.02), nll.log.data, method="Nelder-Mead", control=list(trace=TRUE))