[R] Maximization problem in the optim function
Niroshan
wnnperer at ucalgary.ca
Thu Mar 15 01:43:42 CET 2012
This is the part of the function in my likelihood function
prob<-function(t1,t2,m1,m2,s_r,s_p,s_e,cor_m){
if ((t1==0) & (t2==0))
log_lik<-log(pmvnorm(lower=rep(-Inf, 2),
upper=c(m1/sqrt(s_r+s_p+s_e+1),m2/sqrt(s_r+s_p+s_e+1)),
mean=rep(0,2), corr=cor_m))
else if ((t1==0) & (t2==1))
log_lik<-log(pmvnorm(lower=c(-Inf,m2/sqrt(s_r+s_p+s_e+1)),
upper=c(m1/sqrt(s_r+s_p+s_e+1),Inf),
mean=rep(0,2), corr=cor_m))
else if ((t1==1) & (t2==0))
log_lik<-log(pmvnorm(lower=c(m1/sqrt(s_r+s_p+s_e+1),-Inf),
upper=c(Inf,m2/sqrt(s_r+s_p+s_e+1)),
mean=rep(0,2), corr=cor_m))
else if ((t1==1) & (t2==1))
log_lik<-log(pmvnorm(lower=c(m1/sqrt(s_r+s_p+s_e+1),m2/sqrt(s_r+s_p+s_e+1)),
upper=c(Inf,Inf),
mean=rep(0,2), corr=cor_m))
return(log_lik)
}
--
View this message in context: http://r.789695.n4.nabble.com/Maximization-problem-in-the-optim-function-tp4473408p4473602.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list