diff --git a/.Rbuildignore b/.Rbuildignore index 5f1d894..668d17e 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,3 +17,4 @@ continuous.png ex_code_plot.R README.md anim_ggplot.gif +overwrite_datasets.R diff --git a/DESCRIPTION b/DESCRIPTION index daf5e8e..41c6018 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,7 @@ BugReports: https://github.com/saudiwin/ordbetareg_pack/issues License: MIT + file LICENSE Encoding: UTF-8 LazyData: true +LazyDataCompression: xz Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.2 Depends: diff --git a/NEWS.md b/NEWS.md index 190856f..18b96bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,8 @@ - Improved plot formatting and added theme and label options. - Updated vignette to include information about `glmmTMB` as an alternative for estimation and new plot functions. +- Added distribution `rordbeta` and `dordbeta` functions. +- Removed legacy `0 + Intercept` function code. Now accepts any kind of formula. # ordbetareg v0.5.0 diff --git a/R/distribution.R b/R/distribution.R index 6b0bf14..d788265 100644 --- a/R/distribution.R +++ b/R/distribution.R @@ -21,7 +21,7 @@ #' @param cutpoints A vector of two numeric values for the cutpoints. Second value should #' @param log where to return the log density #' be strictly greater than the first value. -#' @example +#' @examples #' #' # examine density (likelihood) of different possible values #' # given fixed values for ordered beta parameters diff --git a/R/modeling.R b/R/modeling.R index 6534aff..51975d2 100644 --- a/R/modeling.R +++ b/R/modeling.R @@ -115,6 +115,7 @@ #' @examples #' # load survey data that comes with the package #' +#' library(dplyr) #' data("pew") #' #' # prepare data @@ -948,6 +949,8 @@ ordbetareg <- function(formula=NULL, #' #' data("sim_data") #' +#' library(dplyr) +#' #' # will take a while to run this #' \donttest{ #' sim_data <- sim_ordbeta(N=c(250,750), diff --git a/cran-comments.md b/cran-comments.md index 38392fa..00125da 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,31 +2,32 @@ 0 errors | 0 warnings | 1 notes -> checking installed package size ... NOTE - installed size is 5.7Mb +❯ checking installed package size ... NOTE + installed size is 13.4Mb sub-directories of 1Mb or more: - data 5.2Mb + data 10.0Mb + doc 3.3Mb The data sub-directory contains fitted models that are used to illustrate function examples because fitting the model can take up to an hour. -Submitting to win-release results in OK status - no NOTEs or WARNINGs. +Submitting to win-release results in 1 ERROR: -Submitting to win-devel results in the following WARNING: +Error(s) in re-building vignettes: +--- re-building 'package_introduction.Rmd' using rmarkdown +Quitting from lines 247-258 (package_introduction.Rmd) +Error: processing vignette 'package_introduction.Rmd' failed with diagnostics: +could not find function "avg_slopes" +--- failed re-building 'package_introduction.Rmd' -Found the following significant warnings: - Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0. -See 'd:/RCompile/CRANguest/R-devel/ordbetareg.Rcheck/00install.out' for details. +SUMMARY: processing the following file failed: + 'package_introduction.Rmd' -The ggplot2 3.4.0 package is not currently available in CRAN. To address this issue, I added code that will use the updated function argument if ggplot2 3.4.0 is detected (see plot.R line number 154): +Error: Vignette re-building failed. +Execution halted -``` -if(packageVersion('ggplot2')=="3.4.0") { +Submitting to win-devel results in OK status - no NOTEs or WARNINGs. - cont_plot <- cont_plot + geom_density(aes(x=true),linewidth=2,colour="gray",alpha=0.7) +The error in win-release appears to be due to the fact the marginaleffects package, which has the avg_slopes function, does not have a binary available for windows for the current version of the package, 0.9.0. This is the required version listed under the Suggests field in ordbetareg but win-release is installing an older version that does not have the avg_slopes function. However, it is necessary to update to 0.9.0 as otherwise the package vignette fails to compile, and I received an email from the CRAN maintainer requesting that I update the package to handle marginaleffects 0.9.0--see build logs at https://cran.r-project.org/web/checks/check_results_ordbetareg.html. If I do not update the package by 2-16-2023, it will be removed from CRAN. -} else { +As such, it would seem that this error in win-release should be ignored as it is not clear why it is not installing the current version of marginaleffects, which has been available since Feb 1 2023. - cont_plot <- cont_plot + geom_density(aes(x=true),size=2,colour="gray",alpha=0.7) - -} -``` diff --git a/data/fit_imputed.rda b/data/fit_imputed.rda index af5fdfa..fdecd46 100644 Binary files a/data/fit_imputed.rda and b/data/fit_imputed.rda differ diff --git a/data/fit_multivariate.rda b/data/fit_multivariate.rda index 18d1686..8739bf0 100644 Binary files a/data/fit_multivariate.rda and b/data/fit_multivariate.rda differ diff --git a/data/ord_fit_mean.rda b/data/ord_fit_mean.rda index 10dd897..24ef0ce 100644 Binary files a/data/ord_fit_mean.rda and b/data/ord_fit_mean.rda differ diff --git a/data/ord_fit_phi.rda b/data/ord_fit_phi.rda index 14e82b6..e9ef639 100644 Binary files a/data/ord_fit_phi.rda and b/data/ord_fit_phi.rda differ diff --git a/man/dordbeta.Rd b/man/dordbeta.Rd index 350d697..05c1a1e 100644 --- a/man/dordbeta.Rd +++ b/man/dordbeta.Rd @@ -28,3 +28,24 @@ the mean (\code{mu}), dispersion (\code{phi}) and cutpoints governing the ratio of degenerate (discrete) to continuous responses. } +\examples{ + +# examine density (likelihood) of different possible values +# given fixed values for ordered beta parameters + +x <- seq(0, 1, by=0.01) + +x_dens <- dordbeta(x, mu = 0.3, phi=2, cutpoints=c(-2, 2)) + +# Most likely value for x is approx 1 +# Note discontinuity in density function between continuous/discrete values +# density function is a combined PMF/PDF, so not a real PDF +# can though be used for MLE + +plot(x_dens, x) + +# discrete values should be compared to each other: +# prob of discrete 0 > prob of discrete 1 + +x_dens[x==0] > x_dens[x==1] +} diff --git a/man/ordbetareg.Rd b/man/ordbetareg.Rd index 733caf7..ae83d9c 100644 --- a/man/ordbetareg.Rd +++ b/man/ordbetareg.Rd @@ -183,6 +183,7 @@ Kubinec, Robert. "Ordered Beta Regression: A Parsimonious, Well-Fitting Model fo \examples{ # load survey data that comes with the package +library(dplyr) data("pew") # prepare data diff --git a/man/sim_ordbeta.Rd b/man/sim_ordbeta.Rd index 90197c5..a23dfec 100644 --- a/man/sim_ordbeta.Rd +++ b/man/sim_ordbeta.Rd @@ -94,6 +94,8 @@ with one row per simulation draw and covariate \code{k}. data("sim_data") +library(dplyr) + # will take a while to run this \donttest{ sim_data <- sim_ordbeta(N=c(250,750), diff --git a/vignettes/package_introduction.Rmd b/vignettes/package_introduction.Rmd index 5ad3e55..7fb7939 100644 --- a/vignettes/package_introduction.Rmd +++ b/vignettes/package_introduction.Rmd @@ -244,7 +244,6 @@ modelsummary(ord_fit_mean,statistic = "conf.int", There is a related package, `marginaleffects`, that allows us to convert these coefficients into more meaningful marginal effect estimates, i.e., the effect of the predictors expresses as the actual change in the outcome on the 0 - 1 scale. Because we have two variables in our model that are both ordinal in nature, `marginaleffects` will produce an estimate of the marginal effect of each value of each ordinal predictor. I use the `avg_slopes` function to convert the `ordbetareg` model to a data frame of marginal/conditional effects in the scale of the outcome that can be easily printed: ```{r marg_effect} -library(marginaleffects) avg_slopes(ord_fit_mean, variables="education") %>% select(Variable="term", @@ -415,14 +414,14 @@ As I explain in the paper, one of the main advantages of using a Beta regression The one change we need to make to fit this model is to add a formula predicting `phi` in the code below. Because we now have two formulas--one for the mean and one for dispersion--I use the `bf` function to indicate these two sub-models. I also need to specify `phi_reg` to be TRUE because some of the priors will change. -Because there is no need to model the mean, I leave the first formula as `therm ~ 0`. I don't specify 1 for an intercept because the ordered regression model has other intercepts (i.e., the cutpoints). I then specify a separate model for `phi` with an interaction between `age` and `sex` to see if these covariates are associated with dispersion. +Because there is no need to model the mean, I leave the first formula as `therm ~ 1` with the 1 representing only an intercept, not a covariate. I then specify a separate model for `phi` with an interaction between `age` and `sex` to see if these covariates are associated with dispersion. ```{r run_brms_phi} if(run_model) { - ord_fit_phi <- ordbetareg(bf(therm ~ 0, + ord_fit_phi <- ordbetareg(bf(therm ~ 1, phi ~ age + sex), phi_reg = T, data=model_data,