Title: | Object Oriented Solution for Robust Factor Analysis |
---|---|
Description: | Outliers virtually exist in any datasets of any application field. To avoid the impact of outliers, we need to use robust estimators. Classical estimators of multivariate mean and covariance matrix are the sample mean and the sample covariance matrix. Outliers will affect the sample mean and the sample covariance matrix, and thus they will affect the classical factor analysis which depends on the classical estimators (Pison, G., Rousseeuw, P.J., Filzmoser, P. and Croux, C. (2003) <doi:10.1016/S0047-259X(02)00007-6>). So it is necessary to use the robust estimators of the sample mean and the sample covariance matrix. There are several robust estimators in the literature: Minimum Covariance Determinant estimator, Orthogonalized Gnanadesikan-Kettenring, Minimum Volume Ellipsoid, M, S, and Stahel-Donoho. The most direct way to make multivariate analysis more robust is to replace the sample mean and the sample covariance matrix of the classical estimators to robust estimators (Maronna, R.A., Martin, D. and Yohai, V. (2006) <doi:10.1002/0470010940>) (Todorov, V. and Filzmoser, P. (2009) <doi:10.18637/jss.v032.i03>), which is our choice of robust factor analysis. We created an object oriented solution for robust factor analysis based on new S4 classes. |
Authors: | Frederic Bertrand [cre]
|
Maintainer: | Frederic Bertrand <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1-0 |
Built: | 2025-03-07 03:03:43 UTC |
Source: | https://github.com/cran/robustfa |
Outliers virtually exist in any datasets of any application field. To avoid the impact of outliers, we need to use robust estimators. Classical estimators of multivariate mean and covariance matrix are the sample mean and the sample covariance matrix. Outliers will affect the sample mean and the sample covariance matrix, and thus they will affect the classical factor analysis which depends on the classical estimators (Pison, G., Rousseeuw, P.J., Filzmoser, P. and Croux, C. (2003) doi:10.1016/S0047-259X(02)00007-6). So it is necessary to use the robust estimators of the sample mean and the sample covariance matrix. There are several robust estimators in the literature: MCD, OGK, MVE, M, S, and Stahel-Donoho. The most direct way to robustify multivariate anal-ysis is to replace the sample mean and the sample covariance matrix of the classical estimators to robust estima-tors (Maronna, R.A., Martin, D. and Yohai, V. (2006) doi:10.1002/0470010940) (Todorov, V. and Filzmoser, P. (2009) doi:10.18637/jss.v032.i03), which is our choice of robust factor analysis. robustfa is an object oriented solution for robust factor analysis. In the solution, new S4 classes "Fa"
, "FaClassic"
, "FaRobust"
, "FaCov"
, "SummaryFa"
are created.
Package: | robustfa |
Type: | Package |
Version: | 1.0-5 |
Date: | 2013-11-09 |
License: | GPL (>= 2) |
Depends: | methods |
The most important functions are:
FaClassic
, FaCov
, factorScorePca
, factorScorePfa
Ying-Ying Zhang (Robert)
Maintainer: Ying-Ying Zhang (Robert) <[email protected]>
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
library("robustfa")
library("robustfa")
Compute the robust covariance and correlation matrix of a numeric matrix. The function is used to check whether S_r != S_r_tilda and R_r == R_r_tilda?
compute_cov_cor(x, control)
compute_cov_cor(x, control)
x |
A numeric matrix or an object that can be coerced to a numeric matrix. |
control |
A control object (S4) for one of the available control classes, e.g. |
A list with the following components:
S_r |
The robust covariance matrix of cov_x. |
S_r_tilda |
The robust covariance matrix of cov_scale_x. |
R_r |
The robust correlation matrix of cov_x. |
R_r_tilda |
The robust correlation matrix of cov_scale_x. |
cov_x = rrcov::CovRobust(x = x, control = control) cov_scale_x = rrcov::CovRobust(x = scale(x), control = control)
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] compute_cov_cor(x = hbk.x, control = "mcd")
data("hbk") hbk.x = hbk[,1:3] compute_cov_cor(x = hbk.x, control = "mcd")
Compute factor scores on the result of factor analysis method, the method is one of "mle", "pca", and "pfa".
computeScores(out, x = data, covmat = covmat, cor = cor, scoresMethod = scoresMethod)
computeScores(out, x = data, covmat = covmat, cor = cor, scoresMethod = scoresMethod)
out |
The result of factorScorePca(), factorScorePfa(), or factanal(). It is a list. |
x |
A numeric matrix. |
covmat |
A list with components: cov, center, and n.obs. |
cor |
A logical value indicating whether the calculation should use the covariance matrix ( |
scoresMethod |
Type of scores to produce, if any. The default is |
The output is a list. Except for the components of out
, it also has components:
scoringCoef |
The scoring coefficients. |
scores |
The matrix of scores. |
meanF |
The sample mean of the scores. |
corF |
The sample correlation matrix of the scores. |
eigenvalues |
The eigenvalues of the running matrix. |
covariance |
The covariance matrix. |
correlation |
The correlation matrix. |
usedMatrix |
The used matrix (running matrix) to compute |
reducedCorrelation |
NULL. The reduced correlation matrix, reducedCorrelation is calculated in factorScorePfa.R. |
scoringCoef = F = meanF = corF = NULL if scoresMethod = "none"
.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("stock611") stock604 = stock611[-c(92,2,337,338,379,539,79), ] data = as.matrix(stock604[, 3:12]) factors = 2 cor = TRUE scoresMethod = "regression" covx = rrcov::Cov(data) covmat = list(cov = rrcov::getCov(covx), center = rrcov::getCenter(covx), n.obs = [email protected]) out = stats::factanal(factors = factors, covmat = covmat) out = computeScores(out, x = data, covmat = covmat, cor = cor, scoresMethod = scoresMethod) out
data("stock611") stock604 = stock611[-c(92,2,337,338,379,539,79), ] data = as.matrix(stock604[, 3:12]) factors = 2 cor = TRUE scoresMethod = "regression" covx = rrcov::Cov(data) covmat = list(cov = rrcov::getCov(covx), center = rrcov::getCenter(covx), n.obs = covx@n.obs) out = stats::factanal(factors = factors, covmat = covmat) out = computeScores(out, x = data, covmat = covmat, cor = cor, scoresMethod = scoresMethod) out
Show details of an object.
detail(x)
detail(x)
x |
Any |
A list with components:
x |
The argument |
isS4 |
Logical, indicates whether |
isObject |
Logical, indicates whether |
class |
The class of |
attributes |
The attributes of |
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
isS4
, is.object
, class
, attributes
data(stock611) detail(stock611) facovRegOgk=FaCov(x=scale(stock611[,3:12]), factors=3, cov.control = rrcov::CovControlOgk(), scoresMethod = "regression"); facovRegOgk detail(facovRegOgk)
data(stock611) detail(stock611) facovRegOgk=FaCov(x=scale(stock611[,3:12]), factors=3, cov.control = rrcov::CovControlOgk(), scoresMethod = "regression"); facovRegOgk detail(facovRegOgk)
"Fa"
Class "Fa"
is a virtual base class for all classical and robust FA classes. "Fa"
searves as a base class for deriving all other classes representing the results of the classical and robust Factor Analysis methods.
A virtual Class: No objects may be created from it.
call
:Object of class "language"
an unevaluated function call.
converged
:Object of class "Ulogical"
a logical character indicates whether the iterations converged.
loadings
:Object of class "matrix"
the matrix of variable loadings.
communality
:Object of class "Uvector"
the communality.
uniquenesses
:Object of class "vector"
the uniquenesses computed.
cor
:Object of class "Ulogical"
A logical value indicating whether the calculation should use the covariance matrix (cor = FALSE
) or the correlation matrix (cor = TRUE
).
covariance
:Object of class "matrix"
The robust/classical covariance matrix.
correlation
:Object of class "matrix"
The robust/classical correlation matrix.
usedMatrix
:Object of class "matrix"
The used matrix (running matrix). It may be the covariance or correlation matrix according to the value of cor
.
reducedCorrelation
:Object of class "Umatrix"
The last reduced correlation matrix. reducedCorrelation is only calculated in factorScorePfa.R.
criteria
:Object of class "Unumeric"
. The results of the optimization: the value of the negative log-likelihood and information on the iterations used.
factors
:Object of class "numeric"
the number of factors.
dof
:Object of class "Unumeric"
. The number of degrees of freedom of the factor analysis model.
method
:Object of class "character"
. The method: one of "mle", "pca", and "pfa".
scores
:Object of class "Umatrix"
. If requested, a matrix of scores.
scoresMethod
:Object of class "character"
. The scores method: one of "none", "regression", and "Bartlett".
scoringCoef
:Object of class "Umatrix"
the matrix of scoring coefficients.
meanF
:Object of class "Uvector"
the column means of scores.
corF
:Object of class "Umatrix"
the correlation matrix of the scores.
STATISTIC
:Object of class "Unumeric"
. The significance-test statistic, if it can be computed.
PVAL
:Object of class "Unumeric"
. The significance-test P value, if it can be computed.
n.obs
:Object of class "numeric"
. The number of observations.
center
:Object of class "Uvector"
. The center of the data.
eigenvalues
:Object of class "vector"
the eigenvalues.
cov.control
:Object of class "UCovControl"
. Record the cov control method.
signature(obj = "Fa")
: center of the data
signature(obj = "Fa")
: the eigenvalues of the covariance/correlation matrix
signature(obj = "Fa")
: returns an S3 list of class fa
for compatibility with the function factanal(). Thus the standard screeplot() can be used.
signature(obj = "Fa")
: returns the matrix loadings
signature(obj = "Fa")
: returns the number of observations used in the computation, i.e., n.obs
signature(obj = "Fa")
: if requested, a matrix of scores.
signature(obj = "Fa")
: returns the standard deviations of the factor analysis, i.e., the square roots of the eigenvalues of the covariance/correlation matrix
signature(x = "Fa", y = "missing")
: produces a scatterplot of the factor scores (if which = "factorScore") or shows the eigenvalues plot (if which = "screeplot")
signature(object = "Fa")
: calculates prediction using the results in object. The newdata argument is an optional data frame or matrix in which to look for variables with which to predict. If newdata is omitted, the scores are used.
signature(x = "Fa")
: prints the results. obj = print(obj)
signature(object = "Fa")
: produce result summaries of an object of class "Fa".
Ying-Ying Zhang (Robert) [email protected]
Bartlett, M. S. (1937) The statistical conception of mental factors. British Journal of Psychology, 28, 97–104.
Bartlett, M. S. (1938) Methods of estimating mental factors. Nature, 141, 609–610.
Joreskog, K. G. (1963) Statistical Estimation in Factor Analysis. Almqvist and Wicksell.
Lawley, D. N. and Maxwell, A. E. (1971) Factor Analysis as a Statistical Method. Second edition. Butterworths.
Thomson, G. H. (1951) The Factorial Analysis of Human Ability. London University Press.
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
Zhang, Y. Y. (2014), Robust Factor Analysis and Its Applications in the CSI 100 Index, Open Journal of Social Sciences 2(07):12-18, doi:10.4236/jss.2014.27003.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
showClass("Fa")
showClass("Fa")
Performs a classical factor analysis and returns the results as an object of class "FaClassic"
(a.k.a. constructor).
FaClassic(x, ...) ## S3 method for class 'formula' FaClassic(formula, data = NULL, factors = 2, cor = FALSE, method = "mle", scoresMethod = "none", ...) ## Default S3 method: FaClassic(x, factors = 2, cor = FALSE, method = c("mle", "pca", "pfa"), scoresMethod = c("none", "regression", "Bartlett"), ...)
FaClassic(x, ...) ## S3 method for class 'formula' FaClassic(formula, data = NULL, factors = 2, cor = FALSE, method = "mle", scoresMethod = "none", ...) ## Default S3 method: FaClassic(x, factors = 2, cor = FALSE, method = c("mle", "pca", "pfa"), scoresMethod = c("none", "regression", "Bartlett"), ...)
x |
A formula or a numeric matrix or an object that can be coerced to a numeric matrix. |
... |
Arguments passed to or from other methods. |
formula |
A formula with no response variable, referring only to numeric variables. |
data |
An optional data frame (or similar: see |
factors |
The number of factors to be fitted. |
cor |
A logical value indicating whether the calculation should use the covariance matrix ( |
method |
The method of factor analysis, one of "mle" (the default), "pca", and "pfa". |
scoresMethod |
Type of scores to produce, if any. The default is |
An S4 object of class FaClassic-class
which is a subclass of the virtual class Fa-class
.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
data("hbk") hbk.x = hbk[,1:3] ## faClassicPcaReg uses the default method faClassicPcaReg = FaClassic(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression"); faClassicPcaReg summary(faClassicPcaReg) ## faClassicForPcaReg uses the formula interface ## faClassicForPcaReg = faClassicPcaReg faClassicForPcaReg = FaClassic(~., data=as.data.frame(hbk.x), factors = 2, method = "pca", scoresMethod = "regression"); faClassicForPcaReg summary(faClassicForPcaReg)
data("hbk") hbk.x = hbk[,1:3] ## faClassicPcaReg uses the default method faClassicPcaReg = FaClassic(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression"); faClassicPcaReg summary(faClassicPcaReg) ## faClassicForPcaReg uses the formula interface ## faClassicForPcaReg = faClassicPcaReg faClassicForPcaReg = FaClassic(~., data=as.data.frame(hbk.x), factors = 2, method = "pca", scoresMethod = "regression"); faClassicForPcaReg summary(faClassicForPcaReg)
"FaClassic"
Contains the results of a classical Factor Analysis
Objects can be created by calls of the form new("FaClassic", ...)
. But the usual way of creating FaClassic
objects is a call to the function FaClassic
which serves as a constructor.
call
:Object of class "language"
an unevaluated function call
converged
:Object of class "Ulogical"
a logical character indicates whether the iterations converged
loadings
:Object of class "matrix"
the matrix of variable loadings
uniquenesses
:Object of class "vector"
the uniquenesses computed
covariance
:Object of class "matrix"
the covariance matrix
correlation
:Object of class "matrix"
the correlation matrix
usedMatrix
:Object of class "matrix"
the used matrix (running matrix)
criteria
:Object of class "Unumeric"
. The results of the optimization: the value of the negative log-likelihood and information on the iterations used.
factors
:Object of class "numeric"
the number of factors
dof
:Object of class "Unumeric"
. The number of degrees of freedom of the factor analysis model.
method
:Object of class "character"
. The method: one of "mle", "pca", and "pfa".
scores
:Object of class "Umatrix"
. If requested, a matrix of scores.
scoresMethod
:Object of class "character"
. The scores method: one of "none", "regression", and "Bartlett".
STATISTIC
:Object of class "Unumeric"
. The significance-test statistic, if it can be computed.
PVAL
:Object of class "Unumeric"
. The significance-test P value, if it can be computed.
n.obs
:Object of class "Unumeric"
. The number of observations if available.
center
:Object of class "Uvector"
. The center of the data.
eigenvalues
:Object of class "vector"
the eigenvalues
cov.control
:Object of class "UCovControl"
. Record the cov control method.
Class "Fa"
, directly.
No methods defined with class "FaClassic" in the signature.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
showClass("FaClassic")
showClass("FaClassic")
Robust factor analysis are obtained by replacing the classical covariance matrix
by a robust covariance estimator. This can be one of the available estimators in rrcov
, i.e., MCD, OGK, M, S, SDE, or MVE estimator.
FaCov(x, ...) ## S3 method for class 'formula' FaCov(formula, data = NULL, factors = 2, cor = FALSE, method = "mle", scoresMethod = "none", ...) ## Default S3 method: FaCov(x, factors = 2, cor = FALSE, cov.control = rrcov::CovControlMcd(), method = c("mle", "pca", "pfa"), scoresMethod = c("none", "regression", "Bartlett"), ...)
FaCov(x, ...) ## S3 method for class 'formula' FaCov(formula, data = NULL, factors = 2, cor = FALSE, method = "mle", scoresMethod = "none", ...) ## Default S3 method: FaCov(x, factors = 2, cor = FALSE, cov.control = rrcov::CovControlMcd(), method = c("mle", "pca", "pfa"), scoresMethod = c("none", "regression", "Bartlett"), ...)
x |
A formula or a numeric matrix or an object that can be coerced to a numeric matrix. |
... |
Arguments passed to or from other methods. |
formula |
A formula with no response variable, referring only to numeric variables. |
data |
An optional data frame (or similar: see |
factors |
The number of factors to be fitted. |
cor |
A logical value indicating whether the calculation should use the covariance matrix ( |
method |
The method of factor analysis, one of "mle" (the default), "pca", and "pfa". |
scoresMethod |
Type of scores to produce, if any. The default is |
cov.control |
Specifies which covariance estimator to use by providing a |
FaCov
, serving as a constructor for objects of class FaCov-class
is a generic function with "formula" and "default" methods.
An S4 object of class FaCov-class
which is a subclass of the virtual class Fa-class
.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
data("hbk") hbk.x = hbk[,1:3] ## ## faCovPcaRegMcd is obtained from FaCov.default ## faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd ## ## In fact, it is equivalent to use FaCov.formula ## faCovForPcaRegMcd = faCovPcaRegMcd ## faCovForPcaRegMcd = FaCov(~., data = as.data.frame(hbk.x), factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovForPcaRegMcd
data("hbk") hbk.x = hbk[,1:3] ## ## faCovPcaRegMcd is obtained from FaCov.default ## faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd ## ## In fact, it is equivalent to use FaCov.formula ## faCovForPcaRegMcd = faCovPcaRegMcd ## faCovForPcaRegMcd = FaCov(~., data = as.data.frame(hbk.x), factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovForPcaRegMcd
"FaCov"
Robust FA based on a robust covariance matrix. Robust FA are obtained by replacing the classical covariance matrix by a robust covariance estimator. This can be one of the available in rrcov
estimators, i.e., MCD, OGK, M, S, SDE, or MVE estimator.
Objects can be created by calls of the form new("FaCov", ...)
.
But the usual way of creating FaCov
objects is a call to the function FaCov
which serves as a constructor.
call
:Object of class "language"
an unevaluated function call
converged
:Object of class "Ulogical"
a logical character indicates whether the iterations converged
loadings
:Object of class "matrix"
the matrix of variable loadings
uniquenesses
:Object of class "vector"
the uniquenesses computed
covariance
:Object of class "matrix"
the covariance matrix
correlation
:Object of class "matrix"
the correlation matrix
usedMatrix
:Object of class "matrix"
the used matrix (running matrix)
criteria
:Object of class "Unumeric"
. The results of the optimization: the value of the negative log-likelihood and information on the iterations used.
factors
:Object of class "numeric"
the number of factors
dof
:Object of class "Unumeric"
. The number of degrees of freedom of the factor analysis model.
method
:Object of class "character"
. The method: one of "mle", "pca", and "pfa".
scores
:Object of class "Umatrix"
. If requested, a matrix of scores.
scoresMethod
:Object of class "character"
. The scores method: one of "none", "regression", and "Bartlett".
STATISTIC
:Object of class "Unumeric"
. The significance-test statistic, if it can be computed.
PVAL
:Object of class "Unumeric"
. The significance-test P value, if it can be computed.
n.obs
:Object of class "Unumeric"
. The number of observations if available.
center
:Object of class "Uvector"
. The center of the data.
eigenvalues
:Object of class "vector"
the eigenvalues
cov.control
:Object of class "UCovControl"
. Record the cov control method.
Class "FaRobust"
, directly.
Class "Fa"
, by class "FaRobust", distance 2.
No methods defined with class "FaCov" in the signature.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
showClass("FaCov")
showClass("FaCov")
Perform principal component factor analysis on a covariance matrix or data matrix.
factorScorePca(x, factors = 2, covmat = NULL, cor = FALSE, rotation = c("varimax", "none"), scoresMethod = c("none", "regression", "Bartlett"))
factorScorePca(x, factors = 2, covmat = NULL, cor = FALSE, rotation = c("varimax", "none"), scoresMethod = c("none", "regression", "Bartlett"))
x |
A numeric matrix or an object that can be coerced to a numeric matrix. |
factors |
The number of factors to be fitted. |
covmat |
A covariance matrix, or a covariance list as returned by |
cor |
A logical value indicating whether the calculation should use the covariance matrix ( |
rotation |
character. "none" or "varimax": it will be called with first argument the loadings matrix, and should return a list with component |
scoresMethod |
Type of scores to produce, if any. The default is |
Other feasible usages are:
factorScorePca(factors, covmat)
factorScorePca(x, factors, rotation, scoresMethod)
If x
is missing, then the following components of the result will be NULL: scores, ScoringCoef, meanF, corF, and n.obs.
An object of class "factorScorePca"
with components:
call |
The matched call. |
loadings |
A matrix of loadings, one column for each factor. This is of class |
communality |
The common variance. |
uniquenesses |
The uniquenesses/specific variance computed. |
covariance |
The robust/classical covariance matrix. |
correlation |
The robust/classical correlation matrix. |
usedMatrix |
The used matrix (running matrix). It may be the covariance or correlation matrix according to the value of |
reducedCorrelation |
NULL. The reduced correlation matrix, reducedCorrelation is calculated in factorScorePfa.R. |
factors |
The argument factors. |
method |
The method: always |
scores |
If requested, a matrix of scores. NULL if |
scoringCoef |
The scoring coefficients. NULL if |
meanF |
The sample mean of the scores. NULL if |
corF |
The sample correlation matrix of the scores. NULL if |
scoresMethod |
The argument |
n.obs |
The number of observations if available. NULL if |
center |
The center of the data. |
eigenvalues |
The eigenvalues of the usedMatrix. |
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data(stock611) R611=cor(stock611[,3:12]); R611 ## covmat is a matrix fsPca1=factorScorePca(factors = 3, covmat = R611); fsPca1 ## covmat is a list covx <- rrcov::Cov(stock611[,3:12]) covmat <- list(cov=rrcov::getCov(covx), center=rrcov::getCenter(covx), [email protected]) fsPca2=factorScorePca(factors = 3, covmat = covmat); fsPca2 ## fsPca3 contains scores etc. fsPca3=factorScorePca(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPca3
data(stock611) R611=cor(stock611[,3:12]); R611 ## covmat is a matrix fsPca1=factorScorePca(factors = 3, covmat = R611); fsPca1 ## covmat is a list covx <- rrcov::Cov(stock611[,3:12]) covmat <- list(cov=rrcov::getCov(covx), center=rrcov::getCenter(covx), n.obs=covx@n.obs) fsPca2=factorScorePca(factors = 3, covmat = covmat); fsPca2 ## fsPca3 contains scores etc. fsPca3=factorScorePca(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPca3
Perform principal factor factor analysis on a covariance matrix or data matrix.
factorScorePfa(x, factors = 2, covmat = NULL, cor = FALSE, rotation = c("varimax", "none"), scoresMethod = c("none", "regression", "Bartlett"))
factorScorePfa(x, factors = 2, covmat = NULL, cor = FALSE, rotation = c("varimax", "none"), scoresMethod = c("none", "regression", "Bartlett"))
x |
A numeric matrix or an object that can be coerced to a numeric matrix. |
factors |
The number of factors to be fitted. |
covmat |
A covariance matrix, or a covariance list as returned by |
cor |
A logical value indicating whether the calculation should use the covariance matrix ( |
rotation |
character. "none" or "varimax": it will be called with first argument the loadings matrix, and should return a list with component |
scoresMethod |
Type of scores to produce, if any. The default is |
Other feasible usages are:
factorScorePfa(factors, covmat)
factorScorePfa(x, factors, rotation, scoresMethod)
If x
is missing, then the following components of the result will be NULL: scores, ScoringCoef, meanF, corF, and n.obs.
An object of class "factorScorePfa"
with components:
call |
The matched call. |
loadings |
A matrix of loadings, one column for each factor. This is of class |
communality |
The common variance. |
uniquenesses |
The uniquenesses/specific variance computed. |
covariance |
The robust/classical covariance matrix. |
correlation |
The robust/classical correlation matrix. |
usedMatrix |
The used matrix (running matrix). It may be the covariance or correlation matrix according to the value of |
reducedCorrelation |
The last reduced correlation matrix. |
factors |
The argument factors. |
method |
The method: always |
scores |
If requested, a matrix of scores. NULL if |
scoringCoef |
The scoring coefficients. NULL if |
meanF |
The sample mean of the scores. NULL if |
corF |
The sample correlation matrix of the scores. NULL if |
scoresMethod |
The argument |
n.obs |
The number of observations if available. NULL if |
center |
The center of the data. |
eigenvalues |
The eigenvalues of the usedMatrix. |
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data(stock611) R611 = cor(stock611[,3:12]); R611 ## covmat is a matrix fsPfa1 = factorScorePfa(factors = 3, covmat = R611); fsPfa1 ## covmat is a list covx = rrcov::Cov(stock611[,3:12]) covmat = list(cov = rrcov::getCov(covx), center = rrcov::getCenter(covx), n.obs = [email protected]) fsPfa2 = factorScorePfa(factors = 3, cor = TRUE, covmat = covmat); fsPfa2 ## fsPfa3 contains scores etc. fsPfa3 = factorScorePfa(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPfa3
data(stock611) R611 = cor(stock611[,3:12]); R611 ## covmat is a matrix fsPfa1 = factorScorePfa(factors = 3, covmat = R611); fsPfa1 ## covmat is a list covx = rrcov::Cov(stock611[,3:12]) covmat = list(cov = rrcov::getCov(covx), center = rrcov::getCenter(covx), n.obs = covx@n.obs) fsPfa2 = factorScorePfa(factors = 3, cor = TRUE, covmat = covmat); fsPfa2 ## fsPfa3 contains scores etc. fsPfa3 = factorScorePfa(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPfa3
"FaRobust"
Class "FaRobust"
is a virtual base class for all robust FA classes. Currently the only available robust FA class is "FaCov"
. The class "FaRobust"
serves as a base class for deriving all other classes representing the results of the robust Factor Analysis methods.
A virtual Class: No objects may be created from it.
call
:Object of class "language"
an unevaluated function call
converged
:Object of class "Ulogical"
a logical character indicates whether the iterations converged
loadings
:Object of class "matrix"
the matrix of variable loadings
uniquenesses
:Object of class "vector"
the uniquenesses computed
covariance
:Object of class "matrix"
the covariance matrix
correlation
:Object of class "matrix"
the correlation matrix
usedMatrix
:Object of class "matrix"
the used matrix (running matrix)
criteria
:Object of class "Unumeric"
. The results of the optimization: the value of the negative log-likelihood and information on the iterations used.
factors
:Object of class "numeric"
the number of factors
dof
:Object of class "Unumeric"
. The number of degrees of freedom of the factor analysis model.
method
:Object of class "character"
. The method: one of "mle", "pca", and "pfa".
scores
:Object of class "Umatrix"
. If requested, a matrix of scores.
scoresMethod
:Object of class "character"
. The scores method: one of "none", "regression", and "Bartlett".
STATISTIC
:Object of class "Unumeric"
. The significance-test statistic, if it can be computed.
PVAL
:Object of class "Unumeric"
. The significance-test P value, if it can be computed.
n.obs
:Object of class "Unumeric"
. The number of observations if available.
center
:Object of class "Uvector"
. The center of the data.
eigenvalues
:Object of class "vector"
the eigenvalues
cov.control
:Object of class "UCovControl"
. Record the cov control method.
Class "Fa"
, directly.
No methods defined with class "FaRobust" in the signature.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
FaClassic-class
, FaCov-class
, FaRobust-class
, Fa-class
showClass("FaRobust")
showClass("FaRobust")
Compute the ordered factor scores according to the first/second/third... column of the original factor scores.
fsOrder(factorScores)
fsOrder(factorScores)
factorScores |
The original factor scores. |
A list with m
(the number of factors) components:
[[1]] |
The ordered factor scores with a decreasing first column. |
[[2]] |
The ordered factor scores with a decreasing second column. |
... |
|
[[m]] |
The ordered factor scores with a decreasing m-th column. |
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data(stock611) R611=cor(stock611[,3:12]); R611 ## FS.pca contains scores etc. fsPca=factorScorePca(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPca orderedFS=fsOrder(fsPca$scores); orderedFS
data(stock611) R611=cor(stock611[,3:12]); R611 ## FS.pca contains scores etc. fsPca=factorScorePca(x = stock611[,3:12], factors = 2, cor = TRUE, rotation = "varimax", scoresMethod = "regression"); fsPca orderedFS=fsOrder(fsPca$scores); orderedFS
Accessor method to the Center slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the Center slot of an object of class "Fa"
and its subclasses
Accessor method to the Eigenvalues slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the Eigenvalues slot of an object of class "Fa"
and its subclasses
Accessor method to some slots of an object of class "Fa"
and its subclasses. Return a list of class "fa".
signature(obj = "Fa")
Accessor method to some slots of an object of class "Fa"
and its subclasses. Return a list of class "fa".
Accessor method to the Loadings slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the Loadings slot of an object of class "Fa"
and its subclasses
Accessor method to the n.obs slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the n.obs slot of an object of class "Fa"
and its subclasses
Accessor method to the Scores slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the Scores slot of an object of class "Fa"
and its subclasses
Accessor method to the Standard Deviation slot of an object of class "Fa"
and its subclasses.
signature(obj = "Fa")
Accessor method to the Standard Deviation slot of an object of class "Fa"
and its subclasses
Show/print/display an object, including the Call, Standard deviations, Loadings, and Rotated variables (if print.x = TRUE
).
myFaPrint(object, print.x=FALSE)
myFaPrint(object, print.x=FALSE)
object |
an object of class |
print.x |
Logical. If |
An invisible argument object
.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()) ## you can use either object or print(object) or myFaPrint(object) ## since faCovPcaRegMcd is an object of class "Fa" faCovPcaRegMcd print(faCovPcaRegMcd) myFaPrint(faCovPcaRegMcd)
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()) ## you can use either object or print(object) or myFaPrint(object) ## since faCovPcaRegMcd is an object of class "Fa" faCovPcaRegMcd print(faCovPcaRegMcd) myFaPrint(faCovPcaRegMcd)
"myplotDD"
is a revised version of ".myddplot"
in "plot-utils.R"
in the package "rrcov"
. In "myplotDD"
, id.n
and ind
are printed out.
myplotDD(x, cutoff, id.n)
myplotDD(x, cutoff, id.n)
x |
An S4 object of class |
cutoff |
The |
id.n |
Number of observations to identify by a label. If not supplied, the number of observations with robust distance larger than |
Distance-Distance Plot: Plot the vector y=rd
(robust distances) against x=md
(mahalanobis distances). Identify by a label the id.n
observations with largest rd
. If id.n
is not supplied, calculate it as the number of observations larger than cutoff
. Use cutoff
to draw a horisontal and a vertical line. Draw also a dotted line with a slope 1.
"myplotDD(x)"
is equivalent to "plot(x, which="dd")"
.
which
: indicate what kind of plot. If which = "dd"
, then a distance-distance Plot.
A distance-distance plot is shown. Return a list with components:
cutoff |
The |
id.n |
Number of observations to identify by a label. If not supplied, the number of observations with robust distance larger than |
sort.y |
A list containing the sorted values of y (the robust distance) |
ind |
The indices of the largest |
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
plot
, qchisq
, CovClassic
, getDistance
data(stock611) covMcd=CovRobust(x=scale(stock611[,3:12]), control="mcd"); covMcd ## "myplotDD" shows id.n and ind. ## Note: id.n and ind change each time due to covMcd changes each time! ## However, the ind of largest robust distances do not change. result = myplotDD(x=covMcd); result ## "myplotDD" is equivalent to "plot(x=covMcd, which="dd")". plot(x=covMcd, which="dd")
data(stock611) covMcd=CovRobust(x=scale(stock611[,3:12]), control="mcd"); covMcd ## "myplotDD" shows id.n and ind. ## Note: id.n and ind change each time due to covMcd changes each time! ## However, the ind of largest robust distances do not change. result = myplotDD(x=covMcd); result ## "myplotDD" is equivalent to "plot(x=covMcd, which="dd")". plot(x=covMcd, which="dd")
Plot an object of class "Fa". If which = "factorScore", then a scatterplot of the factor scores is produced; if which = "screeplot", shows the eigenvalues and is helpful to select the number of factors.
## S4 method for signature 'Fa' plot(x, which=c("factorScore", "screeplot"), choices=1:2)
## S4 method for signature 'Fa' plot(x, which=c("factorScore", "screeplot"), choices=1:2)
x |
an object of class |
which |
indicate what kind of plot. If |
choices |
an integer vector indicate which columns of the factor scores to plot |
The feasible usages are:
plot(x, which="factorScore", choices=1:2)
plot(x, which="screeplot")
signature(x = "Fa", y = "missing")
generic functions - see plot
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] faClassicPcaReg = FaClassic(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression"); faClassicPcaReg summary(faClassicPcaReg) plot(faClassicPcaReg, which = "factorScore", choices = 1:2) plot(faClassicPcaReg, which = "screeplot")
data("hbk") hbk.x = hbk[,1:3] faClassicPcaReg = FaClassic(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression"); faClassicPcaReg summary(faClassicPcaReg) plot(faClassicPcaReg, which = "factorScore", choices = 1:2) plot(faClassicPcaReg, which = "screeplot")
Calculates prediction using the results in object. The newdata argument is an optional data frame or matrix in which to look for variables with which to predict. If newdata is omitted, the scores are used.
predict(object, ...)
predict(object, ...)
object |
an object of class |
... |
additional arguments, e.g., newdata: an optional data frame or matrix in which to look for variables with which to predict. If newdata is not missing, newdata should be scaled before |
signature(object = "Fa")
generic functions - see print
, summary
, predict
, plot
, getCenter
, getEigenvalues
, getFa
, getLoadings
, getQuan
, getScores
, getSdev
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd ## If missing newdata, the scores are used predict(faCovPcaRegMcd) ## ## If not missing newdata, newdata should be scaled first. ## newdata = hbk.x[1, ] cor = FALSE # the default newdata = { if (cor == TRUE) # standardized transformation scale(newdata, center = faCovPcaRegMcd@center, scale = sqrt(diag(faCovPcaRegMcd@covariance))) else # cor == FALSE # centralized transformation scale(newdata, center = faCovPcaRegMcd@center, scale = FALSE) } ## ## Now, prediction = predict(faCovPcaRegMcd)[1,] = faCovPcaRegMcd@scores[1,] ## prediction = predict(faCovPcaRegMcd, newdata = newdata) prediction
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd ## If missing newdata, the scores are used predict(faCovPcaRegMcd) ## ## If not missing newdata, newdata should be scaled first. ## newdata = hbk.x[1, ] cor = FALSE # the default newdata = { if (cor == TRUE) # standardized transformation scale(newdata, center = faCovPcaRegMcd@center, scale = sqrt(diag(faCovPcaRegMcd@covariance))) else # cor == FALSE # centralized transformation scale(newdata, center = faCovPcaRegMcd@center, scale = FALSE) } ## ## Now, prediction = predict(faCovPcaRegMcd)[1,] = faCovPcaRegMcd@scores[1,] ## prediction = predict(faCovPcaRegMcd, newdata = newdata) prediction
Print/display an object, including the Call, Standard deviations, Loadings.
print(x, ...)
print(x, ...)
x |
an object of class |
... |
additional arguments, e.g., print.x=TRUE |
An invisible argument x
.
generic functions - see print
, summary
, predict
, plot
, getCenter
, getEigenvalues
, getFa
, getLoadings
, getQuan
, getScores
, getSdev
generic functions - see print
, summary
, predict
, plot
, getCenter
, getEigenvalues
, getFa
, getLoadings
, getQuan
, getScores
, getSdev
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()) ## you can use either object or print(object) or myFaPrint(object) ## since faCovPcaRegMcd is an object of class "Fa" faCovPcaRegMcd print(faCovPcaRegMcd) myFaPrint(faCovPcaRegMcd)
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()) ## you can use either object or print(object) or myFaPrint(object) ## since faCovPcaRegMcd is an object of class "Fa" faCovPcaRegMcd print(faCovPcaRegMcd) myFaPrint(faCovPcaRegMcd)
This data set consists of 611 observations with 12 variables.
data(stock611)
data(stock611)
A data frame with 611 observations on the following 12 variables.
code
a numeric vector
name
a numeric vector: the Chinese stocks name is replaced by integer, it can be found by its code.
x1
a numeric vector: main business income (China Yuan)
x2
a numeric vector: main business profit (China Yuan)
x3
a numeric vector: total profit (China Yuan)
x4
a numeric vector: net profit (China Yuan)
x5
a numeric vector: earnings per share (EPS) (China Yuan)
x6
a numeric vector: net assets per share (China Yuan)
x7
a numeric vector: net return on assets (%)
x8
a numeric vector: total return on assets (%)
x9
a numeric vector: total assets (China Yuan)
x10
a numeric vector: equity
The data set is from Chinese stock market in the year 2001. It was used in Wang X. M. (2009) to illustrate the factor analysis methods.
Wang X. M. (2009) Applied Multivariate Analysis. Third edition. ShangHai University of Finance & Economics Press. (This is a Chinese book)
Note: In Wang X. M.'s homepage, he provided a link to download materials related to his book (including the data set stock611): http://bb.shufe.edu.cn/bbcswebdav/institution/
data(stock611) str(stock611) plot(stock611)
data(stock611) str(stock611) plot(stock611)
Produce result summaries of an object of class "Fa".
summary(object, ...)
summary(object, ...)
object |
an object of class |
... |
additional arguments, e.g., print.x=TRUE. |
signature(object = "Fa")
Summary an object of class "Fa".
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd faCovPcaRegMcd summary(faCovPcaRegMcd)
data("hbk") hbk.x = hbk[,1:3] faCovPcaRegMcd = FaCov(x = hbk.x, factors = 2, method = "pca", scoresMethod = "regression", cov.control = rrcov::CovControlMcd()); faCovPcaRegMcd faCovPcaRegMcd summary(faCovPcaRegMcd)
"SummaryFa"
Summary of "Fa"
objects. The "Fa"
object plus some additional summary information.
Objects can be created by calls of the form new("SummaryFa", ...)
. But most often by invoking 'summary' on an "Fa" object. They contain values meant for printing by 'show'.
faobj
:Object of class "Fa"
importance
:Object of class "matrix"
. Matrix with additional information: importance of components.
signature(object = "SummaryFa")
: display the object
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
showClass("SummaryFa")
showClass("SummaryFa")
"Ulogical"
Define class unions for optional slots, e.g., for definition of slots which will be computed on demand.
A virtual Class: No objects may be created from it.
No methods defined with class "Ulogical" in the signature.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.
"Unumeric"
Define class unions for optional slots, e.g., for definition of slots which will be computed on demand.
A virtual Class: No objects may be created from it.
No methods defined with class "Unumeric" in the signature.
Ying-Ying Zhang (Robert) [email protected]
Zhang, Y. Y. (2013), An Object Oriented Solution for Robust Factor Analysis.