From a30361f38f3eee23fc23a94c3ae492e93a21e0e6 Mon Sep 17 00:00:00 2001 From: Phil Chalmers Date: Thu, 19 Nov 2015 10:58:50 -0500 Subject: [PATCH] fix todo, and roxygenise --- DESCRIPTION | 4 +++- NAMESPACE | 2 +- R/LD.R | 12 +++++------- R/faoutlier.R | 30 +++++++++++++++--------------- man/GOF.Rd | 7 ++++--- man/LD.Rd | 7 ++++--- man/faoutlier.Rd | 2 +- man/forward.search.Rd | 7 ++++--- man/gCD.Rd | 5 +++-- man/holzinger.Rd | 2 +- man/holzinger.outlier.Rd | 2 +- man/obs.resid.Rd | 5 +++-- man/robustMD.Rd | 3 ++- man/setCluster.Rd | 3 ++- tests/testthat/test-LD.R | 18 +++++++++--------- 15 files changed, 58 insertions(+), 51 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index af6c1f0..fcd4c22 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,8 @@ Package: faoutlier Version: 0.5.1 Date: 2015-04-26 Type: Package -Title: Influential Case Detection Methods for Factor Analysis and Structural Equation Models +Title: Influential Case Detection Methods for Factor Analysis and Structural + Equation Models Authors@R: c( person("Phil", "Chalmers", email = "rphilip.chalmers@gmail.com", role = c("aut", "cre"))) @@ -27,3 +28,4 @@ LazyData: yes Repository: github License: GPL (>= 2) URL: https://github.com/philchalmers/faoutlier +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 843b98d..1cf1b97 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.1.1): do not edit by hand +# Generated by roxygen2: do not edit by hand S3method(plot,GOF) S3method(plot,LD) diff --git a/R/LD.R b/R/LD.R index c2d58d1..8643d0e 100644 --- a/R/LD.R +++ b/R/LD.R @@ -87,8 +87,8 @@ LD <- function(data, model, ...) Sigma <- res$loadings %*% t(res$loadings) + diag(res$uniquenesses) sum(dmvnorm(data, sigma=Sigma, log=TRUE)) } - f_sem <- function(ind, data, model, objective, ...){ - logLik(sem::sem(model, data=data[-ind, ], objective=objective, ...)) + f_sem <- function(ind, data, model, ...){ + logLik(sem::sem(model, data=data[-ind, ], ...)) } f_lavaan <- function(ind, data, model, ...){ lavaan::logLik(lavaan::sem(model, data=data[-ind, ], ...)) @@ -107,11 +107,9 @@ LD <- function(data, model, ...) MLmod <- f_numeric(nrow(data) + 1, data=data, model=model, ...) LR <- myApply(index, MARGIN=1L, FUN=f_numeric, data=data, model=model, ...) } else if(class(model) == "semmod"){ - stop('semmod objects under construction. Use GOF() for now instead') #TODO - objective <- if(any(is.na(data))) sem::objectiveFIML else sem::objectiveML - MLmod <- sem::sem(model, data=data, objective=objective, ...) - MLmod <- logLik(MLmod) ## TODO, this doesn't resolve correctly - LR <- myApply(index, MARGIN=1L, FUN=f_sem, data=data, model=model, objective=objective, ...) + MLmod <- sem::sem(model, data=data, ...) + MLmod <- logLik(MLmod) + LR <- myApply(index, MARGIN=1L, FUN=f_sem, data=data, model=model, ...) } else if(class(model) == "character"){ MLmod <- lavaan::sem(model, data=data, ...) MLmod <- lavaan::logLik(MLmod) diff --git a/R/faoutlier.R b/R/faoutlier.R index e45c0f7..0335690 100644 --- a/R/faoutlier.R +++ b/R/faoutlier.R @@ -1,10 +1,10 @@ #' Influential case detection methods for factor analysis and SEM -#' +#' #' Implements robust Mahalanobis methods, generalized Cook's distances, -#' likelihood ratio tests, model implied residuals, and various -#' graphical methods to help detect and summarize influential -#' cases that can affect exploratory and confirmatory factor analyses. -#' +#' likelihood ratio tests, model implied residuals, and various +#' graphical methods to help detect and summarize influential +#' cases that can affect exploratory and confirmatory factor analyses. +#' #' @name faoutlier #' @docType package #' @title Influential case detection methods for FA and SEM @@ -15,11 +15,11 @@ NULL #' Description of holzinger data -#' +#' #' A sample of 100 simulated cases from the infamous Holzinger dataset -#' using 9 variables. -#' -#' +#' using 9 variables. +#' +#' #' @name holzinger #' @docType data #' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com} @@ -27,13 +27,13 @@ NULL NULL #' Description of holzinger data with 1 outlier -#' +#' #' A sample of 100 simulated cases from the infamous Holzinger dataset -#' using 9 variables, but with 1 outlier added to the dataset. The first row was replaced -#' by adding 2 to five of the observed variables (odd-numbered items) and subtracting 2 from -#' the other four observed variables (even-numbered items). -#' -#' +#' using 9 variables, but with 1 outlier added to the dataset. The first row was replaced +#' by adding 2 to five of the observed variables (odd-numbered items) and subtracting 2 from +#' the other four observed variables (even-numbered items). +#' +#' #' @name holzinger.outlier #' @docType data #' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com} diff --git a/man/GOF.Rd b/man/GOF.Rd index 946b194..313d4dd 100644 --- a/man/GOF.Rd +++ b/man/GOF.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/GOF.R \name{GOF} \alias{GOF} @@ -53,6 +53,7 @@ can apply to nearly any model being studied where detection of influential observations is important. } \examples{ + \dontrun{ #run all GOF functions using multiple cores @@ -68,14 +69,14 @@ plot(GOFresult.outlier) #------------------------------------------------------------------- #Confirmatory with sem model <- sem::specifyModel() - F1 -> Remndrs, lam11 + F1 -> Remndrs, lam11 F1 -> SntComp, lam21 F1 -> WrdMean, lam31 F2 -> MissNum, lam42 F2 -> MxdArit, lam52 F2 -> OddWrds, lam62 F3 -> Boots, lam73 - F3 -> Gloves, lam83 + F3 -> Gloves, lam83 F3 -> Hatchts, lam93 F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 diff --git a/man/LD.Rd b/man/LD.Rd index 8ba3dd0..c680439 100644 --- a/man/LD.Rd +++ b/man/LD.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LD.R \name{LD} \alias{LD} @@ -52,6 +52,7 @@ can apply to nearly any model being studied where detection of influential observations is important. } \examples{ + \dontrun{ #run all LD functions using multiple cores @@ -67,14 +68,14 @@ plot(LDresult.outlier) #------------------------------------------------------------------- #Confirmatory with sem model <- sem::specifyModel() - F1 -> Remndrs, lam11 + F1 -> Remndrs, lam11 F1 -> SntComp, lam21 F1 -> WrdMean, lam31 F2 -> MissNum, lam42 F2 -> MxdArit, lam52 F2 -> OddWrds, lam62 F3 -> Boots, lam73 - F3 -> Gloves, lam83 + F3 -> Gloves, lam83 F3 -> Hatchts, lam93 F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 diff --git a/man/faoutlier.Rd b/man/faoutlier.Rd index c87c0f9..c0daeaf 100644 --- a/man/faoutlier.Rd +++ b/man/faoutlier.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/faoutlier.R \docType{package} \name{faoutlier} diff --git a/man/forward.search.Rd b/man/forward.search.Rd index 8fec465..f156964 100644 --- a/man/forward.search.Rd +++ b/man/forward.search.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/forward.search.R \name{forward.search} \alias{forward.search} @@ -64,6 +64,7 @@ can apply to nearly any model being studied where detection of influential observations is important. } \examples{ + \dontrun{ #run all internal gCD and GOF functions using multiple cores @@ -78,14 +79,14 @@ plot(FS.outlier) #Confirmatory with sem model <- sem::specifyModel() - F1 -> Remndrs, lam11 + F1 -> Remndrs, lam11 F1 -> SntComp, lam21 F1 -> WrdMean, lam31 F2 -> MissNum, lam41 F2 -> MxdArit, lam52 F2 -> OddWrds, lam62 F3 -> Boots, lam73 - F3 -> Gloves, lam83 + F3 -> Gloves, lam83 F3 -> Hatchts, lam93 F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 diff --git a/man/gCD.Rd b/man/gCD.Rd index 1ecb495..e3b8070 100644 --- a/man/gCD.Rd +++ b/man/gCD.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/gCD.R \name{gCD} \alias{gCD} @@ -48,6 +48,7 @@ can apply to nearly any model being studied where detection of influential observations is important. } \examples{ + \dontrun{ #run all gCD functions using multiple cores @@ -70,7 +71,7 @@ model <- sem::specifyModel() F2 -> MxdArit, lam52 F2 -> OddWrds, lam62 F3 -> Boots, lam73 - F3 -> Gloves, lam83 + F3 -> Gloves, lam83 F3 -> Hatchts, lam93 F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 diff --git a/man/holzinger.Rd b/man/holzinger.Rd index c1a71a6..e0e0f23 100644 --- a/man/holzinger.Rd +++ b/man/holzinger.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/faoutlier.R \docType{data} \name{holzinger} diff --git a/man/holzinger.outlier.Rd b/man/holzinger.outlier.Rd index 5c84f8f..d139fec 100644 --- a/man/holzinger.outlier.Rd +++ b/man/holzinger.outlier.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/faoutlier.R \docType{data} \name{holzinger.outlier} diff --git a/man/obs.resid.Rd b/man/obs.resid.Rd index 2a46a31..98509e5 100644 --- a/man/obs.resid.Rd +++ b/man/obs.resid.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/obs.resid.R \name{obs.resid} \alias{obs.resid} @@ -39,6 +39,7 @@ Compute model predicted residuals for each variable using regression estimated factor scores. } \examples{ + \dontrun{ data(holzinger) data(holzinger.outlier) @@ -60,7 +61,7 @@ model <- sem::specifyModel() F2 -> MxdArit, lam52 F2 -> OddWrds, lam62 F3 -> Boots, lam73 - F3 -> Gloves, lam83 + F3 -> Gloves, lam83 F3 -> Hatchts, lam93 F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 diff --git a/man/robustMD.Rd b/man/robustMD.Rd index aa181a2..009be16 100644 --- a/man/robustMD.Rd +++ b/man/robustMD.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/robustMD.R \name{robustMD} \alias{plot.robmah} @@ -38,6 +38,7 @@ computing methods found in the \code{MASS} package. This function is generally o to models with continuous variables. } \examples{ + \dontrun{ data(holzinger) output <- robustMD(holzinger) diff --git a/man/setCluster.Rd b/man/setCluster.Rd index 233f5c5..cbbba16 100644 --- a/man/setCluster.Rd +++ b/man/setCluster.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/setClusters.R \name{setCluster} \alias{setCluster} @@ -21,6 +21,7 @@ if you are defining other parallel objects (for simulation desings, for example) to define a cluster. } \examples{ + \dontrun{ #make 4 cores available for parallel computing diff --git a/tests/testthat/test-LD.R b/tests/testthat/test-LD.R index fc31826..548b458 100644 --- a/tests/testthat/test-LD.R +++ b/tests/testthat/test-LD.R @@ -14,15 +14,15 @@ test_that('LD run', { expect_is(plot(LDresult.outlier), 'trellis') #------------------------------------------------------------------- -# suppressMessages(model <- sem::specifyModel(file='sem-model/sem-model.txt', quiet=TRUE)) -# LDresult <- LD(holzinger, model) -# LDresult.outlier <- LD(holzinger.outlier, model) -# expect_equal(as.numeric(LDresult[1:3]), c(-4.945440, -1.943843, -3.330193), -# tolerance=1e-5) -# expect_is(LDresult, 'LD') -# expect_is(LDresult.outlier, 'LD') -# expect_is(plot(LDresult), 'trellis') -# expect_is(plot(LDresult.outlier), 'trellis') + suppressMessages(model <- sem::specifyModel(file='sem-model/sem-model.txt', quiet=TRUE)) + LDresult <- LD(holzinger, model) + LDresult.outlier <- LD(holzinger.outlier, model) + expect_equal(as.numeric(LDresult[1:3]), c(-4.945440, -1.943843, -3.330193), + tolerance=1e-5) + expect_is(LDresult, 'LD') + expect_is(LDresult.outlier, 'LD') + expect_is(plot(LDresult), 'trellis') + expect_is(plot(LDresult.outlier), 'trellis') #------------------------------------------------------------------- #Confirmatory with lavaan