0

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))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • 2
    The root of your issue is probably here: `mean=x[1] (1-exp…`. Since `x[1]` is immediately followed by a paren, R thinks it’s a function you’re trying to execute. But `x[1]` presumably isn’t a function, which is what it’s complaining about — you’re attempting to apply a non-function. – zephryl Oct 25 '22 at 02:39

0 Answers0