[R] model selection with spg and AIC (or, convert list to fitted model object)

Ravi Varadhan ravi.varadhan at jhu.edu
Thu Oct 11 23:36:40 CEST 2012


Adam,

See the attached R code that solves your problem and beyond.  One important issue is that you are enforcing constraints only indirectly.  You need to make sure that P1, P2, and P3 (which are functions of original parameters and time) are all between 0 and 1.  It is not enough to impose constraints on original parameters p1, p2, mu1 and mu2.

I also show you how to do a likelihood ratio test with the results from spg.  You can also do the same for nlminb or Rvmmin.

Finally, I also show you how to use optimx to compare different algorithms. This shows you that in addition to spg, you also get very good results (as seen from objective function values and KKT conditions) with a number of other algorithms (e.g., Rvmmin, nlminb), many of which are much faster than spg.

This example illustrates the utility of optimx().  I am always surprised as to why more R users doing optimization are not using optimx.  This is a very powerful for benchmarking unconstrained and box-constrained optimization problems.  It deserves to be used widely, in my biased, but correct, opinion.

Ravi

Ravi Varadhan, Ph.D.
Assistant Professor
The Center on Aging and Health
Division of Geriatric Medicine & Gerontology
Johns Hopkins University
rvaradhan at jhmi.edu<mailto:rvaradhan at jhmi.edu>
410-502-2619



More information about the R-help mailing list