Learn R Programming

latrend (version 1.5.0)

fit: lcMethod fit process: logic for fitting the method to the processed data

Description

Note: this function should not be called directly, as it is part of the lcMethod fitting process. For fitting an lcMethod object to a dataset, see latrend().

The fit() function of the lcMethod object estimates the model with the evaluated method specification, processed training data, and prepared environment.

Usage

# S4 method for lcMethod
fit(method, data, envir, verbose)

Value

The fitted object inheriting from lcModel.

Arguments

method

An object inheriting from lcMethod with all its arguments having been evaluated and finalized.

data

A data.frame representing the transformed training data.

envir

The environment containing variables generated by prepareData() and preFit().

verbose

A R.utils::Verbose object indicating the level of verbosity.

Implementation

This method should be implemented for all lcMethod subclasses.


setMethod("fit", "lcMethodExample", function(method, data, envir, verbose) {
  # estimate the model or cluster parameters
  coefs <- FIT_CODE

# create the lcModel object new("lcModelExample", method = method, data = data, model = coefs, clusterNames = make.clusterNames(method$nClusters) ) })

Fitting procedure

Each lcMethod subclass defines a type of methods in terms of a series of steps for estimating the method. These steps, as part of the fitting procedure, are executed by latrend() in the following order:

  1. compose(): Evaluate and finalize the method argument values.

  2. validate(): Check the validity of the method argument values in relation to the dataset.

  3. prepareData(): Process the training data for fitting.

  4. preFit(): Prepare environment for estimation, independent of training data.

  5. fit(): Estimate the specified method on the training data, outputting an object inheriting from lcModel.

  6. postFit(): Post-process the outputted lcModel object.

The result of the fitting procedure is an lcModel object that inherits from the lcModel class.