Skip to content

Commit

Permalink
Improve documentation + examples of gmo function
Browse files Browse the repository at this point in the history
Clean up imports, exports; Add long description
  • Loading branch information
Express50 committed May 1, 2019
1 parent 572797f commit 3d89732
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 27 deletions.
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ Title: Overdispersion Models using Generalized Estimating Equations
Version: 1.0
Author: Victoria Landsman, David Landsman
Maintainer: David Landsman <david.landsman@mail.utoronto.ca>
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
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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")
26 changes: 17 additions & 9 deletions R/gmo.r
Original file line number Diff line number Diff line change
@@ -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")))
Expand Down Expand Up @@ -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, ...)}
Expand All @@ -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, ...)}
Expand All @@ -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")
}
9 changes: 9 additions & 0 deletions R/helpers.r
Original file line number Diff line number Diff line change
@@ -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))
}
3 changes: 2 additions & 1 deletion R/iterative.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library(rootSolve)

#' Iterative GEE Function
#'
#' Iteratively finds coefficients and overdispersion parameter using
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions R/variance.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions man/gmo.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/print.gmo.glogit.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/print.gmo.ident.Rd

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

19 changes: 19 additions & 0 deletions man/tr.Rd

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

0 comments on commit 3d89732

Please sign in to comment.