diff --git a/DESCRIPTION b/DESCRIPTION index 77350e8..bf97715 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: SimCorMultRes Type: Package Title: Simulates Correlated Multinomial Responses Description: Simulates correlated multinomial responses conditional on a marginal model specification. -Version: 1.7.3 +Version: 1.7.4 Depends: R(>= 2.15.0) Imports: evd, @@ -23,8 +23,8 @@ Authors@R: email = "A.Touloumis@brighton.ac.uk", comment = c(ORCID = "0000-0002-5965-1639") ) -URL: http://github.com/AnestisTouloumis/SimCorMultRes -BugReports: http://github.com/AnestisTouloumis/SimCorMultRes/issues +URL: https://github.com/AnestisTouloumis/SimCorMultRes +BugReports: https://github.com/AnestisTouloumis/SimCorMultRes/issues License: GPL-3 VignetteBuilder: knitr RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE index 27f7ba6..10b883b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,12 +11,14 @@ importFrom(evd,qgumbel) importFrom(methods,formalArgs) importFrom(stats,as.formula) importFrom(stats,formula) +importFrom(stats,get_all_vars) importFrom(stats,model.frame) importFrom(stats,model.matrix) importFrom(stats,na.omit) importFrom(stats,pnorm) importFrom(stats,qcauchy) importFrom(stats,qlogis) +importFrom(stats,qunif) importFrom(stats,rnorm) importFrom(stats,terms) importFrom(stats,toeplitz) diff --git a/R/SimCorMultRes-package.R b/R/SimCorMultRes-package.R index bddecc6..a6dcf34 100644 --- a/R/SimCorMultRes-package.R +++ b/R/SimCorMultRes-package.R @@ -65,7 +65,7 @@ #' \emph{Computational Statistics & Data Analysis} \bold{11}, 275--295. #' @importFrom evd qgumbel #' @importFrom methods formalArgs -#' @importFrom stats as.formula formula model.frame model.matrix na.omit -#' pnorm qcauchy qlogis rnorm terms toeplitz update +#' @importFrom stats as.formula formula get_all_vars model.frame model.matrix +#' na.omit pnorm qcauchy qlogis qunif rnorm terms toeplitz update #' @keywords package NULL diff --git a/R/SimCorMultRes_internals.R b/R/SimCorMultRes_internals.R index a4d0423..c98c878 100644 --- a/R/SimCorMultRes_internals.R +++ b/R/SimCorMultRes_internals.R @@ -201,13 +201,14 @@ create_distribution <- function(link) { if (length(link) != 1) { stop("The length of 'link' must be one") } - links <- c("probit", "logit", "cloglog", "cauchit") + links <- c("probit", "logit", "cloglog", "cauchit", "identity") if (!is.element(link, links)) { - stop("'link' must be 'probit','logit','cloglog' and/or 'cauchit'") + stop("'link' must be 'probit', 'logit', 'cloglog', 'cauchit' and/or + 'identity'") } distr <- switch( link, probit = "qnorm", logit = "qlogis", cloglog = "qgumbel", - cauchit = "qcauchy" + cauchit = "qcauchy", identity = "qunif" ) distr } @@ -276,7 +277,8 @@ create_output <- function(simulated_responses, sample_size, cluster_size, sim_model_frame <- stats::model.frame( formula = linear_predictor_formula, data = xdata ) - simdata <- data.frame(y, sim_model_frame, id, time) + simdata <- data.frame(y, get_all_vars(formula = linear_predictor_formula, + data = xdata), id, time) list( Ysim = simulated_responses, simdata = simdata, rlatent = simulated_latent_variables diff --git a/R/rbin.R b/R/rbin.R index eec8108..d3fa415 100644 --- a/R/rbin.R +++ b/R/rbin.R @@ -54,8 +54,8 @@ #' @param xdata optional data frame containing the variables provided in #' \code{xformula}. #' @param link character string indicating the link function in the marginal -#' model. Options include \code{'probit'}, \code{'logit'}, \code{'cloglog'} or -#' \code{'cauchit'}. Required when \code{rlatent = NULL}. +#' model. Options include \code{'probit'}, \code{'logit'}, \code{'cloglog'}, +#' \code{'cauchit'} or \code{'identity'}. Required when \code{rlatent = NULL}. #' @param cor.matrix matrix indicating the correlation matrix of the #' multivariate normal distribution when the NORTA method is employed #' (\code{rlatent = NULL}). diff --git a/README.md b/README.md index 070710b..88f2af8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # SimCorMultRes: Simulates Correlated Multinomial Responses [![Github -version](https://img.shields.io/badge/GitHub%20-1.7.3-orange.svg)](%22commits/master%22) +version](https://img.shields.io/badge/GitHub%20-1.7.4-orange.svg)](%22commits/master%22) [![R-CMD-check](https://github.com/AnestisTouloumis/SimCorMultRes/workflows/R-CMD-check/badge.svg)](https://github.com/AnestisTouloumis/SimCorMultRes/actions) [![Project Status: Active The project has reached a stable, usable state and is being actively @@ -88,8 +88,8 @@ beta_intercepts <- 0 beta_coefficients <- 0.2 latent_correlation_matrix <- toeplitz(c(1, 0.9, 0.9, 0.9)) x <- rep(rnorm(sample_size), each = cluster_size) -simulated_binary_responses <- rbin(clsize = cluster_size, intercepts = beta_intercepts, - betas = beta_coefficients, xformula = ~x, cor.matrix = latent_correlation_matrix, +simulated_binary_responses <- rbin(clsize = cluster_size, intercepts = beta_intercepts, + betas = beta_coefficients, xformula = ~x, cor.matrix = latent_correlation_matrix, link = "probit") library(gee) binary_gee_model <- gee(y ~ x, family = binomial("probit"), id = id, data = simulated_binary_responses$simdata) diff --git a/SimCorMultRes.Rproj b/SimCorMultRes.Rproj index 42b95bd..05f2229 100644 --- a/SimCorMultRes.Rproj +++ b/SimCorMultRes.Rproj @@ -17,6 +17,5 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source PackageCheckArgs: --as-cran PackageRoxygenize: rd,collate,namespace,vignette diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 5fd90c3..fe7b652 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -1,8 +1,10 @@ \name{NEWS} \title{NEWS file for the \pkg{SimCorMultRes} package} -\section{Changes in Version 1.7.3 (2021-01-22)}{ +\section{Changes in Version 1.7.4 (2021-06-08)}{ \itemize{ + \item{Corrected naming of variables in formula.} + \item{Added \code{identity} link to the function \code{rbin}.} \item{Added \pkg{rmarkdown} dependency.} \item{Removed \pkg{markdown} dependency.} \item{Migrating from travis-ci to github actions.} @@ -11,103 +13,162 @@ } } + \section{Changes in Version 1.7.0 (2019-07-25)}{ - \itemize{ - \item{Added unit tests.} - \item{Improved R code readability.} - \item{Modified .travis.yml.} - \item{Added code coverage.} - \item{Added function \code{rmult.acl} to simulate from a marginal adjacent-categories logit model.} + \subsection{NEW FEATURES}{ + \itemize{ + \item{Added function \code{rmult.acl} to simulate from a marginal adjacent-categories logit model.} + } + } + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Added unit tests.} + } + } + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Added code coverage.} + \item{Improved R code readability.} + \item{Modified .travis.yml.} + } } } + \section{Changes in Version 1.6.0 (2018-07-10)}{ - \itemize{ - \item{Updated documentation.} - \item{Changed vignette from pdf to html.} + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Changed vignette from pdf to html.} + \item{Updated documentation.} + } } } \section{Changes in Version 1.5.0 (2017-07-11)}{ + \subsection{MINOR CHANGES}{ \itemize{ \item{Added README.Rmd.} - \item{Updated vignette.} - \item{Updated R code.} - \item{Updated documentation.} - \item{Updated CITATION.} \item{Created a github repo.} - \item{Improved vignette in R using \pkg{bookdown}.} + \item{Improved vignette using \pkg{bookdown}.} + \item{Updated CITATION.} + \item{Updated documentation.} + \item{Updated R code.} + \item{Updated vignette.} + } } } + \section{Changes in Version 1.4.2 (2016-09-15)}{ + \subsection{MINOR CHANGES}{ \itemize{ \item{Updated CITATION.} \item{Updated documentation.} } } + } + \section{Changes in Version 1.4.1 (2016-07-19)}{ - \itemize{ - \item{Replaced the \code{lin.pred} argument in the core functions with three easier to handle arguments (\code{betas}, \code{xformula} and \code{xdata}).} - \item{Increased the flexibility of the implementation of the NORTA method in the function \code{rnorta}.} - \item{Introduced the \code{rlatent} argument in the core functions to allow user-defined simulated values for the latent variables.} - \item{Updated R code.} - \item{Updated CITATION.} - \item{Updated vignette.} - \item{Updated documentation.} + \subsection{NEW FEATURES}{ + \itemize{ + \item{Introduced argument \code{rlatent} to allow user-defined simulated values for the latent variables.} + } + } + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Increased flexibility in \code{rnorta}.} + \item{Replaced argument \code{lin.pred} with three easier to handle arguments (\code{betas}, \code{xformula} and \code{xdata}).} + } + } + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Updated CITATION.} + \item{Updated documentation.} + \item{Updated R code.} + \item{Updated vignette.} + } } } \section{Changes in Version 1.4.0 (2015-12-15)}{ - \itemize{ - \item{Added the \code{rbin} function to simulate correlated binary responses.} - \item{Updated CITATION.} - \item{Updated DESCRIPTION.} - \item{Updated vignette.} - \item{Updated documentation.} - \item{Change the name of the argument \code{cuts} to \code{intercepts}.} - \item{Allowed the intercepts of the marginal models to vary for the correlated responses.} + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Added \code{rbin} function to simulate correlated binary responses.} + \item{Changed the name of the argument \code{cuts} to \code{intercepts}.} + } + } + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Updated CITATION.} + \item{Updated DESCRIPTION.} + \item{Updated documentation.} + \item{Updated vignette.} } } + } + \section{Changes in Version 1.3.1 (2015-09-08)}{ - \itemize{ - \item{Updated email address of the maintainer.} - \item{The package now imports functions from the R package \pkg{stats}.} - \item{Removed \pkg{evd} dependency.} + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Added to Imports \pkg{stats}.} + \item{Removed \pkg{evd} dependency.} + \item{Updated maintainer's email address.} } } + } + \section{Changes in Version 1.3.0 (2015-01-08)}{ - \itemize{ - \item{Introduced a x.y.z version system.} - \item{Updated documentation.} - \item{Updated vignette.} - \item{Updated R code.} - \item{Added CITATION.} + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Added CITATION.} + \item{Introduced a x.y.z version system.} + \item{Updated documentation.} + \item{Updated R code.} + \item{Updated vignette.} } } + } + \section{Changes in Version 1.2 (2014-03-01)}{ - \itemize{ - \item{Added vignette.} - \item{Updated the email address of the maintainer.} - \item{Updated documentation.} + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Updated maintainer's email address.} + } + } + \subsection{MINOR CHANGES}{ + \itemize{ + \item{Added vignette.} + \item{Updated documentation.} + } } } + \section{Changes in Version 1.1 (2013-05-30)}{ + \subsection{NEW FEATURES}{ + \itemize{ + \item{Added \code{rmult.crm} function to simulate correlated ordinal multinomial responses under a marginal continuation ratio model.} + } + } + \subsection{MAJOR CHANGES}{ + \itemize{ + \item{Removed \pkg{mvtnorm} dependency.} + }} + \subsection{MINOR CHANGES}{ \itemize{ - \item{Removed the R package \pkg{mvtnorm} dependency.} - \item{Added the function \code{rmult.crm} to simulate correlated ordinal multinomial responses under a marginal continuation ratio model.} \item{Updated documentation.} \item{Updated R code.} } } + } + -\section{Changes in Version 1.0 (2012-11-12)}{ +\section{Version 1.0 (2012-11-12)}{ \itemize{ \item{The first version of the R package \pkg{SimCorMultRes} is released on CRAN.} } diff --git a/man/rbin.Rd b/man/rbin.Rd index 8fb2990..7ee6ef9 100644 --- a/man/rbin.Rd +++ b/man/rbin.Rd @@ -26,8 +26,8 @@ but without including a response variable.} \code{xformula}.} \item{link}{character string indicating the link function in the marginal -model. Options include \code{'probit'}, \code{'logit'}, \code{'cloglog'} or -\code{'cauchit'}. Required when \code{rlatent = NULL}.} +model. Options include \code{'probit'}, \code{'logit'}, \code{'cloglog'}, +\code{'cauchit'} or \code{'identity'}. Required when \code{rlatent = NULL}.} \item{cor.matrix}{matrix indicating the correlation matrix of the multivariate normal distribution when the NORTA method is employed diff --git a/vignettes/SimCorMultRes.Rmd b/vignettes/SimCorMultRes.Rmd index 2ce5166..26b09d6 100644 --- a/vignettes/SimCorMultRes.Rmd +++ b/vignettes/SimCorMultRes.Rmd @@ -85,7 +85,7 @@ x2 <- rnorm(sample_size * cluster_size) # create covariates dataframe xdata <- data.frame(x1, x2) set.seed(321) -library(SimCorMultRes) +library("SimCorMultRes") # latent correlation matrix for the NORTA method equicorrelation_matrix <- toeplitz(c(1, rep(0.95,cluster_size - 1))) identity_matrix <- diag(categories_no) @@ -355,7 +355,7 @@ simulated_binary_dataset <- rbin(clsize = cluster_size, betas = beta_coefficients, xformula = ~ x, cor.matrix = latent_correlation_matrix, link = "probit") -library(gee) +library("gee") # fitting a GEE model binary_gee_model <- gee(y ~ x, family = binomial("probit"), id = id, data = simulated_binary_dataset$simdata) @@ -436,7 +436,6 @@ simulated_binary_dataset <- rbin(clsize = cluster_size, betas = beta_coefficients, xformula = ~x, cor.matrix = latent_correlation_matrix, link = "probit") -library(gee) # simulated marginal probabilities colMeans(simulated_binary_dataset$Ysim) ``` @@ -469,6 +468,8 @@ simulated_nominal_dataset <- rmult.bcl(clsize = cluster_size, # simulated marginal probabilities apply(simulated_nominal_dataset$Ysim, 2, table) / sample_size ``` + + # How to Cite ```{r, comment=""} citation("SimCorMultRes")