Skip to content

Commit a31b63e

Browse files
Merge pull request #9 from AnthonyRaborn/bugfix
Bugfix
2 parents c9f38db + 52bdbda commit a31b63e

15 files changed

+224
-58
lines changed

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: ShortForm
22
Type: Package
33
Title: Automatic Short Form Creation
4-
Version: 0.4.4
5-
Date: 2019-10-9
4+
Version: 0.4.5
5+
Date: 2020-02-24
66
Authors@R: c(person("Anthony", "Raborn", email = "anthony.w.raborn@gmail.com", role = c("aut", "cre")), person("Walter", "Leite", email = "Walter.Leite@coe.ufl.edu", role = "aut"))
77
Description: Performs automatic creation of short forms of scales with an
88
ant colony optimization algorithm and a Tabu search. As implemented in the
@@ -19,7 +19,7 @@ Description: Performs automatic creation of short forms of scales with an
1919
<doi:10.1080/10705511.2017.1409074> for an applied example of the Tabu search.
2020
License: LGPL (>= 2.0, < 3) | Mozilla Public License
2121
LazyData: TRUE
22-
RoxygenNote: 6.1.1
22+
RoxygenNote: 7.0.2
2323
Suggests:
2424
knitr,
2525
MplusAutomation (>= 0.7),
@@ -31,7 +31,6 @@ Imports:
3131
stringr
3232
Depends:
3333
R (>= 3.0.0)
34-
Roxygen: list(wrap = FALSE)
3534
URL: https://github.com/AnthonyRaborn/ShortForm
3635
BugReports: https://github.com/AnthonyRaborn/ShortForm/issues
3736
Encoding: UTF-8

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Package v0.4.5
2+
## Extra arugment checks
3+
* There are now additional checks for the function arguments related to the fit statistics (ACO, SA) and the fit statistic tests (ACO) with informative warnings for when the function arguments are not valid.
4+
15
# Package v0.4.2
26
## Introduction of Function Classes
37
* This version introduces classes to each of the main function outputs (`antcolony.lavaan` == "antcolony", `simulatedAnnealing` == "simulatedAnnealing", `tabuShortForm` == "tabu")

R/ACO_lavaan.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ antcolony.lavaan = function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
213213
if(!requireNamespace("lavaan", quietly = TRUE)){
214214
stop("The `lavaan` package is required to use this function. Please install `lavaan`, then try to use this function again.")
215215
}
216-
216+
fitmeasuresCheck(fit.indices)
217+
fitStatTestCheck(fit.indices, fit.statistics.test)
217218
antcolony.lavaan.env <- new.env(parent = baseenv())
218219

219220
if(pheromone.calculation %in% c("gamma", "beta", "regression", "variance") == FALSE) {
@@ -264,6 +265,7 @@ antcolony.lavaan = function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
264265
step = 1
265266

266267
# creates objects in the global environment that are fed into the lavaan function in order to fine-tune the model to user specifications
268+
checkModelSpecs(lavaan.model.specs)
267269
mapply(assign, names(lavaan.model.specs), lavaan.model.specs, MoreArgs=list(envir = antcolony.lavaan.env))
268270

269271
# create the function to check for and save error/warning messages within the lavaan output, as well as saving the fit indices

R/Tabu_shortform.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ tabuShortForm <-
6060
estimator = "default"
6161
),
6262
bifactor = FALSE) {
63+
checkModelSpecs(lavaan.model.specs)
6364
mapply(
6465
assign,
6566
names(lavaan.model.specs),

R/simulated_annealing.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ simulatedAnnealing <-
9393
currentStep = 0
9494
consecutive = 0
9595
allFit = c()
96-
96+
fitmeasuresCheck(fitStatistic)
9797
# creates objects in the function environment that are fed into the lavaan function in order to fine-tune the model to user specifications
9898
# solution from: https://stackoverflow.com/questions/6375790/r-creating-an-environment-in-the-globalenv-from-inside-a-function
9999
# makeCache <- function() {
100100
# # list(get = function(key) cache[[key]],
101101
# # set = function(key, value) cache[[key]] <- value
102102
# # )
103103
# }
104-
104+
checkModelSpecs(lavaan.model.specs)
105105
mapply(
106106
assign,
107107
names(lavaan.model.specs),

R/simulated_annealing_internals.R

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,104 @@ fitWarningCheck <- function(expr, maximize) {
197197
)
198198
return(value)
199199
}
200+
201+
202+
checkModelSpecs <-
203+
function(
204+
x
205+
) {
206+
207+
requiredElements <-
208+
c('model.type',
209+
'auto.var',
210+
'estimator',
211+
'ordered',
212+
'int.ov.free',
213+
'int.lv.free',
214+
'auto.fix.first',
215+
'auto.fix.single',
216+
'auto.cov.lv.x',
217+
'auto.th',
218+
'auto.delta',
219+
'auto.cov.y',
220+
'std.lv')
221+
222+
missingSpecs <-
223+
requiredElements[
224+
which(
225+
!requiredElements %in% names(x)
226+
)
227+
]
228+
229+
if (length(missingSpecs) > 0) {
230+
errorMessage <-
231+
paste0("The following elements of lavaan.model.specs have not been specified:\n\n",
232+
paste(missingSpecs, collapse = "\n"),
233+
"\n\nPlease include the proper specifications for these elements, or use the default values provided.")
234+
stop(errorMessage)
235+
}
236+
}
237+
238+
fitmeasuresCheck <-
239+
function(
240+
x
241+
) {
242+
validMeasures <-
243+
c(
244+
"npar", "fmin",
245+
"chisq", "df", "pvalue",
246+
"baseline.chisq", "baseline.df", "baseline.pvalue",
247+
"cfi", "tli", "nnfi",
248+
"rfi", "nfi", "pnfi",
249+
"ifi", "rni",
250+
"logl", "unrestricted.logl",
251+
"aic", "bic", "ntotal", "bic2",
252+
"rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "rmsea.pvalue",
253+
"rmr", "rmr_nomean",
254+
"srmr", "srmr_bentler", "srmr_bentler_nomean",
255+
"crmr", "crmr_nomean", "srmr_mplus", "srmr_mplus_nomean",
256+
"cn_05", "cn_01",
257+
"gfi", "agfi", "pgfi", "mfi", "ecvi"
258+
)
259+
260+
invalidMeasures <-
261+
x[
262+
which(
263+
!x %in% validMeasures
264+
)
265+
]
266+
267+
if (length(invalidMeasures) > 0) {
268+
errorMessage <-
269+
paste0("The following elements of fit.indices or fitStatistics are not valid fit measures provided by the lavaan::fitmeasures function:\n\n",
270+
paste(invalidMeasures, collapse = "\n"),
271+
"\n\nPlease check the output of this function for proper spelling and capitalization of the fit measure(s) you are interested in.")
272+
stop(errorMessage)
273+
}
274+
275+
}
276+
277+
fitStatTestCheck <-
278+
function(measures, test) {
279+
tempEnv <-
280+
new.env()
281+
mapply(
282+
assign,
283+
measures,
284+
0,
285+
MoreArgs=list(envir = tempEnv))
286+
287+
checkIfEval <-
288+
tryCatch(
289+
expr = eval(parse(text=test),
290+
envir = tempEnv),
291+
error = function(e) {
292+
stop("There was a problem with the fit.statistics.test provided. It cannot be evaluated properly. Please read the function documentation to see how to properly specify a test.")
293+
}
294+
)
295+
296+
if (!is.character(test)) {
297+
stop("There is a problem with the fit.statistics.test provided. The fit.statistics.test was given as a logical, not a character. Please read the function documentation to see how to properly specify a test. ")
298+
}
299+
300+
}

cran-comments.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
## Resubmission
2-
This is a resubmission. In this version I have fixed a bug that caused the lavaan-based functions to improperly use the initial model syntax instead of building the intermediate model syntax when the initial model syntax was specified in an untested manner.
2+
This is a resubmission. In this version I have included three checks to function arguments that will give informative errors if the user misspecifies the arguments.
33

44
## Test Environments
55

6-
* local Windows 10 Enterprise install, R 3.6.1
6+
* local Windows 10 Home install, R 3.6.2
77

88
* Ubuntu 16.04.5 LTS xenial (travis ci), R 3.6.1
99

10+
* r-hub and win_check
11+
1012
## R CMD check results
1113
0 errors | 0 warnings | 0 notes
1214

man/ShortForm.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/add.param.Rd

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/antcolony.lavaan.Rd

Lines changed: 26 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)