Hi,
I know nothing about neither your model nor the Skellam distribution. I
will assume that it is a sensible model and that the parameters are
identifiable from the data.
Here is a toy example showing how to impose equality constraints:
# To maximize x1 + x2, subject to x1^2 + x2^2 = 1
#
f <- function(x, lambda) x[1] + x[2] - lambda * (x[1]^2 + x[2]^2 - 1)^2 #
this is the augmented Lagrangian
eps <- Inf
tol <- 1.e-05
p0 <- c(1, 1)
lambda <- 0.1 # starting value for penalty parameter, this would depend on
the scale of the constraint function
while (eps > tol) {
ans <- optim(fn=f, par=p0, lambda=lambda, method="BFGS",
control=list(fnscale=-1)) # maximizing the augmented Lagrangian
par <- ans$par
eps <- max(abs(p0 - par))
p0 <- par
lambda <- 10 * lambda # we increase the penalty parameter until parameters
do not change
}
ans
In your problem, you can do as follows:
f <- function(par, data, lambda1, lambda2) loglik(par, data) + lambda1 *
(sum(Ai))^2 + lambda2 * (sum(Di))^2
where you allow 2 penalty parameters. You would then increase both by a
factor of 10 in each step until convergence. You would use different
starting values for lamda1 and lambda2, if the scales of the 2 constraints
are very different. If not, you use a single lambda.
Hope this helps,
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan@jhmi.edu
Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml
----------------------------------------------------------------------------
--------
_____
From: Iason Christodoulou [mailto:c_iasonas@hotmail.com]
Sent: Thursday, July 02, 2009 2:58 PM
To: rvaradhan@jhmi.edu
Subject: RE: [R] constrained optimisation in R.
$B&3(Bhe actual problem is:
Log ($B&K(B1i) = $B&L(B + $B&'(B + A$B&'(BTi +
D$B&!(BTi ,
Log($B&K(B2i ) = $B&L(B + AATi + DHTi,
Where $B&L(B is a constant parameter, H is the home effect, Ak and Dk are
the
$B!H(Bnet$B!I(B attacking and defending parameters of team k after removing
correlation and HTi and ATi are the home and away team competing each other
in game i.
We need to impose the constraints
$B-t(BAk=0 and $B-t(BDk=0
I want to solve it with maximum likelihood method
(the distribution is skellam distribution)
Thank you very much for your time.
> From: RVaradhan@jhmi.edu
> To: c_iasonas@hotmail.com; r-help@r-project.org
> Subject: RE: [R] constrained optimisation in R.
> Date: Thu, 2 Jul 2009 13:15:27 -0400
>
> Please tell us about the actual problem that you are trying to solve,
> because the "answer" would very much depend on that.
>
> Are your constraints really sum(par) = 0? If so, you can just eliminate
one> of the parameters and solve the optimization problems with (p-1)
parameters.>
> If you have other constraints on the parameters such that par[i] > 0,
then
> you can use any one of the optimization functions that allow for
> box-constraints (e.g. optim() with method="L-BFGS-B", nlminb(),
spg() in
> "BB" package).
>
> If you have convex inequality constraints, you can use constrOptim(). If
> you have nonlinear inequalities you may try Rdonlp2, or you can use a
> function that I have written that extends constrOptim() to handle
non-linear> inequalities.
>
> As you can see, the answer depends upon what type of constraints you
really> have.
>
> Ravi.
>
>
>
----------------------------------------------------------------------------> -------
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: rvaradhan@jhmi.edu
>
> Webpage:
>
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h> tml
>
>
>
>
----------------------------------------------------------------------------> --------
>
>
> -----Original Message-----
> From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org]
On> Behalf Of Iason Christodoulou
> Sent: Thursday, July 02, 2009 11:56 AM
> To: r-help@r-project.org
> Subject: [R] constrained optimisation in R.
>
>
> i want to estimate parameters with maximum likelihood method with
contraints> (contant numbers).
> for example
> sum(Ai)=0 and sum(Bi)=0
> i have done it without the constraints but i realised that i have to use
the> contraints.
>
>
> Without constraints(just a part-not complete):
>
> skellamreg_LL=function(parameters,z,design)
> {
> n=length(z);
> mu=parameters[1];
> H=parameters[2];
> Apar=parameters[3:10];
> Dpar=parameters[11:18];
>
> res=optim(par,skellamreg_LL,method="Nelder-Mead", hessian =
FALSE,
> control=list(trace=1000,maxit=100000),z=z,design=x,)
>
> _________________________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
_____
check out the rest of the Windows Live(tm). More than mail-Windows Live(tm)
goes way beyond your inbox. More than messages
<http://www.microsoft.com/windows/windowslive/>
[[alternative HTML version deleted]]