Giter Club home page Giter Club logo

Comments (4)

boyiguo1 avatar boyiguo1 commented on September 14, 2024

The root cause of the problem is the artificial offset induced when fitting group-updated models, which will trigger the wrong data pull with in cv.bh at line 136.

BhGLM/R/cv.bh.r

Line 136 in ac76cec

if (!is.null(object$offset)) {

To examine, we follow the previous example code and show group-updated models introduce artificial offset with the follows

is.null(mdl_joint$offset) #TRUE
#> Error in eval(expr, envir, enclos): object 'mdl_joint' not found
is.null(mdl_group$offset) #FALSE
#> Error in eval(expr, envir, enclos): object 'mdl_group' not found

Created on 2022-01-03 by the reprex package (v2.0.1)

from bhglm.

boyiguo1 avatar boyiguo1 commented on September 14, 2024

Suggested solution:
We can re-assign the correct offset after fitting coxph internally. For example, we can add a line of code

fit$offset<- offset

at bcoxph.r line 436

Technically, there is a correction of offset implemented in bcoxph with on Line 266

if (any(offset != 0)) fit$offset <- offset

However, it doesn't work when offsets are 0.

from bhglm.

boyiguo1 avatar boyiguo1 commented on September 14, 2024

This bug does not have an impact on prediction via predict function. Specifically, predict.coxph in the survival package, check attributes to decide if offset should be included in prediction,

 has.offset <- !is.null(attr(Terms, 'offset'))
 if (is.null(object[['x']]) || has.weights || has.offset || # the remaining code is omited

In our case, the Terms are corrected via

fit$terms <- Terms

To demonstrate there is no impact on prediction, here is the example (following previous code)

is.null(attr(mdl_joint, "offset")) #TRUE
is.null(attr(mdl_group, "offset")) #TRUE

is.null(attr(mdl_joint$terms, "offset")) #TRUE
is.null(attr(mdl_group$terms, "offset")) #TRUE


## Examination of prediction
cor(
  data.frame(
  joint_mdl = predict(mdl_joint, type="expected"),
  group_mdl = predict(mdl_group, type="expected")
  )
) # Correlation is 0.99

from bhglm.

boyiguo1 avatar boyiguo1 commented on September 14, 2024

The problem resolved via f0f80cc

from bhglm.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.