Git Product home page Git Product logo

mstweedie's Introduction

MSTweedie

Extending the HDtweedie package to multi-source data, this package implements multi-source sparse Tweedie modelling. Given non-negative data with excess zeroes (typically insurance claim data), the algorithm fits the Tweedie distribution while penalizing the coefficient. Flexible regularization is achieved by an adjustable penalty factor that can balance between-feature sparsity and between-sources sparsity within features.

Installation

You can install the R package directly from GitHub using the devtools package function install_github using the following command :

devtools::install_github("fontaine618/MSTweedie")

Examples

Load package via

library(MSTweedie)

AutoClaim dataset

The package contains a dataset of auto insurance claims, AutoClaim, which is a preprocessed version of the dataset of the same name from the cplm package.

data(AutoClaim)

The manual contains information on the dataset; you can display the first rows of it by

head(AutoClaim)

The sources are defined by the REVOLKED variable (i.e. whether or not the policyholder had its license revoked in the past.) Here we classify the data by sources and by whether there was a claim or not.

table(AutoClaim$REVOLKED, AutoClaim$CLM_AMT5 > 0)

Fit the model and analyse

We fit the penalized Tweedie model with L1/Linf-regularization. The response is the variable CLM_AMT5, the claim amount.

fit <- MSTweedie(x = AutoClaim, y=1, source=4, reg='Linf')

We can extract the estimated coefficients at, say, the 34th regularization parameter value.

coef.MSTweedie(fit, s=3)

We can predict the response using the coefficients from the 34th regularization parameter value.

head(predict.MSTweedie(fit, s=34L)[[1]])

Print the regularization parameter value with the number of variables in the model along the regularization path.

print.MSTweedie(fit)

We can plot the regularization pth of the norm of the coefficients

plot.MSTweedie(fit, type.coef='norm')

or the coefficients themselves in each source.

par(mfrow=c(2,1))
plot.MSTweedie(fit, type.coef='coef')

We can check the convergence of the algorithm through the KKT conditions.

par(mfrow=c(2,1))
kkt.check(fit)

The deviance of the model can be computed (at the 34th regularization paramter for example) by

deviance.MSTweedie(y= fit$y, mu = predict.MSTweedie(fit, s=34L))

Cross-validation

We can perform 10-folds cross-validation.

cv<-cv.MSTweedie(x = AutoClaim, y=1, source=4, reg='Linf')

Cross-validation is used to perform model selection. We can extract the estimated coefficients at le selected value of the regularization paramter according to the one-standard-error rule.

coef.cv.MSTweedie(cv)

Also, we can use the selected coefficients to predict the responses.

head(predict.cv.MSTweedie(cv)[[1]])

Finally, we can plot the CV model deviance with its standard error along the regularization path.

plot.cv.MSTweedie(cv)

Built with

This R package was built using the devtools package. The optimization routine is written in FORTRAN90.

Author

Simon Fontaine

License

GPL-2

Acknowledgments

The code for the R end of the developpment was based in part on the HDtweedie package and the glmnet package. The FORTRAN90 subroutine was inspired from that of the HDtweedie pakckage.

mstweedie's People

Contributors

fontaine618 avatar

Watchers

 avatar  avatar  avatar

mstweedie's Issues

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.