Package CompGLM. April 29, 2018

Similar documents
Package coga. May 8, 2018

Package inca. February 13, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package validara. October 19, 2017

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package vinereg. August 10, 2018

Package ECctmc. May 1, 2018

Package spark. July 21, 2017

Package fastdummies. January 8, 2018

Package PrivateLR. March 20, 2018

Package TVsMiss. April 5, 2018

Package palmtree. January 16, 2018

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package farver. November 20, 2018

Package robustreg. R topics documented: April 27, Version Date Title Robust Regression Functions

Package strat. November 23, 2016

Package sfc. August 29, 2016

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package crossword.r. January 19, 2018

Package ihs. February 25, 2015

Package datasets.load

Package truncreg. R topics documented: August 3, 2016

Package geogrid. August 19, 2018

Package ramcmc. May 29, 2018

Package milr. June 8, 2017

Package glmmml. R topics documented: March 25, Encoding UTF-8 Version Date Title Generalized Linear Models with Clustering

Package canvasxpress

Package embed. November 19, 2018

Package assortnet. January 18, 2016

Package clipr. June 23, 2018

Package attrcusum. December 28, 2016

Package libstabler. June 1, 2017

Package MTLR. March 9, 2019

Package fitur. March 11, 2018

Package gppm. July 5, 2018

Package kirby21.base

Package wrswor. R topics documented: February 2, Type Package

Package RAMP. May 25, 2017

Package robets. March 6, Type Package

Package sfa. R topics documented: February 20, 2015

Package queuecomputer

Package CMPControl. February 19, 2015

Package semver. January 6, 2017

Package nmslibr. April 14, 2018

Package elmnnrcpp. July 21, 2018

Package PUlasso. April 7, 2018

Package rvinecopulib

Package sessioninfo. June 21, 2017

Package intcensroc. May 2, 2018

Package iccbeta. January 28, 2019

Package understandbpmn

Package ibm. August 29, 2016

Package reval. May 26, 2015

Package sankey. R topics documented: October 22, 2017

Package RcppProgress

Package messaging. May 27, 2018

Package RaPKod. February 5, 2018

Package FSelectorRcpp

Package TANDEM. R topics documented: June 15, Type Package

Package glmnetutils. August 1, 2017

Package ompr. November 18, 2017

Package Rtsne. April 14, 2017

Package CVR. March 22, 2017

Package bayescl. April 14, 2017

Package githubinstall

Package colf. October 9, 2017

Package mvprobit. November 2, 2015

Package citools. October 20, 2018

Package raker. October 10, 2017

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package rngtools. May 15, 2018

Package fasttextr. May 12, 2017

Package ordinalnet. December 5, 2017

Package pkgbuild. October 16, 2018

Package CatEncoders. March 8, 2017

Package kdtools. April 26, 2018

Package jstree. October 24, 2017

Package tidyselect. October 11, 2018

Package sqlscore. April 29, 2018

Package intccr. September 12, 2017

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package projector. February 27, 2018

Package svalues. July 15, 2018

Package robustgam. February 20, 2015

Package psda. September 5, 2017

Package repec. August 31, 2018

Package lvec. May 24, 2018

Package GauPro. September 11, 2017

Package gifti. February 1, 2018

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package hyphenatr. August 29, 2016

Package vip. June 15, 2018

Package purrrlyr. R topics documented: May 13, Title Tools at the Intersection of 'purrr' and 'dplyr' Version 0.0.2

Package regexselect. R topics documented: September 22, Version Date Title Regular Expressions in 'shiny' Select Lists

Package BayesCR. September 11, 2017

Package statip. July 31, 2018

Package nonlinearicp

Package reconstructr

Package bife. May 7, 2017

Package StVAR. February 11, 2017

Transcription:

Type Package Package CompGLM April 29, 2018 Title Conway-Maxwell-Poisson GLM and Distribution Functions Version 2.0 Date 2018-04-29 Author Jeffrey Pollock Maintainer URL https://github.com/jeffpollock9/compglm BugReports https://github.com/jeffpollock9/compglm/issues A function (which uses a similar interface to the `glm' function) for the fitting of a Conway-Maxwell-Poisson GLM. There are also various methods for analysis of the model fit. The package also contains functions for the Conway-Maxwell-Poisson distribution in a similar interface to functions `dpois', `ppois' and `rpois'. The functions are generally quick, since the workhorse functions are written in C++ (thanks to the Rcpp package). License GPL (>= 2) Imports Rcpp, stats LinkingTo Rcpp Suggests testthat, devtools, roxygen2, covr, lintr NeedsCompilation yes Encoding UTF-8 RoxygenNote 6.0.1 Repository CRAN Date/Publication 2018-04-29 12:45:36 UTC R topics documented: dcomp............................................ 2 glm.comp.......................................... 3 pcomp............................................ 4 rcomp............................................ 5 1

2 dcomp Index 7 dcomp Conway-Maxwell-Poisson Probability Density Function The PDF of the Conway-Maxwell-Poisson distribution with parameters lam and nu at point y. dcomp(y, lam, nu, sumto = 100L, logp = FALSE) y an integer vector where the density is to be calculated. If the input is not an integer, it will be coerced to be an integer. lam a double vector of the parameter λ. nu a double vector of the parameter ν. sumto an integer for the summation term in the density (default 100). logp a boolean for if the log of the density should be given (default FALSE). The Conway-Maxwell-Poisson distribution has density: P (y) = λ y (y!) ν Z(λ, ν) for y = 0, 1, 2,..., and: Z(λ, ν) = j=0 λ j (j!) ν where the summation is approximated by summing from j = 0 to sumto. The value of the PDF (or log PDF if logp = TRUE). Input vectors are recycled to be same length.

glm.comp 3 dcomp(-5:5, 2.5, 1) dcomp(2, 2.5, 1.5) require(graphics) require(stats) comp <- dcomp(0:10, 2.5, 0.9) poisson <- dpois(0:10, 2.5) barplot(rbind(comp, poisson), beside = TRUE, names= 0:10, legend.text = TRUE) glm.comp Conway-Maxwell Poisson GLM Fitting Function A function in similar format to glm which provides a linear form regressing on the parameters lambda and mu. glm.comp(lamformula, nuformula = NULL, data, lamstart = NULL, nustart = NULL, sumto = 100L, method = "BFGS",...) lamformula nuformula data lamstart nustart an object of class formula which determines the form of regression for the model parameter λ. An offset can also be added in the formula. an object of class formula which determines the form of regression for the model parameter ν. The default value is NULL meaning the formula is intercept only. An offset can also be added in the formula. an optional data.frame containing the variables in the model. If not found in data, the variables are taken from environment(lamformula). optional vector of starting values for the coefficients of the λ regression. optional vector of starting values for the coefficients of the ν regression. sumto an integer for the summation term in the density (default 100). method optimisation method passed to optim (default "BFGS").... further arguments to be passed to optim. A log link is used for regression of the model parameters λ and ν, that is: log(λ) = βx log(ν) = ζy

4 pcomp where: β is the vector of coefficients for the parameter λ, ζ is the vector of coefficients for the parameter ν, X is the model matrix for the parameter λ, and Y is the model matrix for the parameter ν. The parameter vectors are calculated via maximum likelihood using the general optimisation function optim. A Poisson model will be fit using glm.fit and (unless starting values are supplied) the coefficients will be used as starting values for the parameter vector β. Several S3 functions have been implemented for model analysis print, coef, extractaic, loglik, predict, and summary, An object of class Comp which is a list with all the components needed for the relevant S3 class methods. References A Flexible Regression Model for Count Data, by Sellers & Shmueli, http://papers.ssrn.com/ sol3/papers.cfm?abstract_id=1127359 set.seed(1) n <- 5000 x1 <- rnorm(n, -1.0, 0.5) x2 <- rnorm(n, 1.0, 0.7) x3 <- rnorm(n, 2.0, 0.4) y <- rpois(n, exp(-0.5 + 0.3 * x1 + 0.8 * x2 + 0.2 * x3)) data <- data.frame(y, x1, x2, x3) model <- glm.comp(y ~., data = data) print(model) summary(model) coef(model) head(predict(model)) AIC(model) pcomp Conway-Maxwell-Poisson Cumulative Density Function The CDF of the Conway-Maxwell-Poisson distribution with parameters lam and nu at point q. pcomp(q, lam, nu, sumto = 100L, lowertail = TRUE, logp = FALSE)

rcomp 5 q an integer vector where the CDF is to be calculated. If the input is not an integer, it will be coerced to be an integer. lam a double vector of the parameter λ. nu a double vector of the parameter ν. sumto an integer for the summation term in the density (default 100) lowertail logp See dcomp for details of the PDF. a boolean for if P(Y<=q) should be returned (default TRUE), otherwise, P(Y>q) is returned. a boolean for if the log of the probability should be given (default FALSE) The value of the CDF (or 1-CDF if lowertail = FALSE) or log of this value if logp = TRUE. Input vectors are recycled to be same length. pcomp(1:10, 1.5, 1.2) rcomp Conway-Maxwell-Poisson Random Sample Provides a size n sample from the Conway-Maxwell-Poisson distribution with parameters lam and nu. Sampling is done via a simple multinomial approach. rcomp(n, lam, nu, sumto = 100L) n an integer of the number of random samples to be taken. lam a double of the parameter λ. nu a double of the parameter ν. sumto an integer for the summation term in the density (default 100).

6 rcomp The function is only implemented for single values of lam and nu. See dcomp for details of the PDF. A random sample of size n. require(graphics) sample <- rcomp(1000, 8.5, 0.9) barplot(table(sample))

Index coef, 4 data.frame, 3 dcomp, 2, 5, 6 extractaic, 4 formula, 3 glm.comp, 3 glm.fit, 4 loglik, 4 optim, 3, 4 pcomp, 4 predict, 4 print, 4 rcomp, 5 summary, 4 7