[R] How can I fitting this function from values.
Rolf Turner
r.turner at auckland.ac.nz
Mon Nov 12 21:16:28 CET 2007
On 13/11/2007, at 8:27 AM, Horacio Castellini wrote:
> Hi all, I'd like fit this function:
>
> G(t)=A*1/(1+t/B)*1/sqrt(1+t/C)
>
> where A, B and C are fitting constants that one like search. I have
> got a fcs<-(t,G(t)) value table in a data frame.
>
> Any one can help me? Tahnks Horacio.
I ***thought*** that nls would solve your problem in a trice.
But I tried a toy example before replying to you, and it messed up
mightily:
foo <- function(t,ccc){
ccc[1]*1/(1+t/ccc[2])*1/sqrt(1+1/ccc[3])
}
ttt <- seq(1,10,length=100)
yyy <- foo(ttt,c(5,3,2))
set.seed(42)
dat.test <- data.frame(t=ttt,y=yyy+rnorm(100,0,0.1))
with(dat.test,plot(t,y))
with(dat.test,lines(t,foo(t,c(5,3,2)))) # Looks cool.
fit.test <- nls(y~A*1/(1+t/B)*1/sqrt(1+t/C),start=list
(A=5,b=3,C=2),data=dat.test)
# Gives error; no idea what the implications are.
The error message:
Error in `[[<-.data.frame`(`*tmp*`, var, value = c(0.70934153524875,
0.761288405463172, :
replacement has 65 rows, data has 100
In addition: Warning message:
In t/B : longer object length is not a multiple of shorter object length
I don't think I have *ever* had a good experience with nls(); it is
always pretty flaky.
(Well, maybe it worked for me once ..., can't remember for sure. :-) )
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list