FindFit and NormFunction (to find a best fit by medians)

I'm trying to use FindFit to find a best linear fit using Medians rather
than Mean

At one time, I believe the following code worked (I used it in several
places, and never noted it failing, but it hasn't been used in a while and I
don't actually remember):

FindFit[sampledata,a+b*x,{a,b},x,NormFunction->(Sqrt[Median[#^2]]&)]

Now, Mathematica seems to pass unevaluated expressions to the NormFunction,
causing Median o fail with a "rectn: Rectangular array of real numbers is
expected at position 1" error.

I would appreciate any guidance.

Michael


0
nycstern (85)
9/6/2008 6:05:25 AM
comp.soft-sys.math.mathematica 28833 articles. 0 followers. Follow

2 Replies
173 Views

Similar Articles

[PageSpeed] 8
Hi,

thank you that you was so kind to post a complete working example,

sampledata =
  Table[{t, 0.2*Random[] + (2 + 0.1*Random[])*t}, {t, 0, 10, 0.25}];

myNorm[lst : {__Real}] := Sqrt[Median[lst^2]]

FindFit[sampledata, a + b*x, {a, b}, x, NormFunction -> myNorm]

will avoid the rectn-error message.

Regards
   Jens


Stern wrote:
> I'm trying to use FindFit to find a best linear fit using Medians rather
> than Mean
> 
> At one time, I believe the following code worked (I used it in several
> places, and never noted it failing, but it hasn't been used in a while and I
> don't actually remember):
> 
> FindFit[sampledata,a+b*x,{a,b},x,NormFunction->(Sqrt[Median[#^2]]&)]
> 
> Now, Mathematica seems to pass unevaluated expressions to the NormFunction,
> causing Median o fail with a "rectn: Rectangular array of real numbers is
> expected at position 1" error.
> 
> I would appreciate any guidance.
> 
> Michael
> 
> 

0
kuska (2791)
9/7/2008 9:35:42 AM
When I am trying one problem with FindFit, I found your note.

Here I have one similar question: Here I have TWO methods to constrain
the fitting process, one is the normal  least-squares method, another
is made by me. And now I want to use these two methods at the same
time.

You have given one method to use your own function, but how to write
the codes to add the normal least-squares into the program?


I have searched this  for a long time, but have not found this kind of
examples, please help me.


Many thanks

0
liqfer (3)
9/20/2008 8:55:24 AM
Reply:
Similar Artilces:

Re: FindFit and NormFunction
-----Original Message----- From: "David W. Cantrell" <DWCantrell@sigmaxi.org> Date: Sun, 5 Feb 2006 20:10:46 -0500 (EST) Subject: Re: FindFit and NormFunction > > Maxim <m.r@inbox.ru> wrote: > > On Fri, 3 Feb 2006 00:11:19 +0000 (UTC), Paul Abbott > > <paul@physics.uwa.edu.au> wrote: > > > > > I am having difficulty using the NormFunction option to FindFit. Let me > > > give a concrete example. Abramowitz and Stegun Section 17.3.35 gives a > > > nonlinear approximant to the complete elliptic integral. ...

Why can't CDrWin find my NEC DVD+RW 2100??
Hi CDrWin refuses to recognise my NEC DVD+RW device. What can I do to fix it? Andreas Hallerby Andreas Hallerby wrote... > >Hi > >CDrWin refuses to recognise my NEC DVD+RW device. >What can I do to fix it? > >Andreas Hallerby Try d/l aspi drivers from http://www.goldenhawk.com/download_body.htm. Back up your system before you install any drivers, just in case. Andreas Hallerby wrote: > Hi > > CDrWin refuses to recognise my NEC DVD+RW device. > What can I do to fix it? In addition to Harry's suggestion about an ASPI la...

HELP with where to find NEW MIDI
Argh, I'm getting well ticked off with not being able to find "Franz Ferdinand - Take Me Out" as a MIDI, can anyone help me find this? Also, I found an "Ace of Spades" MIDI file on this Slovakian(?) site, but it wouldn't let me save it. So if anyone can help me with this as well, I'd be very greatful. John On 16 Sep 2004 09:52:46 -0700, jdunbar98@macunlimited.net (John) wrote: >Also, I found an "Ace of Spades" MIDI file on this Slovakian(?) site, >but it wouldn't let me save it. So if anyone can help me with this as >well, I'd be...

PENGUINS ARE THE BEST BIRDS
PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS wrote: > PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS wrote: > PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS PENGUINS ARE THE BEST BIRDS wrote: > PENGUINS ARE THE BEST BIRDS ...

Findfit in C++
Hallo, I looking for the function similar to ' Findfit ' of mathematica in C++ ? Please can somebody help me with this.. your help much appreciated May Dear May, There are functions for fitting in the book Numerical Recipes http://www.nr.com/. A while ago, I had the same problem to fit some data in C++ and to reproduce the results from the Mathematica fit routine. The routine mrqmin (implementation of the Levenberg-Marquardt algorithm) should do what you want. The same algorithm is also normally used by default in Mathematica. At least, in my cas...

OLAP Cube Testing Best Practices & Automation
Has anyone ever seen or used any tools for developing automated test procedures for testing OLAP cubes? If you are familiar at all with Microsoft .NET technologies or Java, you may have heard of NUnit or JUnit (respectively). These are tools/frameworks used to develop reusable, automated unit test cases that can frequently be run during the development process. Presumably, any automated OLAP testing tool may still require me to write a good bit of MDX, but that may be okay... Any general best practices or articles in this area would be much appreciated. Thanks in advance for any a...

How to find the true hardware MAC address?
Hi, I need to know if there is a way to find the burned-in hardware MAC address? For example, if someone has changed the MAC on my system using the registry or the other spoofing tools then ipconfig /all would just show that spoofed address. I need to find the true hardware burned-in address. Is there any way to do that? Apart from physically reading the lable of the NIC. Is there a command or software or any way to do it programatically? Thanks... Regars, Ali ...

finding hosts allowed to do ftp
Hello, I am using a solaris 10 machine. From my cygwin/windowsXP PC I want to access the solaris machine through ftp. While accessing the solaris machine with ftp, I have to give root@<host> . How could I enquire that what are the valid <host> names . Thanks in advance. msh On Sep 30, 9:51=A0am, manish <manishmod...@gmail.com> wrote: > Hello, > > I am using a solaris 10 machine. From my cygwin/windowsXP PC I want to > access the solaris machine through ftp. > > While accessing the solaris machine with ftp, I have to give > root@<host> . > &g...

Finding name and owner of open files
Hello all, I would like to write a program which tells me all about running programs. Kind of like Window's Task Viewer on steroids. I have figured out most things except one. I would like to figure what open files (and hopefully list transactions as they happen) each task has. Any help would be greatly appreciated! Thanks, Adam There are some excellent free tools at http://www.sysinternals.com that might do some of what you want to build yourself. Frank, I am pretty familiar with Mark's and Bryce's work. I even went to see Mark at a Window'...

how to find mean of n observation for subject
HI All, I have data like The data like Each subject having two periods in two periods left and right and diffent samples for each left and right side for all subjects patid sample val1 val2 val3 side_t side period 1 3 2 4 2 LEFT 1 1 1 4 3 3 . LEFT 1 1 2 9 4 4 3 LEFT 1 1 2 11 3 5 3 LEFT 1 1 2 16 2 4 2 RIGHT 2 1 9 57 2 4 1 LEFT 1 1 9 58 4 2 LEFT 1 1 1 248 2 2 2 RIGHT 2 2 2 254 2 2 2 RIGHT 2 2 2 256 1 1 1 RIGHT 2 2 9 298 2 2 2 LEFT 1 2 9 300 1 1 1 LEFT 1 2 I want output like patid period side side_t val1 val2 val3 val4 val5 val6 mean 1 1 ...

Finder not finding
When I search using the 'Find' command the Finder lists all the files on my drive. Well, it seems to, I always abort the search before Finder finishes listing found files as there are so many. Anyone know what's going on and is there a fix? In article <3FC911CC.9050003@nlonline.demon.co.uk>, neil leslie <neilleslie@nlonline.demon.co.uk> wrote: > When I search using the 'Find' command the Finder lists all the files on > my drive. Well, it seems to, I always abort the search before Finder > finishes listing found files as there are so many. Anyo...

finding distance between two points
Hi, How distance between two points be calculated, provided their geodetic coordinates are given? Thanks "chapman z" <chapmankhan@gmail.com> wrote in message <faum51$9r5$1@fred.mathworks.com>... > Hi, > How distance between two points be calculated, provided > their geodetic coordinates are given? > Thanks flat space uses simple pythagorean formula.. but you say 'geodetic', are you talking latitude/longitude type of earth surface coordinates or some other kind of coordinates?? yes, the coordinates are in latitude, longitude and height. "...

Best DOS debugger?
What is the best DOS debugger? Thanks. Hi, On Aug 16, 1:00=A0am, Fritz Wuehler <fr...@spamexpire-201108.rodent.frell.theremailer.net> wrote: > > What is the best DOS debugger? Thanks. I feel sheepish even replying here due to inexperience. But since I just stumbled upon this *and* nobody else responded yet *and* traffic is low anyways *and* I'm bored / curious about things like this, I'll try giving a few guesses: (commercial): SoftICE ?? Borland Turbo Debugger ?? (Win32 version used to be freeware on Borland's site) MS Codeview ?? MS Symdeb ??...

Fitting with tabulated models
I have a large set of models where I have two (but plan to expand) degrees of freedom. The models are not directly compared to data, but need to be multiplied by a low-order polynomial to take out calibration issues and massaged in other ways. I have a function that returns a value of chi^2 for a model given some data, but it is not trivial so I would like to minimize the number of models I have to compare. My question is, what's the best method for finding the chi^2 minimum given tabulated function values? Should I try to use mpfit and make sure the minimum step size is larg...

Bounding Parameters used in FindFit[]
Is there a method to limit (bound) the search for a least-squares fit with FindFit[] in Mathematica 5.2? For example I am using FindFit[] to fit a decaying exponential of the form P1 * Exp[-t/P2] + P3. I know from the experiment that P3 is smaller than the value Mathematica continues to find for that parameter. It would be great if there was a way to bound the search for P3 to help Mathematica properly optimize P1 and P2. Joshua LaForge Hi Joshua, consider the surface of fit-residuals. If this surface has one unique minimum, you can either give P1 a fixed value or...

Finding a foreign key to any given table
This is a multi-part message in MIME format. --------------002DF50AE1DE79DD5838FD61 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Given a table existing in my database called "AAA", I can determine if a foreign key exists for "AAA" by looking up the "tabid" in the systables and finding any "R" constraints on the table by searching in sysconstraints for that tabid. Then, I can look up the constraint ID in the sysreferences table to find the ID of the table that is the "target" of the constraint (table &qu...

Find Question
Hi All, I am trying to write a find command that will list all jpg or gif files under my home direcotry. I tried the following: find . -type f -name '*.{gif,jpg}' -print but did not return anything. The second try was: find . -type f -name '*.gif' -o -name '*.jpg' -print but this would only return the jpg files, not gif ones. What am I doing wrong? Regards, George On 2008-04-01, George <me@me.com> wrote: > > > Hi All, > > I am trying to write a find command that will list all jpg or gif files > under my home direcotry. I tried the follo...

Which Baseball Game is the best?
Need one that is good and lets you name & roster your own teams. Thx On Thu, 01 Jan 2004 23:08:08 +0000, Arclight wrote: > Need one that is good and lets you name & roster your own teams. > > Thx high heat 2004, although a lot of people bitch about the lack of mouse support. who cares, you can navigate it just as easy with a control pad. no online feature also. a small price to pay if you're really into baseball as you will see once you play it. On Fri, 02 Jan 2004 17:52:37 GMT, radioactiveman <radioactivem@springfield.com> wrote: ...

Help finding INTERFACE4.PDF document
I've seen a number of references to: http://www.research.microsoft.com/~drh/pubs/interface4.pdf but that URL is no longer valid. Does anyone have a copy of this .PDF file that they can email to me (google@kaser.com) or have a valid URL that gets me to the document? Thanks! Everett Kaser I've now received a copy (actually two) from helpful folks. Thanks! If anyone else wants/needs a copy, I'll be glad to make it available. Everett Kaser The link seems to be updated recently and now the new home is http://drh.home.dyndns.org/pubs/interface4.pdf ...

Why a S-function block can't find a soucefile.c?
1)I write a s function(xianwei.c) in c language ,then save to the directory of matlab. 2)I create o new model .The Level-2 Mfile S-function is one of them.But The s-function block can't find the soucefile. I input the s-function's name 'xianwei',then point the button 'edit',but can't find the file. Leo Li schrieb: > 1)I write a s function(xianwei.c) in c language ,then save to the > directory of matlab. > 2)I create o new model .The Level-2 Mfile S-function is one of > them.But The s-function block can't find the soucefile. I input the > s-functi...

find a shape descriptor
hello all! i wanna extract shape feature in order to perform my CBIR system can u help me to do that with a robust shape descriptor. thank u very much! ...

How to use cross correlation function. I have two( Exacly same signals from the same source )signals and I want to find out how much one signal resembles the other signal. How can I do that.
Hi &nbsp; I have data for two signals for&nbsp;a &nbsp;time period of one second. Bothe the signals are from the same source and now I want ot use the cross correlation function to test how much one signal resembles the other signal.Can some one help me out in doing this. &nbsp; bye &nbsp; Ankit ...

FindFit
Can anybody help me? I want to try to show my model (function) and my data in the same graph so I can see that my conclusions are correct. data= { {40,0.0624}, {50,42.2.276}, {58,127.718}, {60,216.608}, {70,2040.088}, I used FindFit for Exponential as my model to plot: t200= {Exp200} t200= {Exp300} model=aExp[kt]; fit=FindFit[data,model,{a,k},t] Best regads jj "jj" <yohan2@spray.se> wrote in message news:hgid9p$o1i$1@smc.vnet.net... > Can anybody help me? > I want to try to show my model (function) and my data in the same > graph so I can see...

Where do I find good excercises?
I am rather new at Java and would like to find some excercises that deal with small project where you are supposed to connect a couple of classes and interfaces. I know a little about inheritance, return statements for, while, try-catch statements so if they contain these elements it would be great. The book I use at the moment only uses written codeexamples that you have to copy from the book and then make some small changes. I miss making everything from the ground and I am getting pretty tired of copying all the stuff that would be exciting to come up with on my own. I really need to learn...

Find function names from C
I am parsing a C file and want to find the function names, is this python worthy or is Emacs-Lisp better for this. I have searched for some libraries but coming up null. I just need the function names, no args or anything else. I would probably have to run a regular expression pattern looking for int,void,static, etc and then the enclosing { }. Berlin Brown wrote: > I am parsing a C file and want to find the function names, is this > python worthy or is Emacs-Lisp better for this. I have searched for > some libraries but coming up null. I just need the function names, n...