I'm trying to fit my data to a regression model as follows : y=betaMu+betaA*Xa+betaD*Xd+si
where si
is an error term with a normal distribution. I wrote the code below, where phen[,2]
is data for y
, data.xa[,1]
is Xa
and data.xd[,1]
is Xd
:
library(stats4)
ll <- function(betaM,betaA,betaD, mu, sigma){
R= phen[,2]-betaM-betaA*data.xa[,1]-betaD*data.xd[,1]
R = suppressWarnings(dnorm(R, mu, sigma, log=TRUE))
-sum(log(R))
}
fit <- mle(ll,start = list(betaM = 1, betaA = 1,betaD=1 ,mu = -1, sigma=1.5))
but I keep getting this error :
Error in optim(start, f, method = method, hessian = TRUE, ...) : initial value in 'vmmin' is not finite In addition: Warning message: In log(R) : NaNs produced
Can anyone help me fix this?