Home > Back-end >  attempt to apply non-function(R)
attempt to apply non-function(R)

Time:09-26

I'm trying to run the following code in R, but I'm getting an error.

I'm not sure what part of the formula is incorrect. Any help would be greatly appreciated.

loglik<-function(y,theta)
{
  mu=theta[1]
  sigma2=theta[2]
  lambda=theta[3]
  n=length(y)
  -0.5*n*log(2*pi)-0.5*n*log(sigma2)-sum((y^lambda-1)/lambda-mu)^2/(2*sigma2) (lambda-1)(sum(log(y)))
}

Error: attempt to apply non-function

CodePudding user response:

The issue is in

(lambda-1)(sum(log(y))

If it needs to be multiplied, add the *

(lambda-1)*(sum(log(y))

CodePudding user response:

You are missing a * in the final line of the function.. Should be (lambda-1)*(sum(log(y)))

  •  Tags:  
  • r
  • Related