Skip to content

Commit

Permalink
Updated Tutorial to include an underdispersion example
Browse files Browse the repository at this point in the history
Also undo some changes to examples as it can't find autoplot.cmp for some reasons.
  • Loading branch information
thomas-fung committed Oct 26, 2020
1 parent 4d698ca commit 6c19792
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion R/glm.cmp.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
#' M.attendance <- glm.cmp(daysabs~ gender+math+prog, data=attendance)
#' M.attendance
#' summary(M.attendance)
#' \donttest{autoplot(M.attendance) # or plot(M.attendance)
#' \donttest{plot(M.attendance) # or autoplot(M.attendance)
#' }
#'
#' ### Ribeiro et al. (2013): Varying dispersion as a function of covariates
Expand Down
2 changes: 1 addition & 1 deletion R/mpcmp-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ NULL
#' + bidprem + insthold + size + sizesq + regulatn, data=takeoverbids)
#' M.bids
#' summary(M.bids)
#' autoplot(M.bids) #or plot(M.bids)
#' plot(M.bids) #or autoplot(M.bids)
#'
NULL

Expand Down
40 changes: 22 additions & 18 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
## Test environments
* local R installation, R 4.0.2
* ubuntu 16.04 (on travis-ci), R 4.0.2
* ubuntu 16.04, Windows, macOS (on GitHub Actions), R 4.0.2
* win-builder (devel and release)
* ubuntu 16.04 (on travis-ci), R 4.0.3
* ubuntu 16.04, Windows, macOS (on GitHub Actions), R 4.0.3
* win-builder (devel and release)

## R CMD check results
This is a patch submission to fix some issues picked up by CRAN checks.

There were no ERRORs or WARNINGs.
## R CMD check results

There was 1 NOTE:
0 errors | 0 warnings | 0 notes

* checking CRAN incoming feasibility ... NOTE
Maintainer: ‘Thomas Fung <[email protected]>’

New maintainer:
Thomas Fung <[email protected]>
Old maintainer(s):
Thomas Fung <[email protected]>
Errors and notes from previous submission.

The maintainer changed his email address.
Version: 0.3.5
Check: dependencies in R code
Result: NOTE
Namespace in Imports field not imported from: ‘broom’
All declared Imports should be used.
Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-release-macos-x86_64, r-oldrel-macos-x86_64

There are some issues with the ubuntu 16.04 check via GitHub actions:
"Failed to get R 4.0.3: Failed to get R 4.0.3" but it passes the checks on travis-ci.
* Moved `broom` to the `Suggests` field in Description.

## Downstream dependency.
Version: 0.3.5
Check: whether package can be installed
Result: ERROR
Installation failed.
Flavor: r-patched-solaris-x86

There are currently no downstream dependencies for this package.
* Cast integer to double for log function in Rcpp code. This should fix the solaris issue.

## Downstream dependency.

There are currently no downstream dependencies for this package.

2 changes: 1 addition & 1 deletion man/glm.cmp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/takeoverbids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vignettes/mpcmp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ methods(class = "cmp")

## Constant Underdispersion Example: `takeoverbids`

A dataset from @Cameron1997a that gives the number of bids received by 126 US firms that were successful targets of tender offers during the period 1978-85. The dataset comes with a set of explanatory variables such as defensive actions taken by management of target firm, firm-specific characteristics and intervention by federal regulators.
One of the key strength of the CMP distribution is that it can handle underdispersion. Here is an example demonstrating that. A dataset from @Cameron1997a that gives the number of bids received by 126 US firms that were successful targets of tender offers during the period 1978-85. The dataset comes with a set of explanatory variables such as defensive actions taken by management of target firm, firm-specific characteristics and intervention by federal regulators.

If we fit a Poisson distribution to the marginal distribution of the number of bids, we have:
```{r}
Expand All @@ -179,7 +179,7 @@ ggplot(takeoverbids) +
colour = "red") +
labs(title = "Number of bids with Poisson fit", y = "Probability")
```
We can see that the response variable is more concentrated than a Poisson fit suggests which is a sign of underdispersion.
We can see that the response variable is more concentrated than a Poisson fit, which is a sign of underdispersion.

Here, we can use `glm.cmp()` to fit the mean-parametrized CMP model to try to account for that underdispersion.
```{r}
Expand All @@ -188,7 +188,7 @@ M.bids <- glm.cmp(numbids ~ leglrest + rearest + finrest + whtknght
tidy(M.bids)
LRTnu(M.bids)
```
From the likelihood ratio test, we can see that the dispersion parameter is significantly differnet to 1, suggesting the model is trying to account for that underdispersion.
From the likelihood ratio test, we can see that the dispersion parameter is significantly different to 1, suggesting the model is trying to account for that underdispersion.

We can also compare the results with a Poisson model.
```{r}
Expand Down

0 comments on commit 6c19792

Please sign in to comment.