Skip to content

Commit

Permalink
change confint behavior when not using convergence
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Feb 18, 2025
1 parent 699e5c3 commit 740a8c1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cyclops.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 5004ae26-a9a8-4fe8-8392-938892bbd248

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Cyclops
Type: Package
Title: Cyclic Coordinate Descent for Logistic, Poisson and Survival Analysis
Version: 3.5.0
Version: 3.5.1
Authors@R: c(
person("Marc A.", "Suchard", email = "[email protected]", role = c("aut","cre")),
person("Martijn J.", "Schuemie", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ develop

1. add Schoenfeld residual output for Cox models
2. check for negative curvature before computing CIs
a. change to "lange"-convergence when needed
3. fix `vcov` when model has an offset

Cyclops v3.5.0
Expand Down
27 changes: 20 additions & 7 deletions R/ModelFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,27 @@ confint.cyclopsFit <- function(object, parm, level = 0.95, #control,

hessianDiagonal <- .cyclopsGetLogLikelihoodHessianDiagonal(object$cyclopsData$cyclopsInterfacePtr,
parm)
if (any(hessianDiagonal > maximumCurvature)) {
warning("Cannot estimate confidence interval for a monotonic log-likelihood function")

prof <- data.frame(covariate = savedParm,
lower = rep(NA, length(parm)),
upper = rep(NA, length(parm)),
evaluations = rep(NA, length(parm)))
} else {
convergenceType <- .cyclopsGetConvergenceType(object$cyclopsData$cyclopsInterfacePtr)
prof <- NULL
if (convergenceType != 1 && any(hessianDiagonal >= maximumCurvature)) {

.cyclopsSetConvergenceType(object$interface, "lange")
newFit <- .cyclopsFitModel(cyclopsData$cyclopsInterfacePtr)
newHessianDiagonal <- .cyclopsGetLogLikelihoodHessianDiagonal(object$cyclopsData$cyclopsInterfacePtr,
parm)

if (any(newHessianDiagonal > 0)) {
warning("Cannot estimate confidence interval for positive-curvature log-likelihood function")

prof <- data.frame(covariate = savedParm,
lower = rep(NA, length(parm)),
upper = rep(NA, length(parm)),
evaluations = rep(NA, length(parm)))
}
}

if (is.null(prof)) {

prof <- .cyclopsProfileModel(object$cyclopsData$cyclopsInterfacePtr, parm,
threads, threshold,
Expand Down
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
.Call(`_Cyclops_cyclopsPredictModel`, inRcppCcdInterface)
}

.cyclopsSetConvergenceType <- function(inRcppCcdInterface, convergenceType) {
invisible(.Call(`_Cyclops_cyclopsSetConvergenceType`, inRcppCcdInterface, convergenceType))
}

.cyclopsGetConvergenceType <- function(inRcppCcdInterface) {
.Call(`_Cyclops_cyclopsGetConvergenceType`, inRcppCcdInterface)
}

.cyclopsSetControl <- function(inRcppCcdInterface, maxIterations, tolerance, convergenceType, useAutoSearch, fold, foldToCompute, lowerLimit, upperLimit, gridSteps, noiseLevel, threads, seed, resetCoefficients, startingVariance, useKKTSwindle, swindleMultipler, selectorType, initialBound, maxBoundCount, algorithm, doItAll, syncCV) {
invisible(.Call(`_Cyclops_cyclopsSetControl`, inRcppCcdInterface, maxIterations, tolerance, convergenceType, useAutoSearch, fold, foldToCompute, lowerLimit, upperLimit, gridSteps, noiseLevel, threads, seed, resetCoefficients, startingVariance, useKKTSwindle, swindleMultipler, selectorType, initialBound, maxBoundCount, algorithm, doItAll, syncCV))
}
Expand Down
19 changes: 19 additions & 0 deletions src/RcppCyclopsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,25 @@ List cyclopsPredictModel(SEXP inRcppCcdInterface) {
return list;
}

// [[Rcpp::export(".cyclopsSetConvergenceType")]]
void cyclopsSetConvergenceType(SEXP inRcppCcdInterface, const std::string& convergenceType) {
using namespace bsccs;
XPtr<RcppCcdInterface> interface(inRcppCcdInterface);
// Convergence control
CCDArguments& args = interface->getArguments();
args.modeFinding.convergenceType = RcppCcdInterface::parseConvergenceType(convergenceType);
}


// [[Rcpp::export(".cyclopsGetConvergenceType")]]
int cyclopsGetConvergenceType(SEXP inRcppCcdInterface) {
using namespace bsccs;
XPtr<RcppCcdInterface> interface(inRcppCcdInterface);
// Convergence control
CCDArguments& args = interface->getArguments();
return args.modeFinding.convergenceType;
}


// [[Rcpp::export(".cyclopsSetControl")]]
void cyclopsSetControl(SEXP inRcppCcdInterface,
Expand Down
24 changes: 24 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// cyclopsSetConvergenceType
void cyclopsSetConvergenceType(SEXP inRcppCcdInterface, const std::string& convergenceType);
RcppExport SEXP _Cyclops_cyclopsSetConvergenceType(SEXP inRcppCcdInterfaceSEXP, SEXP convergenceTypeSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type inRcppCcdInterface(inRcppCcdInterfaceSEXP);
Rcpp::traits::input_parameter< const std::string& >::type convergenceType(convergenceTypeSEXP);
cyclopsSetConvergenceType(inRcppCcdInterface, convergenceType);
return R_NilValue;
END_RCPP
}
// cyclopsGetConvergenceType
int cyclopsGetConvergenceType(SEXP inRcppCcdInterface);
RcppExport SEXP _Cyclops_cyclopsGetConvergenceType(SEXP inRcppCcdInterfaceSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type inRcppCcdInterface(inRcppCcdInterfaceSEXP);
rcpp_result_gen = Rcpp::wrap(cyclopsGetConvergenceType(inRcppCcdInterface));
return rcpp_result_gen;
END_RCPP
}
// cyclopsSetControl
void cyclopsSetControl(SEXP inRcppCcdInterface, int maxIterations, double tolerance, const std::string& convergenceType, bool useAutoSearch, int fold, int foldToCompute, double lowerLimit, double upperLimit, int gridSteps, const std::string& noiseLevel, int threads, int seed, bool resetCoefficients, double startingVariance, bool useKKTSwindle, int swindleMultipler, const std::string& selectorType, double initialBound, int maxBoundCount, const std::string& algorithm, bool doItAll, bool syncCV);
RcppExport SEXP _Cyclops_cyclopsSetControl(SEXP inRcppCcdInterfaceSEXP, SEXP maxIterationsSEXP, SEXP toleranceSEXP, SEXP convergenceTypeSEXP, SEXP useAutoSearchSEXP, SEXP foldSEXP, SEXP foldToComputeSEXP, SEXP lowerLimitSEXP, SEXP upperLimitSEXP, SEXP gridStepsSEXP, SEXP noiseLevelSEXP, SEXP threadsSEXP, SEXP seedSEXP, SEXP resetCoefficientsSEXP, SEXP startingVarianceSEXP, SEXP useKKTSwindleSEXP, SEXP swindleMultiplerSEXP, SEXP selectorTypeSEXP, SEXP initialBoundSEXP, SEXP maxBoundCountSEXP, SEXP algorithmSEXP, SEXP doItAllSEXP, SEXP syncCVSEXP) {
Expand Down Expand Up @@ -908,6 +930,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_Cyclops_cyclopsGetProfileLikelihood", (DL_FUNC) &_Cyclops_cyclopsGetProfileLikelihood, 5},
{"_Cyclops_cyclopsProfileModel", (DL_FUNC) &_Cyclops_cyclopsProfileModel, 6},
{"_Cyclops_cyclopsPredictModel", (DL_FUNC) &_Cyclops_cyclopsPredictModel, 1},
{"_Cyclops_cyclopsSetConvergenceType", (DL_FUNC) &_Cyclops_cyclopsSetConvergenceType, 2},
{"_Cyclops_cyclopsGetConvergenceType", (DL_FUNC) &_Cyclops_cyclopsGetConvergenceType, 1},
{"_Cyclops_cyclopsSetControl", (DL_FUNC) &_Cyclops_cyclopsSetControl, 23},
{"_Cyclops_cyclopsRunCrossValidationl", (DL_FUNC) &_Cyclops_cyclopsRunCrossValidationl, 1},
{"_Cyclops_cyclopsFitModel", (DL_FUNC) &_Cyclops_cyclopsFitModel, 1},
Expand Down

0 comments on commit 740a8c1

Please sign in to comment.