[R] Weighted Optimization
Jan van der Laan
rhelp at eoos.dds.nl
Thu Jan 13 13:57:01 CET 2011
You will have to modify your likelihood in such a way that it also
includes the weights. If your likelihood has the following form: l =
sum(log p_i) you could for example add the weights to the likelihood:
lw = sum(w_i * log p_i) (although I am not sure that this is the
correct way to add the weights in your case)
Therefore, you will have to change your functions negllh and se to
also accepts the weights as input parameters:
negllh <- function([PARAMETERS YOU HAVE ALREADY HERE], weights, ...) }{ ... }
se <- function([PARAMETERS YOU HAVE ALREADY HERE], weights, ...) { ... }
You can then call optim adding weights as additional parameter which
gets passed on to negllh and se:
gh.fit = try(optim(vega, negllh,hessian = se,pdf = gh.pdf,
tmp.data = data, transf = transform, const.pars = vars[!opt.pars],
silent = silent, par.names = names(vars), weights = w, ...))
HTH,
Jan
Quoting JASON SCALLY <j.scally at student.qut.edu.au>:
> Hi All,
>
> I am trying to code an R script which gives me the time varying
> parameters of the NIG and GH distributions. Further, becasue I think
> these these time varying parameters should be more responsive to
> more recent observations, I would like to include a weighted
> likelihood estimation proceedure where the observations have an
> exponentially decaying weighting rather than the equal weighting
> implied by a standard MLE approach.
>
> The optimization function which leads to my parameter estimates is given by;
>
> gh.fit = try(optim(vega, negllh,hessian = se,pdf = gh.pdf,
> tmp.data = data, transf = transform, const.pars = vars[!opt.pars],
> silent = silent, par.names = names(vars), ...))
>
> param.est = gh.fit$par
>
> In the above, vega are the parameters to estimate and pdf is the GH
> pdf. This seems to work well for the case where observations are
> equally weighted. However, I'm stuck on how to include a weighted
> vector (w_i) to turn this problem into a weighted ML optimization.
>
> Would you please be able to suggest a function or change in code
> which may allow me to do this?
>
> Thank you in advance for your time.
>
> Jason
> ______________________________________________
> 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.
>
More information about the R-help
mailing list