> opt.out
$par
[1] 5.271906 2.112786 5.655760 1.899040
$value
[1] 0.1945089
$counts
function gradient
205 NA
$convergence
[1] 0
$message
NULL
> opt.out2
$par
[1] 13.855497 1.723488 19.658422 1.871615
$value
[1] 0.1943919
$counts
function gradient
399 NA
$convergence
[1] 0
$message
NULL
>
minC<--2
maxC<-2
x<-c(2^(seq(from=minC,to=maxC,length=10)))
a<-5
b<-2
U<-5
L<-2
y<-U/(1+(a/x)^b)+L
s<-0.3
y<-y+rnorm(length(y),sd=sqrt(var(y))*s)
X<-log(x)
fr <- function(ks) {
k1 <- ks[1]
k2 <- ks[2]
k3 <- ks[3]
k4 <- ks[4]
sum((y-(k3/(1+(k1/x)^k2)+k4))^2)
}
fr2 <- function(ks) {
k1 <- ks[1]
k2 <- ks[2]
k3 <- ks[3]
k4 <- ks[4]
sum((y-(k3/(1+exp(-k2*(log(x)-log(k1))))+k4))^2)
}
opt.out<-optim(runif(4)*10, fr)
opt.out2<-optim(runif(4)*10, fr2)
par(mfcol=c(2,2))
plot(x,y)
t<-2^(seq(from=min(X),to=max(X),length=100))
points(t,opt.out$par[3]/(1+(opt.out$par[1]/t)^opt.out$par[2])+opt.out$par[4],col=2,cex=0.01)
plot(log(x),y)
points(log(t),opt.out$par[3]/(1+(opt.out$par[1]/t)^opt.out$par[2])+opt.out$par[4],col=2,cex=0.01)
plot(X,y)
points(log(t),opt.out2$par[3]/(1+exp(-opt.out2$par[2]*(log(t)-log(opt.out2$par[1]))))+opt.out2$par[4],col=2,cex=0.01)
plot(exp(X),y)
points(t,opt.out2$par[3]/(1+exp(-opt.out2$par[2]*(log(t)-log(opt.out2$par[1]))))+opt.out2$par[4],col=2,cex=0.01)
opt.out
opt.out2