Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail
From: Steven <ytsteven@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Help on fminsearch
Date: Sun, 8 Nov 2009 02:32:32 -0800 (PST)
Organization: http://groups.google.com
Lines: 35
Message-ID: <09b40b63-dab0-4d44-ae14-e078505de963@s31g2000yqs.googlegroups.com>
NNTP-Posting-Host: 61.88.236.240
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1257676352 10427 127.0.0.1 (8 Nov 2009 10:32:32 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 8 Nov 2009 10:32:32 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: s31g2000yqs.googlegroups.com; posting-host=61.88.236.240; 
	posting-account=8IzR6AoAAADtXVpNmJ2BoypqTzJEOQO_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
	2.0.50727; .NET CLR 1.1.4322; CIBA; .NET CLR 3.0.4506.2152; .NET CLR 
	3.5.30729),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:583313


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);

ebz = exp(z*beta);
L = ones(n,1);

for i = 1:n
    if ind(i,1)== 1
        L(i,1) = ebz(i)/sum(ebz(i:n));
    end
end

logL = -sum(log(L));

[beta] = fminsearch(@myfun,ones(p,1));