Skip to content

Commit

Permalink
Renamed lcMetaConverged to lcFitConverged (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdt committed Nov 4, 2022
1 parent 3401fd2 commit fd7e404
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 172 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Collate:
'matrix.R'
'method.R'
'meta-method.R'
'meta-method-converged.R'
'meta-fit-converged.R'
'methodMatrix.R'
'methodAKMedoids.R'
'methodCrimCV.R'
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export(latrendBatch)
export(latrendBoot)
export(latrendCV)
export(latrendRep)
export(lcMetaConverged)
export(lcFitConverged)
export(lcMethodAkmedoids)
export(lcMethodCrimCV)
export(lcMethodDtwclust)
Expand Down Expand Up @@ -174,7 +174,7 @@ export(validate)
export(weighted.meanNA)
export(which.weight)
exportClasses(lcApproxModel)
exportClasses(lcMetaConverged)
exportClasses(lcFitConverged)
exportClasses(lcMetaMethod)
exportClasses(lcMethod)
exportClasses(lcModel)
Expand Down
25 changes: 15 additions & 10 deletions R/meta-method-converged.R → R/meta-fit-converged.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
#' @include meta-method.R

#' @export
#' @rdname lcMetaMethods
#' @name lcFitMethods
#' @rdname lcFitMethods
#' @title Method fit modifiers
#' @description A collection of special methods that adapt the fitting procedure of the underlying longitudinal cluster method.
#' Supported fit methods:
#' * `lcFitConverged`: Fit a method until a converged result is obtained.
#' @examples
#' data(latrendData)
#' method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time", nClusters = 2)
#' metaMethod <- lcMetaConverged(method, maxRep = 10)
#' metaMethod <- lcFitConverged(method, maxRep = 10)
#' metaMethod
#' model <- latrend(metaMethod, latrendData)
setClass('lcMetaConverged', contains = 'lcMetaMethod')
setClass('lcFitConverged', contains = 'lcMetaMethod')

#' @export
#' @rdname lcMetaMethods
#' @rdname lcFitMethods
#' @param method The `lcMethod` to use for fitting.
#' @param maxRep The maximum number of fit attempts
lcMetaConverged = function(method, maxRep = Inf) {
lcFitConverged = function(method, maxRep = Inf) {
mc = match.call.all()
mc$method = getCall(method)
mc$Class = 'lcMetaConverged'
mc$Class = 'lcFitConverged'
do.call(new, as.list(mc))
}


#' @rdname lcMetaMethod-interface
setMethod('fit', 'lcMetaConverged', function(method, data, envir, verbose) {
#' @rdname interface-metaMethods
setMethod('fit', 'lcFitConverged', function(method, data, envir, verbose) {
attempt = 1L

repeat {
Expand Down Expand Up @@ -61,8 +66,8 @@ setMethod('fit', 'lcMetaConverged', function(method, data, envir, verbose) {
}
})

#' @rdname lcMetaMethod-interface
setMethod('validate', 'lcMetaConverged', function(method, data, envir = NULL, ...) {
#' @rdname interface-metaMethods
setMethod('validate', 'lcFitConverged', function(method, data, envir = NULL, ...) {
callNextMethod()

validate_that(
Expand Down
34 changes: 15 additions & 19 deletions R/meta-method.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#' @include method.R

#' @export
#' @name lcMetaMethods
#' @rdname lcMetaMethods
#' @name interface-metaMethods
#' @rdname interface-metaMethods
#' @aliases lcMetaMethod-class
#' @title Meta methods
#' @description `lcMetaMethod` classes are used to specify a repeated or adjusted fitting approach for the given longitudinal cluster method.
#' Supported meta methods:
#' * `lcMetaMethodConverged`: Fit a method until a converged result is obtained.
#' @title lcMetaMethod abstract class
#' @description Virtual class for internal use. Do not use.
setClass(
'lcMetaMethod',
contains = c('lcMethod', 'VIRTUAL')
Expand All @@ -23,59 +21,57 @@ as.character.lcMetaMethod = function(x, ...) {
}

#' @export
#' @name lcMetaMethod-interface
#' @rdname lcMetaMethod-interface
#' @title lcMetaMethod methods
#' @rdname interface-metaMethods
setMethod('compose', 'lcMetaMethod', function(method, envir = NULL) {
newMethod = method
newMethod@arguments$method = evaluate.lcMethod(getLcMethod(method), try = FALSE, envir = envir)
newMethod
})

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('getLcMethod', 'lcMetaMethod', function(object, ...) object$method)

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('getName', 'lcMetaMethod', function(object, ...) getName(getLcMethod(object), ...))

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('getShortName', 'lcMetaMethod', function(object, ...) getShortName(getLcMethod(object), ...))

#' @export
#' @rdname idVariable
#' @rdname interface-metaMethods
setMethod('idVariable', 'lcMetaMethod', function(object, ...) idVariable(getLcMethod(object), ...))

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('preFit', 'lcMetaMethod', function(method, data, envir, verbose) {
preFit(getLcMethod(method), data = data, envir = envir, verbose = verbose)
})

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('prepareData', 'lcMetaMethod', function(method, data, verbose) {
prepareData(getLcMethod(method), data = data, verbose = verbose)
})

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('postFit', 'lcMetaMethod', function(method, data, model, envir, verbose) {
postFit(getLcMethod(method), data = data, model = model, envir = envir, verbose = verbose)
})

#' @export
#' @rdname responseVariable
#' @rdname interface-metaMethods
setMethod('responseVariable', 'lcMetaMethod', function(object, ...) responseVariable(getLcMethod(object), ...))

#' @export
#' @rdname timeVariable
#' @rdname interface-metaMethods
setMethod('timeVariable', 'lcMetaMethod', function(object, ...) timeVariable(getLcMethod(object), ...))

#' @export
#' @rdname lcMetaMethod-interface
#' @rdname interface-metaMethods
setMethod('validate', 'lcMetaMethod', function(method, data, envir = NULL, ...) {
validate(getLcMethod(method), data = data, envir = envir, ...)
})
Empty file added lcFitMethods.Rd
Empty file.
5 changes: 1 addition & 4 deletions man/idVariable.Rd

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

30 changes: 21 additions & 9 deletions man/lcMetaMethod-interface.Rd → man/interface-metaMethods.Rd

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

29 changes: 29 additions & 0 deletions man/lcFitMethods.Rd

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

31 changes: 0 additions & 31 deletions man/lcMetaMethods.Rd

This file was deleted.

5 changes: 1 addition & 4 deletions man/responseVariable.Rd

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

5 changes: 1 addition & 4 deletions man/timeVariable.Rd

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

Loading

0 comments on commit fd7e404

Please sign in to comment.