Re: [R] nonlinear fitting on many voxels

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Mon, 09 Jun 2008 12:59:15 -0700

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.&nbsp; 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.&nbsp; I've tested the routine using simulated data and things went well.&nbsp; As for the real data, the fitting routine works variably.&nbsp; By variably, I mean the following: &nbsp; 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.&nbsp; NEVER was I able to get starting values that would allow the routine to run entirely!&nbsp; The error I would get after fitting the limited number of voxels is:&nbsp;
>
> "Error in approx(x, fx, n = 2 * n.pts + 1) :
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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.&nbsp; I've tried
> numerous nonlinear functions including: nlm, optim and nlminb, but all
> stop after performing the fit on a limited number of voxels.&nbsp; I
> took the values for which the fitting routine stops and I applied
> different starting values to them and it works!&nbsp; 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.&nbsp; 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


&nbsp; 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 ______________________________________________ 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.
Received on Mon 09 Jun 2008 - 20:05:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 Jun 2008 - 01:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive