diff --git a/DESCRIPTION b/DESCRIPTION index 29e380c..c2c9231 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,14 +4,12 @@ Title: Overdispersion Models using Generalized Estimating Equations Version: 1.0 Author: Victoria Landsman, David Landsman Maintainer: David Landsman -Description: More about what it does (maybe more than one line) - Use four spaces when indenting paragraphs within the Description. +Description: Provides an implementation of a GEE solver for estimating + the parameters of an overdispersion model. The solver supports data with + both an independence and exchangeable correlation model. License: MIT + file LICENSE Encoding: UTF-8 LazyData: true RoxygenNote: 6.1.1 -Imports: - base, - stats, - psych, +Imports: rootSolve diff --git a/NAMESPACE b/NAMESPACE index 7c5818e..00e658e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,8 @@ -exportPattern("^[[:alpha:]]+") +# Generated by roxygen2: do not edit by hand + +S3method(print,gmo.glogit) +S3method(print,gmo.ident) export(gmo) -importFrom("psych", "tr") importFrom("rootSolve", "multiroot") -importFrom("stats", "uniroot") +importFrom("stats", "uniroot") \ No newline at end of file diff --git a/R/gmo.r b/R/gmo.r index d0c263f..f86b5fe 100644 --- a/R/gmo.r +++ b/R/gmo.r @@ -1,16 +1,27 @@ #' GMO - General Multinomial Overdisperion Model #' -#' Creates an General Multinomial Overdispersion Model for the given data +#' Creates an General Multinomial Overdispersion Model for the given data matrix. +#' The data passed in should be in the form of multinomial clusters. #' +#' The `corstr` option specifies the intra-cluster correlation structure: +#' - `independence` is used when there is no intra-cluster correlation (i.e.: rho = 0) (default) +#' - `exchangebale` is used when there is intra-cluster correlation +#' +#' The `link` option specifies the format of the output: +#' - `glogit` option gives the estimates and variance matrix in terms of beta (real-valued) (default) +#' - `identity` option gives the estimates and variance matrix in terms of pi's in [0, 1] #' #' @param dat matrix of multinomial clusters #' @param corstr one of: independence, exchangeable #' @param link one of: glogit, identity -#' @param ... parameters to be passed on to \code{iterative_function} +#' +#' @examples +#' dat <- matrix(c(6, 4, 4, 3, 1, 2, 2, 2, 1, 3, 15, 6, 5, 8, 4, 2, 2, 1, 13, 10, 8, 1, 3, 2, 10, 22, 11, 31, 10, 14), nrow=10, ncol=3, byrow=TRUE) +#' gmo(dat, link='identity') #' #' @return a GMO object #' @export -gmo <- function (dat, corstr = "independence", link = "glogit", ...) { +gmo <- function (dat, corstr = "independence", link = "glogit") { if (!is.matrix(dat)) stop("dat must be a matrix") if (!(corstr %in% c("independence", "exchangeable"))) @@ -50,7 +61,7 @@ gmo <- function (dat, corstr = "independence", link = "glogit", ...) { #' Print GMO glogit #' -#' Prints GMO glogit object +#' Prints GMO glogit object. #' #' @param x gom glogit object #' @param ... additional params to \code{print(x, ...)} @@ -75,7 +86,7 @@ print.gmo.glogit <- function(x, ...) { #' Print GMO identity #' -#' Prints GMO identity object +#' Prints GMO identity object. #' #' @param x gom identity object #' @param ... additional params to \code{print(x, ...)} @@ -96,7 +107,4 @@ print.gmo.ident <- function(x, ...) { cat('\nVar-Covar Matrix: \n') print(round(x$var.mat, 6), ...) -} - -registerS3method("print", "gmo.glogit", "print.gmo.glogit") -registerS3method("print", "gmo.ident", "print.gmo.ident") +} \ No newline at end of file diff --git a/R/helpers.r b/R/helpers.r new file mode 100644 index 0000000..0b8772d --- /dev/null +++ b/R/helpers.r @@ -0,0 +1,9 @@ +#' Compute trace of a square matrix, that is, the sum +#' of its diagonal elements. +#' +#' @param m a square matrix +#' +#' @return trace of input matrix +tr <- function(m) { + sum(diag(m)) +} \ No newline at end of file diff --git a/R/iterative.r b/R/iterative.r index ab5bb41..cce0c60 100644 --- a/R/iterative.r +++ b/R/iterative.r @@ -1,3 +1,5 @@ +library(rootSolve) + #' Iterative GEE Function #' #' Iteratively finds coefficients and overdispersion parameter using @@ -9,7 +11,6 @@ #' @param thresholds vector of thresholds for betas and rho #' #' @return list containing estimates (probabilities and rho) and number of iterations -#' @export iterative_function <- function(dat, RHO = FALSE, max.iter = 10, thresholds = NULL) { n <- dim(dat)[[2]] if (is.null(thresholds)) thresholds <- rep(0.00000001, n) diff --git a/R/variance.r b/R/variance.r index 5c56598..2509a12 100644 --- a/R/variance.r +++ b/R/variance.r @@ -7,7 +7,6 @@ #' @param dat matrix of multinomial clusters #' #' @return matrix of covariance -#' @export get_var_ident <- function (p.vec, rho, dat) { n <- dim(dat)[[2]] # dimensions of multinom m <- n - 1 # order of multinom @@ -47,7 +46,6 @@ get_var_ident <- function (p.vec, rho, dat) { #' @param dat matrix of multinomial clusters #' #' @return matrix of covariance -#' @export get_var_glogit <- function(betas, rho, dat) { n <- dim(dat)[[2]] # dimensions of multinom m <- n - 1 # order of multinom diff --git a/man/gmo.Rd b/man/gmo.Rd index 055549a..3401fe5 100644 --- a/man/gmo.Rd +++ b/man/gmo.Rd @@ -4,7 +4,7 @@ \alias{gmo} \title{GMO - General Multinomial Overdisperion Model} \usage{ -gmo(dat, corstr = "independence", link = "glogit", ...) +gmo(dat, corstr = "independence", link = "glogit") } \arguments{ \item{dat}{matrix of multinomial clusters} @@ -12,12 +12,25 @@ gmo(dat, corstr = "independence", link = "glogit", ...) \item{corstr}{one of: independence, exchangeable} \item{link}{one of: glogit, identity} - -\item{...}{parameters to be passed on to \code{iterative_function}} } \value{ a GMO object } \description{ -Creates an General Multinomial Overdispersion Model for the given data +Creates an General Multinomial Overdispersion Model for the given data matrix. +The data passed in should be in the form of multinomial clusters. +} +\details{ +The `corstr` option specifies the intra-cluster correlation structure: + - `independence` is used when there is no intra-cluster correlation (i.e.: rho = 0) (default) + - `exchangebale` is used when there is intra-cluster correlation + +The `link` option specifies the format of the output: + - `glogit` option gives the estimates and variance matrix in terms of beta (real-valued) (default) + - `identity` option gives the estimates and variance matrix in terms of pi's in [0, 1] +} +\examples{ +dat <- matrix(c(6, 4, 4, 3, 1, 2, 2, 2, 1, 3, 15, 6, 5, 8, 4, 2, 2, 1, 13, 10, 8, 1, 3, 2, 10, 22, 11, 31, 10, 14), nrow=10, ncol=3, byrow=TRUE) +gmo(dat, link='identity') + } diff --git a/man/print.gmo.glogit.Rd b/man/print.gmo.glogit.Rd index 72396ca..0b7e792 100644 --- a/man/print.gmo.glogit.Rd +++ b/man/print.gmo.glogit.Rd @@ -15,5 +15,5 @@ None } \description{ -Prints GMO glogit object +Prints GMO glogit object. } diff --git a/man/print.gmo.ident.Rd b/man/print.gmo.ident.Rd index 52c8d70..ec74446 100644 --- a/man/print.gmo.ident.Rd +++ b/man/print.gmo.ident.Rd @@ -15,5 +15,5 @@ None } \description{ -Prints GMO identity object +Prints GMO identity object. } diff --git a/man/tr.Rd b/man/tr.Rd new file mode 100644 index 0000000..2b138cf --- /dev/null +++ b/man/tr.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.r +\name{tr} +\alias{tr} +\title{Compute trace of a square matrix, that is, the sum +of its diagonal elements.} +\usage{ +tr(m) +} +\arguments{ +\item{m}{a square matrix} +} +\value{ +trace of input matrix +} +\description{ +Compute trace of a square matrix, that is, the sum +of its diagonal elements. +}