Skip to content

Commit

Permalink
fix todo, and roxygenise
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Nov 19, 2015
1 parent 2e3b9d0 commit a30361f
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 51 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]", role = c("aut", "cre")))
Expand All @@ -27,3 +28,4 @@ LazyData: yes
Repository: github
License: GPL (>= 2)
URL: https://github.com/philchalmers/faoutlier
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 5 additions & 7 deletions R/LD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ], ...))
Expand All @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions R/faoutlier.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,25 +15,25 @@
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}
#' @keywords data
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}
Expand Down
7 changes: 4 additions & 3 deletions man/GOF.Rd

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

7 changes: 4 additions & 3 deletions man/LD.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/faoutlier.Rd

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

7 changes: 4 additions & 3 deletions man/forward.search.Rd

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

5 changes: 3 additions & 2 deletions man/gCD.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/holzinger.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/holzinger.outlier.Rd

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

5 changes: 3 additions & 2 deletions man/obs.resid.Rd

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

3 changes: 2 additions & 1 deletion man/robustMD.Rd

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

3 changes: 2 additions & 1 deletion man/setCluster.Rd

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

18 changes: 9 additions & 9 deletions tests/testthat/test-LD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a30361f

Please sign in to comment.