Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help on fminsearch
Date: Sun, 8 Nov 2009 12:05:19 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 60
Message-ID: <hd6c5v$g56$1@fred.mathworks.com>
References: <09b40b63-dab0-4d44-ae14-e078505de963@s31g2000yqs.googlegroups.com> <bd6f5cbd-b390-436e-b740-2d13064169ef@l13g2000yqb.googlegroups.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257681919 16550 172.30.248.37 (8 Nov 2009 12:05:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 8 Nov 2009 12:05:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:583329


Steven <ytsteven@gmail.com> wrote in message <bd6f5cbd-b390-436e-b740-2d13064169ef@l13g2000yqb.googlegroups.com>...
> On Nov 8, 10:15?pm, "John D'Errico" <woodch...@rochester.rr.com>
> wrote:
> > Steven <ytste...@gmail.com> wrote in message <09b40b63-dab0-4d44-ae14-e078505de...@s31g2000yqs.googlegroups.com>...
> > > Hi, all
> >
> > > I am a newbie and need some help on fminsearch. I worte this function
> > > on cox proportional hazard model, and try to maximise the likelihood
> > > on the coefficient of the covariates.
> >
> > > But the code doesn't work, it only sticks to thei nitial values of the
> > > coefficients, ie. beta = ones(p,1) and won't do the optimisation.
> > > Could anybody please help me on this? Many Thanks!!
> >
> > > function [logL] = myfun(beta)
> >
> > > load mydata
> >
> > > d = size(mydata);
> > > n = d(1,1);
> > > p = d(1,2)-2;
> > > t = mydata(1:n,1);
> > > ind = mydata(1:n,2);
> > > z = mydata(1:n,3:p+2);
> > > beta = ones(p,1);
> >
> > You do recognize that regardless of the value of
> > beta as it is passed in, that this line will overwrite it?
> >
> > John- Hide quoted text -
> >
> > - Show quoted text -
> 
> Hi, John
> 
> Do you mean this line ----> beta = ones(p,1); ?
> 
> But without this line, I always have the error message like "beta is
> undefined" or something...

How are you calling this?

Do you actually have the call to fminsearch
INSIDE the myfun function?

Telling me "or something" gives no useful
information as to the actual error.

Are you trying to run myfun as a script? Are
you using "run" on it?

Do you realize that loading the data file for
EVERY function call here is a terrible way to
waste CPU time? Ok, maybe that was wrong.
It is actually a very GOOD way if your goal is
to waste CPU time. Load the variable ONCE in
your mainline, and then pass it in to myfun
using an anonymous function call.

John