Skip to content
Prev 97718 / 398498 Next

Fitting data with optim or nls--different time scales

<see in line>
Leslie Chavez wrote:
SG:  What about the following:

  Modelfit=function(s) {
  	parms[1:4]=s[1:4];
	times=c(0,7,12,14,17,20,25)
	lsodaTimes <- seq(min(times),max(times), by=0.01)
  	out=lsoda(x0,lsodaTimes,Model,parms)
	obsTimes <- (100*times-1)
  	mse=mean((log10(out[obsTimes,4])-log10(i(times)))^2)
  #	cat(times)
  	return(mse)
  }

	  Your example is not self contained, so obviously I haven't tried this 
with it.  However, something of this nature should work fine, I believe. 
  Something similar but different should also work, I believe, with 
'nls';  this would give you access to many helper functions (see 
"methods(class='nls')").  If 'nls' bombed on me, I'd then try 'optim' as 
it is less brittle.  Then I might use the output of 'optim' as initial 
values for 'nls' to get confidence intervals etc.

	  hope this helps.
	  Spencer Graves