[R] nonlinear fitting on many voxels

Charles C. Berry cberry at tajo.ucsd.edu
Mon Jun 9 21:59:15 CEST 2008


On Mon, 9 Jun 2008, Ayman Oweida wrote:

> After many months, I am now banging my head against the wall because I can't find a solution to this seemingly trivial problem.  Any help would be appreciated:
>
> I am trying to apply a nonlinear fitting routine to a 3D MR image on a voxel-by-voxel basis.  I've tested the routine using simulated data and things went well.  As for the real data, the fitting routine works variably.  By variably, I mean the following:   with a specific set of starting parameters the routine would work for the first 10 voxels, for another set of starting values the routine would work for the first 1000 voxels and so on.  NEVER was I able to get starting values that would allow the routine to run entirely!  The error I would get after fitting the limited number of voxels is: 
>
> "Error in approx(x, fx, n = 2 * n.pts + 1) :
>         need at least two non-NA values to interpolate"
>
> I think the error is from the library Bolstad since I'm using the 
> sintegral function as part of the fitting equation.  I've tried 
> numerous nonlinear functions including: nlm, optim and nlminb, but all 
> stop after performing the fit on a limited number of voxels.  I 
> took the values for which the fitting routine stops and I applied 
> different starting values to them and it works!  I'm still using 
> the same voxel/parameter values and I am sure they are not NA values as 
> per the error!

Reread the error message. It does NOT say that there are NA values. It 
only says that you 'need at least two non-NA values'.

>
> Ok, I think the problem is clear.  any solutions?

The problem is not clear.

Here is some advice:

 	PLEASE do read the posting guide
 	http://www.R-project.org/posting-guide.html and provide commented,
 	minimal, self-contained, reproducible code.

Often, developing the 'minimal' example helps you to perceive the 
underlying difficulty. Without it, you will only get very general advice 
and off-hand guesses about where your problem lies, which may not move you 
closer to a solution.

---

So here is some of that general advice: find out why approx() sends you 
that error message.

One way to do this is to set

 	options(error=recover)

before running your function. And then inspect objects in the frame in 
which the error occurred and in the frames leading up to the one in which 
the error was triggered. See

 	?recover

HTH,

Chuck


  I am new to this complex world of statistical analysis.
> Your help is very very much appreciated.
>
> Thanks,
> Ayman
>
> Montreal Neurological Institute
> Montreal, Canada
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list