Skip to content
Prev 81963 / 398506 Next

Minimizing a Function with three Parameters

voodooochild at gmx.de wrote:

            
hi sundar,

your advice has helped very much, thanks a lot.

now i have another model where instead of i    i2 is used, but i don't 
now way i got so large estimates?

x<-c(10,8,14,17,15,22,19,27,35,40)

# 1.Gleichung

l1 <- function(beta0,beta1,alpha,x) {
 n<-length(x)
 s2<-length(x)
   for(i in 1:n) {
   s2[i]<-log(beta0+beta1*i2)-log(x[i]+beta0+beta1*i2)
   }
 s2<-sum(s2)
 return((n/alpha)+s2)
}


# 2.Gleichung

l2 <- function(beta0,beta1,alpha,x) {
 n<-length(x)
 s1<-length(x)
 s2<-length(x)
   for(i in 1:n) {
   s1[i]<-1/(beta0+beta1*i2)
   s2[i]<-1/(beta0+beta1*i2+x[i])
   }
 s1<-sum(s1)
 s2<-sum(s2)
 return(alpha*s1-(alpha+1)*s2)
}

# 3.Gleichung

l3 <- function(beta0,beta1,alpha,x) {
 n<-length(x)
 s1<-length(x)
 s2<-length(x)
   for(i in 1:n) {
   s1[i]<-(i2)/(beta0+beta1*i2)
   s2[i]<-(i2)/(x[i]+beta0+beta1*i2)
   }
 s1<-sum(s1)
 s2<-sum(s2)
 return(alpha*s1-(alpha+1)*s2)
}

# Zusammenf??gen aller Teile

gl <- function(beta,x) {
 beta0<-beta[1]
 beta1<-beta[2]
 alpha<-beta[3]
 v1<-l1(beta0,beta1,alpha,x)2
 v2<-l2(beta0,beta1,alpha,x)2
 v3<-l3(beta0,beta1,alpha,x)2
 v1+v2+v3
}


# Nullstellensuche mit Nelder-Mead

optim(c(20000,6000,20000),gl,x=x,control=list(reltol=1e-12))

the values should be alpha=20485, beta0=19209 and beta1=6011

and another point is, what is a good method to find good starting values 
for 'optim'. it seems, that i only get the desired values when the 
starting values are in the same region. I used 
control=list(reltol=1e-12), but it seems, that then it is also important 
to have the starting values in the same region as the the desired values.

regards
andreas