FAiR (version 0.2-0)

S4GenericsFAiR: S4 Generic Functions and Methods for Package `FAiR'

Description

It is not necessary to understand this help page if one merely wants to estimate a factor analysis model. This help page is intended for those who want to modify or extend FAiR or otherwise want some idea of how FAiR works ``behind the scenes''. These generic functions are used to create starting values for, estimate, and encapsulate the results of a factor analysis model that is estimated by Factanal. The various methods for these models pertain to different types of factor analysis models.

Usage

fitS4(par, object, ...)
bfgs_fitS4(par, object, helper, ...)
gr_fitS4(par, object, helper, ...)
bfgs_helpS4(initial, object, done, ...)
create_start(restrictions, ...)
create_FAobject(restrictions, ...)

Arguments

par
A numeric vector containing values for all the free or parameters to be estimated, which corresponds to the par argument for genoud and for
initial
Same as par.
object
In FAiR, this object is always inherits from class "restrictions", see restrictions-class.
helper
An object, typically a list that contains necessary information for the bfgs_fitS4 and gr_fitS4 methods as documented in genoud.
done
A logical indicating whether the optimization has terminated or could terminate immediately if a stopping condition is met.
restrictions
An object of that inherits from class "restrictions", see restrictions-class.
...
Further arguments to be passed to downstream functions

Value

  • fitS4produces a numeric vector
  • bfgs_fitS4produces a numeric scalar
  • gr_fitS4produces a numeric vector
  • bfgs_helpS4typically produces a list
  • create_startproduces a numeric matrix
  • create_FAobjectproduces an object that is or inherits from class "FA"

Methods

See the examples below. The essential concept is that the estimation behavior depends on object and restrictions which is an object of a class that inherits from the "restrictions" superclass. See also restrictions-class.

Details

None of these S4 generic functions have default methods; any additional methods must be tailored to the specific factor analysis model being estimated.

The fitS4 method is the function for which the optimal par is sought and produces a numeric vector of fit criteria. This method is passed to the fn argument of genoud for lexical optimization. Thus, the last element of this vector should be fully continuous so that all ties are broken among unique individuals in the population of the genetic algorithm. For example, the last element is the value of the log-likelihood function when method = "MLE" is specified in the call to Factanal.

Lexical optimization can be seen as optimization with respect to the last criterion produced by the fitS4 method among indiivduals in the population of the genetic algorithm with the same values on all previous criteria produced by the fitS4 method. Thus, previous elements of this vector of criteria are values of constraint criteria and by convention are operationalized as piecewise functions of par that take the value of 1.0 if the constraint is satisfied and some value less than 1.0 when the constraint is not satisfied. For example, the constraint that prevents Heywood cases takes the value of 1.0 when all specific variances are positive and takes the value of the minimum specific variance otherwise. In FAiR, fitS4 is supplied with an additional argument, S, which is the sample correlation matrix among outcomes.

The bfgs_fitS4 method produces a scalar fit criterion, and this method is passed to the BFGSfn argument of genoud and is in turned passed to the fn argument of optim. Usually, this criterion is the last criterion produced by the fitS4 method, such as the log-likelihood. The gr_fitS4 method produces the gradient of the function defined by the bfgs_fitS4 method, and this method is passed to the gr argument of genoud and optim. Both bfgs_fitS4 and gr_fitS4 take an argument called helper, which is produced by the bfgs_helpS4 method and corresponds to the BFGShelp argument of genoud. The BFGShelp method typically produces a list that contains information about the initial value of the individual when optim is called. In FAiR, the bfgs_fitS4 methods and gr_fitS4 methods behave differently depending on the contents of helper. In FAiR, each of these methods are supplied with an additional argument, S, which is the sample correlation matrix among outcomes. The create_start method creates a matrix of starting values that is then passed to the starting.values argument of genoud. If you think the starting values are inadequate in a particular situation, it is much easier to create a matrix of starting values in the global environment and pass it through the ... of Factanal to the starting.values argument of genoud yourself. See Factanal for details on doing so. It is only necessary to write a create_start method when extending the restrictions-class to implement a new kind of factor analysis model. In FAiR, the create_start method is supplied with additional arguments: pop.size, which corresponds to the argument of the same name in genoud and indicates how many starting vectors to create; start which is a one-column matrix containing the initially estimated communalities for the outcomes; and S, which is the sample correlation matrix among the outcome variables.

Finally, the create_FAobject takes the output of genoud and produces an object of class "FA" or an object that inherits from class "FA". In FAiR, the create_FAobject method is supplied with additional arguments: opt, which is the list produced by genoud; manifest, which is a list containing the sample covariance matrix, sample correlation matrix, and the number of observations in the sampe; and call, which is the call to Factanal.

To summarize, in order to write a new method for FAiR, create a new class that inherits from restrictions-class. Write a fitS4 method for this new class that calculates all criteria that you want to find the lexical optimum of, given par, this object, and S. Write a bfgs_fitS4 method to calculate some scalar criterion. The bfgs_fitS4 method would typically reuse a lot of code from the fitS4 method or, in the case of all bfgs_fitS4 methods currently implemented in FAiR, simply calls the fit_S4 method and selects the first value of the vector that is not equal to $1.0$. Write a gr_fitS4 method that calculates the gradient of the bfgs_fitS4 method at par, which will also reuse a lot of code from the fitS4 method. If you want to do anything fancy with the bfgs_fitS4 and gr_fitS4 methods write a bfgs_helpS4 method that evaluates the fitS4 method at initial and passes the result to the bfgs_fitS4 and gr_fitS4 methods via their helper argument. Finally, write a create_FAobject method that produces an object of class "FA" or that inherits from class "FA" (in which case you would need to define that class and at least write summary methods for it). It is recommended to also write a create_start method that creates starting values in light of the fitS4 method. Starting values should ideally be widely dispersed throughout the subset of the parameter space where all of the constraints are satisfied. For each of these methods, the existing methods in FAiR provide a good template to start from.

See Also

Factanal, restrictions-class and genoud

Examples

Run this code
showMethods("fitS4")
  showMethods("bfgs_fitS4")
  showMethods("gr_fitS4")
  showMethods("bfgs_helpS4")
  showMethods("create_start")
  showMethods("create_FAobject")

Run the code above in your browser using DataLab