Skip to content

Commit

Permalink
version 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
friendly authored and cran-robot committed Sep 20, 2022
1 parent 65bca8a commit dbd7cb3
Show file tree
Hide file tree
Showing 48 changed files with 11,843 additions and 1,159 deletions.
22 changes: 16 additions & 6 deletions DESCRIPTION
Expand Up @@ -2,21 +2,31 @@ Package: mvinfluence
Type: Package
Title: Influence Measures and Diagnostic Plots for Multivariate Linear
Models
Version: 0.8-3
Date: 2018-05-16
Author: Michael Friendly
Version: 0.9.0
Date: 2022-09-10
Authors@R:
person(given ="Michael",
family = "Friendly",
email = "friendly@yorku.ca",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3237-0941"))
Maintainer: Michael Friendly <friendly@yorku.ca>
Description: Computes regression deletion diagnostics for multivariate linear models and provides some associated
diagnostic plots. The diagnostic measures include hat-values (leverages), generalized Cook's distance, and
generalized squared 'studentized' residuals. Several types of plots to detect influential observations are
provided.
Depends: car, heplots
Suggests:
Suggests: knitr, rmarkdown, ggplot2, tibble, patchwork, rgl, dplyr
LazyData: TRUE
VignetteBuilder: knitr
Encoding: UTF-8
License: GPL-2
Language: en-US
URL: https://github.com/friendly/mvinfluence
BugReports: https://github.com/friendly/mvinfluence/issues
Packaged: 2018-05-17 12:28:23 UTC; Friendly
Packaged: 2022-09-20 16:49:20 UTC; friendly
RoxygenNote: 7.2.1
NeedsCompilation: no
Author: Michael Friendly [aut, cre] (<https://orcid.org/0000-0002-3237-0941>)
Repository: CRAN
Date/Publication: 2018-05-17 17:01:07 UTC
Date/Publication: 2022-09-20 17:10:02 UTC
70 changes: 43 additions & 27 deletions MD5
@@ -1,28 +1,44 @@
1c07be2e0c5bbe21a9bd4bf16b9b7ba7 *DESCRIPTION
3929b04f43ef8f79555e80f65271b747 *NAMESPACE
7fdab54a6c9b91ad720fbc9036e5b1a5 *NEWS
49bc7ebcfa2f3f476d13b4875613cd9d *R/Jfuns.R
06e1290da5c78cf6a91d38930b4a8252 *R/as.data.frame.inflmlm.R
15114d05d1500e91790a4e6431f5c4f1 *R/cooks.distance.mlm.R
c55b965d1603ed5eac3ab22180fb22f0 *R/hatvalues.mlm.R
3faff10861c8fbf8c365567f646a9022 *R/infIndexPlot.R
0e14b325696afceba3f1ac95aaf6b4d7 *R/influence.mlm.R
d47fee763278b361a68f5727b7e34741 *R/influencePlot.mlm.R
de37a9e4cbe7b1131769679115ef376d *R/lrPlot.R
f2228772ea8fa017bd6a7ccfc8739f24 *R/mlm.influence.R
7e8913d0afd5dc3b6b0960a6ed4e0c5f *R/mpower.R
3f2b26d56c2b1ea50847dbb4e070e571 *R/print.inflmlm.R
c455d858c18ba6024178ad65848253a4 *R/tr.R
514e37d6dcfe1b6f91ef7716edca4358 *build/partial.rdb
2012e00080b590a585c2d1becaa087b5 *DESCRIPTION
7a5993b346c13f2525bbea88da61c0da *NAMESPACE
2a333652ac77fe5f40b89aa36375a154 *NEWS
491f3374662db29d33a6adae35c0670b *R/Jfuns.R
825b78c5dd0914300a26b0bc3f17f3cb *R/as.data.frame.inflmlm.R
48ef35f87ce844b7ba48d66747aef849 *R/cooks.distance.mlm.R
fd1a5195ea357f514d9753302481c9b2 *R/data.R
2ed4a0a7c6f0a96f767a0b7e6b54c482 *R/hatvalues.mlm.R
8b7b5a431fb5d075261e0db0ce764728 *R/infIndexPlot.R
b3a7b0ac5fb53e46f394fb3c652c49df *R/influence.mlm.R
26cfdc9b64fb2c524f6f88bb5232813c *R/influencePlot.mlm.R
d08b35411458e6a645cf72d56a565e15 *R/lrPlot.R
d1e0884fa1dac0e18a1864184086b7d9 *R/mlm.influence.R
323c725cc3de6bebddbce416845448b9 *R/mpower.R
f987a9a9a01175c898020252355a6952 *R/mvinfluence-package.R
92491f4656b2c51654f6b4cd682976c6 *R/print.inflmlm.R
e7da14a110a10d16032b674d0fd846e6 *R/tr.R
f25a8619493445f188092a97b4d02808 *build/vignette.rds
0d7a8dcfee6858612d29312323be439e *data/Fertilizer.RData
ed140f0678b98693e8e63848efdc86c4 *man/Fertilizer.Rd
c502ca573146e16df22b7c6ea2f0014f *man/Jfuns.Rd
f3aa73270289d22dc741f37ba4778e21 *man/infIndexPlot.mlm.Rd
6a96040426010375959dec31db876cab *man/influence.measures.Rd
6fbb1a5481d3c7d5ea03fbf858dd3fcd *man/influence.mlm.Rd
78115c0f8e8aa84b7054e4057b440d6c *man/influencePlot.mlm.Rd
8e95b216d551cb532ba48ea91696fc0d *man/lrPlot.Rd
05e441e6a98f380b8c67559cb01d56a5 *man/mlm.influence.Rd
486e141717ec3d594e5328cac11e0c10 *man/mpower.Rd
2b03dce00dd6adb1c2cee4cb23f36eb3 *man/mvinfluence-package.Rd
69f0a830fa15cea5d1a0083f87adc438 *man/tr.Rd
71f07e44feed8bc45a1a3a386afddf9b *inst/WORDLIST
5d98fbfe67d6d931331b66d0e2eb8263 *inst/doc/uni-vs-multi.R
92a6966895ebea8922d80f08d7d88493 *inst/doc/uni-vs-multi.Rmd
09265eece8aa02e9dc07f912d60d7b3b *inst/doc/uni-vs-multi.html
cfa5dc385fd4c375d98f725655d60a6b *man/Fertilizer.Rd
9fae563ac277e85b7423719dec83ee4c *man/Jtr.Rd
bea1077751ca6af9a17aee903c8ee4a1 *man/as.data.frame.inflmlm.Rd
3c72348269093153d113224b0187fe49 *man/cooks.distance.mlm.Rd
62ac4898ecb84a9c7e2ca8131908fdaf *man/figures/README-indexplot-1.png
4d366c6b0501974690eabf07a1edace7 *man/figures/README-rob-index-plot-1.png
f6d1d5782ed20c6da51a26193206958e *man/figures/README-rohwer1-1.png
f6d1d5782ed20c6da51a26193206958e *man/figures/README-rohwer2-1.png
115056eed09d0e3c93b9c709389e959e *man/figures/README-rohwer3-1.png
c982220d9e17177be79ffed6bcadbd12 *man/figures/logo.png
18beb2d139f1a1d90426eb514d74fb65 *man/hatvalues.mlm.Rd
6a45ee81b44bcc860972fd79530eb3f5 *man/infIndexPlot.mlm.Rd
da7a00c22badabb2f6ecdb70c1bd7c12 *man/influence.mlm.Rd
9b4b5058a970e8018b84927d0d067961 *man/influencePlot.mlm.Rd
a07e2b10c3ab83d8b115410f4d28fd44 *man/lrPlot.Rd
d241f616a341241f70cec75546654f32 *man/mlm.influence.Rd
f357f5dff77c043d2c05305e3f55c6f4 *man/mpower.Rd
b84a1c5beeddb19acc3f59d74fcfb774 *man/mvinfluence.Rd
2f551bd5964304c18b4c7f8c5c4e059e *man/print.inflmlm.Rd
6867c63755088b8b9c494ba2483fceb9 *man/tr.Rd
92a6966895ebea8922d80f08d7d88493 *vignettes/uni-vs-multi.Rmd
77 changes: 41 additions & 36 deletions NAMESPACE
@@ -1,37 +1,42 @@
# Generated by roxygen2: do not edit by hand

# imports
importFrom("car", "showLabels", "influencePlot", "infIndexPlot", "influenceIndexPlot")
importFrom("heplots", "trans.colors", "Mahalanobis")
importFrom("grDevices", "palette")
importFrom("graphics", "abline", "axis", "box", "mtext", "par", "plot",
"points", "text")
importFrom("stats", "cooks.distance", "hatvalues", "influence",
"coef", "model.frame", "model.matrix",
"model.response", "qbeta", "qf", "residuals", "rstudent")
importFrom("utils", "combn")

#exportPattern("^[[:alpha:]]+")

export(
cooks.distance.mlm,
hatvalues.mlm,
influence.mlm,
influencePlot.mlm,
mlm.influence,
lrPlot,
mpower,
tr,
infIndexPlot.mlm
)

S3method(lrPlot, lm)

S3method(hatvalues, mlm)
S3method(cooks.distance, mlm)
S3method(influence, mlm)
S3method(influencePlot, mlm)
S3method(infIndexPlot, mlm)

S3method(print, inflmlm)
S3method(as.data.frame, inflmlm)

S3method(as.data.frame,inflmlm)
S3method(cooks.distance,mlm)
S3method(hatvalues,mlm)
S3method(infIndexPlot,mlm)
S3method(influence,mlm)
S3method(influencePlot,mlm)
S3method(lrPlot,lm)
S3method(print,inflmlm)
export("%^%")
export(lrPlot)
export(mlm.influence)
export(mpower)
export(tr)
importFrom(car,infIndexPlot)
importFrom(car,influenceIndexPlot)
importFrom(car,influencePlot)
importFrom(car,showLabels)
importFrom(grDevices,palette)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,box)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(graphics,text)
importFrom(heplots,Mahalanobis)
importFrom(heplots,trans.colors)
importFrom(stats,coef)
importFrom(stats,cooks.distance)
importFrom(stats,hatvalues)
importFrom(stats,influence)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,model.response)
importFrom(stats,qbeta)
importFrom(stats,qf)
importFrom(stats,residuals)
importFrom(stats,rstudent)
importFrom(utils,combn)
7 changes: 7 additions & 0 deletions NEWS
@@ -1,3 +1,10 @@
Version 0.9-0 (2022-09-10)

o Complete overhaul, using `roxygen2` for documentation
o Expand README, now with better examples
o Added package `vignette("uni-vs-multi")`
o Document the formulas used in calculations in `mvfluence-package.R`

Version 0.8-3 (2018-05-16)

o update mvinfluence-package.Rd using utils::promptPackage to conform to avoid hard-wired DESCRIPTION metadata
Expand Down
63 changes: 61 additions & 2 deletions R/Jfuns.R
Expand Up @@ -4,30 +4,89 @@
# These are simply experimental, probably not to be exported
##########################################################

#' General Classes of Influence Measures
#'
#' These functions implement the general classes of influence measures for
#' multivariate regression models defined in Barrett and Ling (1992), Eqn 2.3,
#' 2.4, as shown in their Table 1.
#'
#' There are two classes of functions, denoted \eqn{J_I^{det}} and \eqn{J_I^{tr}},
#' with parameters \eqn{n, p, q} of the data, \eqn{m} of the subset size
#' and \eqn{a} and \eqn{b} which define powers of terms in the formulas, typically
#' in the set \code{-2, -1, 0}.
#'
#' They are defined in terms of the submatrices for a deleted index subset
#' \eqn{I},
#' \deqn{H_I = X_I (X^T X)^{-1} X_I}
#' \deqn{Q_I = E_I (E^T E)^{-1} E_I}
#' corresponding to the hat and residual matrices in univariate models.
#'
#' For subset size \eqn{m = 1} these evaluate to scalar equivalents of hat
#' values and studentized residuals.
#'
#' For subset size \eqn{m > 1} these are \eqn{m \times m} matrices and
#' functions in the \eqn{J^{det}} class use \eqn{|H_I|} and \eqn{|Q_I|}, while
#' those in the \eqn{J^{tr}} class use \eqn{tr(H_I)} and \eqn{tr(Q_I)}.
#'
#' The functions \code{COOKD}, \code{COVRATIO}, and \code{DFFITS} implement
#' some of the standard influence measures in these terms for the general cases
#' of multivariate linear models and deletion of subsets of size \code{m>1},
#' but they have not yet been incorporated into our main functions
#' \code{\link{mlm.influence}} and \code{\link{influence.mlm}}.
#'
#' @aliases Jdet Jtr COOKD COVRATIO DFFITS
#' @param H a scalar or \eqn{m \times m} matrix giving the hat values for subset \eqn{I}
#' @param Q a scalar or \eqn{m \times m} matrix giving the residual values for subset \eqn{I}
#' @param a the \eqn{a} parameter for the \eqn{J^{det}} and \eqn{J^{tr}} classes
#' @param b the \eqn{b} parameter for the \eqn{J^{det}} and \eqn{J^{tr}} classes
#' @param f scaling factor for the \eqn{J^{det}} and \eqn{J^{tr}} classes
#' @return The scalar result of the computation.
#' @author Michael Friendly
#' @references Barrett, B. E. and Ling, R. F. (1992). General Classes of
#' Influence Measures for Multivariate Regression. \emph{Journal of the
#' American Statistical Association}, \bold{87}(417), 184-191.
#' @keywords array

#' J trace function
Jtr <- function (H, Q, a, b, f) {
I <- diag(nrow(H))
res <- H %*% Q %*% mpower(I-H-Q, a) %*% mpower(I-H, b)
f * tr(res)
}

#' J det function
#'
#' @rdname Jtr
Jdet <- function (H, Q, a, b, f) {
I <- diag(nrow(H))
res <- H %*% Q %*% mpower(I-H-Q, a) %*% mpower(I-H, b)
f * det(res)
}

# Cook D, in terms of Jtr()
#' Cook D, in terms of Jtr()
#'
#' @param n sample size
#' @param p number of predictor variables
#' @param r number of response variables
#' @param m deletion subset size
#' @rdname Jtr

COOKD <- function(H, Q, n, p, r, m) {
f <- (n-p)/p
Jtr(H, Q, 0, -2, f)
}

# DFFITS^2, in terms of Jtr()
#' DFFITS^2, in terms of Jtr()
#'
#' @rdname Jtr
DFFITS <- function(H, Q, n, p, r, m) {
f <- (n-p-m)/p
Jtr(H, Q, -1, 0, f)
}

#' COVRATIO, in terms of Jdet()
#' @rdname Jtr

COVRATIO <- function(H, Q, n, p, r, m) {
f <- ((n-p)/(n-p-m))^r*p
Jdet(H, Q, p, -(r+p), f)
Expand Down
17 changes: 17 additions & 0 deletions R/as.data.frame.inflmlm.R
@@ -1,3 +1,20 @@
#' Convert an inflmlm object to a data frame
#'
#' This function is used internally in the package to convert the result of \code{mlm.influence()} to a data frame.
#' It is not normally called by the user.
#'
#' @param x An \code{inflmlm} object, as returned by \code{mlm.influence}
#' @param ... ignored
#' @param FUN in the case where the subset size, \code{m>1}, the function used on the \code{H, Q, L, R} to calculate
#' a single statistic. The default is \code{det}. An alternative is \code{tr}, for matrix trace.
#' @param funnames logical. Should the \code{FUN} name be prepended to the statistics when creating a data frame?
#'
#' @return A data frame containing the influence statistics
#' @export
#'
#' @examples
#' # none
#'
as.data.frame.inflmlm <-
function(x, ..., FUN=det, funnames=TRUE) {
m <- x$m
Expand Down
33 changes: 33 additions & 0 deletions R/cooks.distance.mlm.R
@@ -1,3 +1,36 @@
#' Cook's distance for a MLM
#'
#' The functions \code{cooks.distance.mlm} and \code{hatvalues.mlm} are
#' designed as extractor functions for regression deletion diagnostics for
#' multivariate linear models following Barrett & Ling (1992). These are close
#' analogs of methods for univariate and generalized linear models handled by
#' the \code{\link[stats]{influence.measures}} in the \code{stats} package.
#'
#' In addition, the functions provide diagnostics for deletion of subsets of
#' observations of size \code{m>1}.
#'
#' @param model A \code{mlm} object, fit by \code{lm()}
#' @param infl A \code{inflmlm} object. The default simply runs \code{mlm.influence()} on the model, suppressing coefficients.
#' @param ... Ignored
#'
#' @importFrom stats cooks.distance hatvalues influence coef model.frame model.matrix
#' @return A vector of Cook's distances
#' @export
#' @references Barrett, B. E. and Ling, R. F. (1992). General Classes of
#' Influence Measures for Multivariate Regression. \emph{Journal of the
#' American Statistical Association}, \bold{87}(417), 184-191.
#' @keywords models regression
#'
#' @examples
#'
#' data(Rohwer, package="heplots")
#' Rohwer2 <- subset(Rohwer, subset=group==2)
#' rownames(Rohwer2)<- 1:nrow(Rohwer2)
#' Rohwer.mod <- lm(cbind(SAT, PPVT, Raven) ~ n+s+ns+na+ss, data=Rohwer2)
#'
#' hatvalues(Rohwer.mod)
#' cooks.distance(Rohwer.mod)
#'
cooks.distance.mlm <-
function (model, infl = mlm.influence(model, do.coef = FALSE), ...)
{
Expand Down
46 changes: 46 additions & 0 deletions R/data.R
@@ -0,0 +1,46 @@
#' Fertilizer Data
#'
#' A small data set on the use of fertilizer (x) in relation to the amount of
#' grain (y1) and straw (y2) produced.
#'
#' The first observation is an obvious outlier and influential observation.
#'
#' @name Fertilizer
#' @docType data
#' @format A data frame with 8 observations on the following 3 variables.
#' \describe{
#' \item{grain}{amount of grain produced}
#' \item{straw}{amount of straw produced}
#' \item{fertilizer}{amount of fertilizer applied} }
#' @references
#' Hossain, A. and Naik, D. N. (1989). Detection of influential
#' observations in multivariate regression.
#' \emph{Journal of Applied Statistics}, 16 (1), 25-37.
#' @source Anderson, T. W. (1984). \emph{An Introduction to Multivariate
#' Statistical Analysis}, New York: Wiley, p. 369.
#' @keywords datasets
#' @examples
#'
#' data(Fertilizer)
#'
#' # simple plots
#' plot(Fertilizer, col=c('red', rep("blue",7)),
#' cex=c(2,rep(1.2,7)),
#' pch=as.character(1:8))
#'
#' # A biplot shows the data in 2D. It gives another view of how case 1 stands out in data space
#' biplot(prcomp(Fertilizer))
#'
#' # fit the mlm
#' mod <- lm(cbind(grain, straw) ~ fertilizer, data=Fertilizer)
#' Anova(mod)
#'
#' # influence plots (m=1)
#' influencePlot(mod)
#' influencePlot(mod, type='LR')
#' influencePlot(mod, type='stres')
#'
#'
NULL


0 comments on commit dbd7cb3

Please sign in to comment.