Skip to content

Commit

Permalink
Merge pull request #51 from pletschm/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pletschm authored Oct 26, 2023
2 parents ad495f6 + 4d9b5d2 commit 919a1eb
Show file tree
Hide file tree
Showing 65 changed files with 568 additions and 502 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
^README\.Rmd$
^cran-comments\.md$
^prepare_submission\.R$
^aldvmm_tracker\.txt$
^\.travis\.yml$
^\.github$
^codecov\.yml$
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: aldvmm
Type: Package
Title: Adjusted Limited Dependent Variable Mixture Models
Version: 0.8.7
Version: 0.8.8
Authors@R: c(person(given = "Mark", family = "Pletscher", email = "pletscher.mark@gmail.com",
role = c("aut", "cre", "cph")),
person(given = "Achim", family = "Zeileis", email = "Achim.Zeileis@R-project.org",
role = c("ctb"), comment = c(ORCID = "0000-0003-0918-3766")))
Date: 2023-07-08
Date: 2023-10-26
Depends: R (>= 3.5.0)
Description: The goal of the package 'aldvmm' is to fit adjusted limited
dependent variable mixture models of health state utilities. Adjusted
Expand All @@ -21,7 +21,7 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Imports: numDeriv, stats, checkmate, optimr, Formula, sandwich, lmtest
Imports: numDeriv, stats, checkmate, optimx, Formula, sandwich, lmtest
URL: https://github.com/pletschm/aldvmm/
BugReports: https://github.com/pletschm/aldvmm/issues
Suggests:
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export(vcov.aldvmm)
import(Formula)
import(checkmate)
import(numDeriv)
import(optimr)
import(optimx)
import(stats)
importFrom(lmtest,coefci)
importFrom(lmtest,coeftest)
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
* The package "aldvmm" now uses analytical gradients instead of numerical approximations during optimization and in methods used for estimators from the "sandwich" package.
* New methods for generic functions stats::formula(), stats::residuals() and stats::update(). Objects of class "aldvmm" can now be supplied to sandwich::sandwich(), sandwich::vcovCL(), sandwich::vcovPL(), sandwich::vcovHAC() and sandwich::vcovBS(). sandwich::vcovBS() allows re-estimating the covariance matrix using bootstrapping with and without clustering.
* Objects of class "aldvmm" now include predicted probabilities of component membership for all observations in the estimation data.
* New html vignette.
* New html vignette.

# aldvmm 0.8.8
* The optimizer package was changed from "optimr" to "optimx". The functionality remains identical.
39 changes: 21 additions & 18 deletions R/aldvmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' @import numDeriv
#' @import stats
#' @import checkmate
#' @import optimr
#' @import optimx
#' @import Formula
#' @importFrom sandwich estfun
#' @importFrom lmtest coeftest coefci
Expand Down Expand Up @@ -73,19 +73,19 @@ NULL
#' \code{"zero"}, \code{"random"}, \code{"constant"} and \code{"sann"}. The
#' default value is \code{"zero"}.
#' @param optim.method an optional character value of one of the following
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}
#' methods: \code{"Nelder-Mead"}, \code{"BFGS"}, \code{"CG"},
#' \code{"L-BFGS-B"}, \code{"nlminb"}, \code{"Rcgmin"}, \code{"Rvmmin"} and
#' \code{"hjn"}. The default method is \code{"BFGS"}. The method
#' \code{"L-BFGS-B"} is used when lower and/or upper constraints are set
#' using \code{'init.lo'} and \code{'init.hi'}. The method \code{"nlm"}
#' cannot be used in the \code{'aldvmm'} package.
#' @param optim.control an optional list of
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}
#' control parameters.
#' @param optim.grad an optional logical value indicating if an analytical
#' gradient should be used in
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}
#' methods that can use this information. The default value is \code{TRUE}.
#' If \code{'optim.grad'} is set to \code{FALSE}, a finite difference
#' approximation is used.
Expand Down Expand Up @@ -144,7 +144,7 @@ NULL
#' membership.
#'
#' \ifelse{html}{\code{\link[aldvmm]{aldvmm}}}{ \code{aldvmm()}} uses
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}} for
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}} for
#' maximum likelihood estimation of model parameters. The argument
#' \code{'optim.method'} accepts the following methods: \code{"Nelder-Mead"},
#' \code{"BFGS"}, \code{"CG"}, \code{"L-BFGS-B"}, \code{"nlminb"},
Expand All @@ -153,10 +153,10 @@ NULL
#' \ifelse{html}{\code{\link[aldvmm]{aldvmm}}}{ \code{aldvmm()}} because it
#' requires a different implementation of the likelihood function. The
#' argument \code{'optim.control'} accepts a list of
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}
#' control parameters. If \code{'optim.grad'} is set to \code{TRUE} the
#' function
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}} uses
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}} uses
#' analytical gradients during the optimization procedure for all methods
#' that allow for this approach. If \code{'optim.grad'} is set to
#' \code{FALSE} or a method cannot use gradients, a finite difference
Expand All @@ -177,14 +177,17 @@ NULL
#' are supplied in \code{'init.est'}, the argument \code{'init.method'} is
#' ignored.
#'
#' By default, \ifelse{html}{\code{\link[aldvmm]{aldvmm}}}{ \code{aldvmm()}}
#' By default, \ifelse{html}{\code{\link[aldvmm]{aldvmm}}}{\code{aldvmm()}}
#' performs unconstrained optimization with upper and lower limits at
#' \code{-Inf} and \code{Inf}. When user-defined lower and upper limits are
#' supplied to \code{'init.lo'} and/or \code{'init-hi'}, these default limits
#' supplied to \code{'init.lo'} and/or \code{'init.hi'}, these default limits
#' are replaced with the user-specified values, and the method
#' \code{"L-BFGS-B"} is used for box-constrained optimization instead of the
#' user defined \code{'optim.method'}. It is possible to only set either
#' maximum or minimum limits.
#' maximum or minimum limits. When initial values supplied to
#' \code{'init.est'} or from default methods lie outside the limits, the
#' in-feasible values will be set to the limits using the function
#' \ifelse{html}{\code{\link[optimx]{bmchk}}}{\code{optimx::bmchk()}}.
#'
#' The function \code{aldvmm()} returns the negative log-likelihood, Akaike
#' information criterion and Bayesian information criterion. Smaller values
Expand Down Expand Up @@ -293,7 +296,7 @@ NULL
#' (\code{"delta"}).} } }
#'
#' \item{\code{optim.method}}{a character value of the used
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}
#' method.}
#' \item{\code{level}}{a numeric value of the confidence level used for
#' reporting.}
Expand Down Expand Up @@ -490,7 +493,7 @@ aldvmm <- function(formula,
lcpar = lcpar,
optim.method = optim.method)

if (!is.finite(test)) {
if (!is.finite(test) | (optim.method == "L-BFGS-B" & test >= 1e+20)) {
stop("Starting values are not feasible.")
}

Expand All @@ -499,19 +502,19 @@ aldvmm <- function(formula,
# Fit model
#----------

fit <- optimr::optimr(fn = aldvmm.ll,
par = init[["est"]],
fit <- optimx::optimr(par = init[["est"]],
fn = aldvmm.ll,
X = mm,
y = y,
lower = init[["lo"]],
upper = init[["hi"]],
psi = psi,
dist = dist,
ncmp = ncmp,
dist = dist,
lcoef = lcoef,
lcmp = lcmp,
lcpar = lcpar,
lcmp = lcmp,
optim.method = optim.method,
lower = init[["lo"]],
upper = init[["hi"]],
method = optim.method,
gr = grd,
hessian = FALSE,
Expand Down
22 changes: 18 additions & 4 deletions R/aldvmm.init.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' creates initial values for the minimization of the negative log-likelihood
#' returned by
#' \ifelse{html}{\code{\link[aldvmm]{aldvmm.ll}}}{\code{aldvmm.ll()}} using
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}}.
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}}.
#'
#' @inheritParams aldvmm
#' @inheritParams aldvmm.ll
Expand All @@ -29,7 +29,10 @@
#' are replaced with the user-specified values, and the method
#' \code{"L-BFGS-B"} is used for box-constrained optimization instead of the
#' user defined \code{'optim.method'}. It is possible to only set either
#' maximum or minimum limits.
#' maximum or minimum limits. When initial values supplied to
#' \code{'init.est'} or from default methods lie outside the limits, the
#' in-feasible values will be set to the limits using the function
#' \ifelse{html}{\code{\link[optimx]{bmchk}}}{\code{optimx::bmchk()}}.
#'
#' @return
#' \ifelse{html}{\code{\link[aldvmm]{aldvmm.init}}}{\code{aldvmm.init()}}
Expand Down Expand Up @@ -140,7 +143,7 @@ aldvmm.init <- function(X,
dimnames = list(NULL, "(Intercept)")) )
names(X0) <- lcoef[1]
}

# Initial values of constant-only model
tmp <- list()
for (i in names(zero)) {
Expand All @@ -161,7 +164,7 @@ aldvmm.init <- function(X,
}

# Fit model
fit <- optimr::optimr(method = optim.method,
fit <- optimx::optimr(method = optim.method,
fn = aldvmm.ll,
par = tmp,
X = X0,
Expand Down Expand Up @@ -270,6 +273,17 @@ aldvmm.init <- function(X,
}
names(init[["hi"]]) <- names(init[["est"]])

# Set initial values outside constraint to bounds
#------------------------------------------------

bc <- optimx::bmchk(init[["est"]],
lower = init[["lo"]],
upper = init[["hi"]])

if(bc[["parchanged"]] == TRUE) {
init[["est"]] <- bc[["bvec"]]
}

return(init)

}
2 changes: 1 addition & 1 deletion R/aldvmm.ll.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' distributions) enter the likelihood function as log-transformed values.
#'
#' As the "L-BFGS-B" and "Rcgmin" methods in
#' \ifelse{html}{\code{\link[optimr]{optimr}}}{\code{optimr::optimr()}} fail
#' \ifelse{html}{\code{\link[optimx]{optimr}}}{\code{optimx::optimr()}} fail
#' if they encounter infinite values, the log-likelihood function takes the
#' value -1e+20 if it is infinite during these algorithms.
#'
Expand Down
14 changes: 14 additions & 0 deletions aldvmm_tracker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Planned
- test.aldvmm.R: check the models really behave in the expected manner wrt messages, warnings and errors.
- Check number of iterations is returned by optimr/optimx
- Check all optimx::optimr() return values collected in output object.

Completed
- Email John C. Nash: Unused parameter error, why only starting value within limits, anyworkaround?
- aldvmm.init(): Add tests for initial values lying within bounds.
- Update detailed documentation of use of bounds and the behavior of aldvmm
- aldvmm(): modify feasibility test of initial values to stop when ll is larger than 1e+20 for optim.method L-BFGS-B
- Document rule of initial values outside limits in aldvmm.init(). Also mention optimx::bmchk() explicitely.
- Add test of aldvmm.init() for initial values outside limits behavior.

Discarded
5 changes: 1 addition & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
This is a re-submission.

It includes the following updates.
* The package "aldvmm" now uses analytical gradients instead of numerical approximations.
* New methods for generic functions stats::formula(), stats::residuals() and stats::update().
* Objects of class "aldvmm" now include predicted probabilities of component membership for all observations in the estimation data.
* New html vignette.
* The optimizer package was changed from "optimr" to "optimx". The functionality remains identical.

Maintainer: 'Mark Pletscher <pletscher.mark@gmail.com>'

Expand Down
23 changes: 13 additions & 10 deletions man/aldvmm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/aldvmm.check.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aldvmm.cv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aldvmm.gr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 919a1eb

Please sign in to comment.