Hi, this following problem is a S-Plus problem, I know
many guys here are also experts in S-plus, so I am
posting here, too.
Thanks
I encountered a weird problem of fitting nls inside a
loop, it works well in R, but not in S-plus. The code
is:
>
data1<-cbind(c(2.87,1.66,0.44,-0.78,-2.00,-3.21,-4.43,-5.65,2.87,1.66,0.44,-0.78,-2.00,-3.21,-4.43,-5.65),c(-0.69,-1.91,-3.13,-4.34,-5.56,-6.78,-7.99,-9.21,-0.69,-1.91,-3.13,-4.34,-5.56,-6.78,-7.99,-9.21))
>
data2<-cbind(c(8.05,6.50,5.03,4.37,4.03,3.92,3.87,3.89,7.84,6.27,4.74,4.14,3.76,3.69,3.69,3.71),c(8.07,6.94,5.59,4.43,3.66,3.00,2.64,2.40,8.09,6.90,5.56,4.44,3.50,2.71,2.48,2.08))
> par(mfrow=c(2,2))
> for (i in 1:2) {
conc<-data1[,i]
signal<-data2[,i]
fit<-nls(signal~SSfpl(conc,A,B,xmid,scal))
p.conc<-data.frame(conc=(1:99)*(max(conc)-min(conc))/100+min(conc))
plot(as.numeric(p.conc[,1]),as.numeric(predict(fit,newdata=p.conc)),type='l',col=4)
}
When the above code was run in R, it worked very well,
but when it was run in S-plus, it gave me the
following error:
Problem in data.frameAux.list(x, na.strings na.strings, stringsAsFactors ..:
arguments imply
differing number of rows: 4, 3,
2, 16, 4, 4, 4, 4, 16, 1, 1, 1, 1
Also, If I only run the loop for only 1 cycle (either
No.1 or No.2 by setting "for (i in 1:1)" or "for (i in
2:2)), the code worked ok in S-Plus, so the problem
has nothing to do with my data.
If I replace
"fit<-nls(signal~SSfpl(conc,A,B,xmid,scal))" with
"fit<-lm(signal~conc)", then the code worked well in
both R and S-Plus. So it seems the problem only
pertain to the "nls" function. Can anyone pinpoint the
problem for me?
Thanks