Coder Social home page Coder Social logo

cplm's People

Contributors

actuaryzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cplm's Issues

Trouble with cpglmm

Hi,
Great library; thanks for putting it together. Having an odd problem with running CPGLMM. I'm doing a few thousand regressions in a loop (apply isn't optimal for my use case). I don't expect all of them to converge, and have it set up in a tryCatch loop to handle this. However, I've found that once 1 regression fails, all those following it fail as well, even if when run in isolation they don't. If I start the loop at at different value (ie i=8 instead of i=1), regressions that previously failed do not...Any idea why this would be the case? I'm curious if using cpglmm changes some environmental feature that does not get shifted back when a regression completes?

Image 1 shows what happens if I start the loop at "regression 1," image 2 shows what happens if I start the loop at "regression 2."

screen shot 2017-08-25 at 11 52 00 am

screen shot 2017-08-25 at 11 56 53 am

Any help you can provide would be greatly appreciated.
Thanks,
Braden

Matrix.h - no longer has GET_SLOT in Matrix 1.5-4

See also our e-mail to you, from Jan.24, 2023.
The <Rdefines.h> header has become "semi - deprecated",
and so in the Matrix package we have stopped using. It contains a very simple macro GET_SLOT() which you have been using.

A back compatible change such that {cplm} continues to install fine with the upcoming Matrix 1.5-4 is

1 file changed, 5 insertions(+), 1 deletion(-)
src/common.h | 6 +++++-

modified   src/common.h
@@ -18,7 +18,11 @@
 #include <Rinternals.h>
 #include <Rmath.h>
 #include <R_ext/Lapack.h>        /* for BLAS and Lapack related */
-#include "Matrix.h"		 /* for cholmod functions and S4 structures (GET_SLOT)*/
+#include "Matrix.h"		 /* for cholmod functions and S4 structures */
+#ifndef GET_SLOT
+   // in Rdefines.h (formerly in Matrix.h) :
+#  define GET_SLOT(x, what)	R_do_slot(x, what)
+#endif
 #ifndef FCONE
 # define FCONE
 #endif

`predict` without `newdata` specified has weird outputs

fitted(model) and predict(model, type='response') are supposed to return the same set of values. But it is not the case for the cplm model objects.

library(cplm)

da <- subset(AutoClaim, IN_YY == 1)
da <- transform(da, CLM_AMT = CLM_AMT / 1000)

P1 <- cpglm(CLM_AMT ~ 1, data = da, offset = log(NPOLICY))

# Compare the values of fitted and predicted with type response specified.

all.equal(fitted(P1), predict(P1, type='response'), check.attributes = FALSE)
# Mean relative difference: 0.5924107

# The values are different!
# Plot and see:

plot(fitted(P1))
plot(predict(P1, type='response'))

# But if added the `newdata` argument, it's now same.

all.equal(fitted(P1), predict(P1, newdata=da, type='response'), check.attributes = FALSE)
# TRUE

# Compare to other models, there is no such problem?
# I checked with `glm::glm()`, `MASS::glm.nb()`, and `tweedie()` with `glm::glm()`.

trace = 0 not working

Hello,

Under R 4.1.0, I'm using cplm::cpglm() within a tryCatch.
The control argument is understanding things like max.iter = X, but fails to accepts trace = 0 (at least my understanding is that it should remove any verbose print in the console).

Code below:

fit <- tryCatch(
  expr = {
    cplm::cpglm(
      formula = formula, 
      data = data,
      control = list(trace = 0)
    )
  },
  error = function(cond) {
    # Stuff
  },
  warning = function(cond) {
    # Stuff
  }
)

Console

Call:
cplm::cpglm(formula = formula, data = data, control = list(trace = 0))
Deviance Residuals:
Min 1Q Median 3Q Max
-3.0237 -2.6788 -0.5744 0.3147 5.9825
Estimate Std. Error t value Pr(>|t|)
(Intercept) -9.3936 0.3071 -30.589 <2e-16 ***
Group_A_vs_Control 0.2241 0.4094 0.547 0.586
Group_B_vs_Control 0.1434 0.4179 0.343 0.732
Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1
Estimated dispersion parameter: 3.7397
Estimated index parameter: 1.3619
Residual deviance: 400.3 on 86 degrees of freedom
AIC: 441.87
Number of Fisher Scoring iterations: 5

Any tips on how to suppress the verbose output?

Need S3 methods for `terms`, probably others as well

I had a user ask about emmeans support for cplm objects. I found that the terms method does not work in the namespace of my package. (See also rvlenth/emmeans#116) As explained in an answer on Stack Overflow -- https://stackoverflow.com/questions/56739673/flaky-s4-method-dispatch -- there exists an S3 generic for terms but there is no S3 method for cplm or cpglm objects. The answerer points to documentation recommending that such S3 methods be added, and how to do it. In particular, add and export functions like this:

terms.cplm <- function(x, ...) terms(x, ...)
terms.cpglm <- function(x, ...) terms(x, ...)

To test it, try something like:

m <- cpglm(...)
stats::terms(m)

I think you need to do this for all S4 methods you provide for which there also exists an S3 generic.

In emmeans, I opted to create S4 objects, but use S3 methods exclusively, no S4 ones, for exactly these kinds of reasons.

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.