likelihood with integration in R

by Nata107   Last Updated April 13, 2017 04:19 AM

Could someone help me with my code?

I need to do ML with integral inside with using data there not only parameters

I am using next code:

B<-function(beta) { trial<-function(eps) {dnorm(eps)pnorm((dat$taxcor*beta[2]+beta[3]*dnorm(eps)/pnorm(dat$salesbeta[1])))/(1-beta[3]^2*(epsdnorm(eps/pnorm(dat$sales*beta[1]+(dnorm(-dat$salesbeta)/pnorm(dat$sales*beta[1]))^2)))^(1/2))} integrate(trial, lower = -dat$sales*beta[1], upper = Inf)$value }

likeli<-function(beta){prod((pnorm(dat$sales*beta[1])*B(beta))) }

likelihood<-nlm(likeli,beta<-c(0,0,0), hessian='True')

I have a mistake in maximization:

Error in integrate(trial, lower = -dat$sales * beta, upper = Inf) : evaluation of function gave a result of wrong length

Thank you for comments and suggestions

Related Questions

Find ML estimate of a and b

Updated April 13, 2018 17:19 PM

Integrating kernel density estimator in 2D

Updated May 28, 2015 11:08 AM